2025-07-18 17:05:40 +03:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import torch
|
|
|
|
|
|
2025-07-24 18:23:29 -07:00
|
|
|
from comfy_api.latest import io
|
2025-07-18 17:05:40 +03:00
|
|
|
|
|
|
|
|
|
2025-07-23 15:05:58 -07:00
|
|
|
class DifferentialDiffusion(io.ComfyNode):
|
2025-07-18 17:05:40 +03:00
|
|
|
@classmethod
|
|
|
|
|
def define_schema(cls):
|
2025-07-23 14:55:53 -07:00
|
|
|
return io.Schema(
|
2025-07-18 17:05:40 +03:00
|
|
|
node_id="DifferentialDiffusion_V3",
|
|
|
|
|
display_name="Differential Diffusion _V3",
|
|
|
|
|
category="_for_testing",
|
|
|
|
|
inputs=[
|
2025-07-24 22:03:50 +03:00
|
|
|
io.Model.Input("model"),
|
2025-07-18 17:05:40 +03:00
|
|
|
],
|
|
|
|
|
outputs=[
|
|
|
|
|
io.Model.Output(),
|
|
|
|
|
],
|
|
|
|
|
is_experimental=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def execute(cls, model):
|
|
|
|
|
model = model.clone()
|
|
|
|
|
model.set_model_denoise_mask_function(cls.forward)
|
|
|
|
|
return io.NodeOutput(model)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def forward(cls, sigma: torch.Tensor, denoise_mask: torch.Tensor, extra_options: dict):
|
|
|
|
|
model = extra_options["model"]
|
|
|
|
|
step_sigmas = extra_options["sigmas"]
|
|
|
|
|
sigma_to = model.inner_model.model_sampling.sigma_min
|
|
|
|
|
if step_sigmas[-1] > sigma_to:
|
|
|
|
|
sigma_to = step_sigmas[-1]
|
|
|
|
|
sigma_from = step_sigmas[0]
|
|
|
|
|
|
|
|
|
|
ts_from = model.inner_model.model_sampling.timestep(sigma_from)
|
|
|
|
|
ts_to = model.inner_model.model_sampling.timestep(sigma_to)
|
|
|
|
|
current_ts = model.inner_model.model_sampling.timestep(sigma[0])
|
|
|
|
|
|
|
|
|
|
threshold = (current_ts - ts_to) / (ts_from - ts_to)
|
|
|
|
|
|
|
|
|
|
return (denoise_mask >= threshold).to(denoise_mask.dtype)
|
|
|
|
|
|
|
|
|
|
|
2025-07-25 21:03:11 +03:00
|
|
|
NODES_LIST: list[type[io.ComfyNode]] = [
|
2025-07-18 17:05:40 +03:00
|
|
|
DifferentialDiffusion,
|
|
|
|
|
]
|