11# code adapted from https://github.com/exx8/differential-diffusion
22
3+ from typing_extensions import override
4+
35import torch
6+ from comfy_api .latest import ComfyExtension , io
7+
8+
9+ class DifferentialDiffusion (io .ComfyNode ):
10+ @classmethod
11+ def define_schema (cls ):
12+ return io .Schema (
13+ node_id = "DifferentialDiffusion" ,
14+ display_name = "Differential Diffusion" ,
15+ category = "_for_testing" ,
16+ inputs = [
17+ io .Model .Input ("model" ),
18+ io .Float .Input (
19+ "strength" ,
20+ default = 1.0 ,
21+ min = 0.0 ,
22+ max = 1.0 ,
23+ step = 0.01 ,
24+ optional = True ,
25+ ),
26+ ],
27+ outputs = [io .Model .Output ()],
28+ is_experimental = True ,
29+ )
430
5- class DifferentialDiffusion ():
631 @classmethod
7- def INPUT_TYPES (s ):
8- return {
9- "required" : {
10- "model" : ("MODEL" , ),
11- },
12- "optional" : {
13- "strength" : ("FLOAT" , {
14- "default" : 1.0 ,
15- "min" : 0.0 ,
16- "max" : 1.0 ,
17- "step" : 0.01 ,
18- }),
19- }
20- }
21- RETURN_TYPES = ("MODEL" ,)
22- FUNCTION = "apply"
23- CATEGORY = "_for_testing"
24- INIT = False
25-
26- def apply (self , model , strength = 1.0 ):
32+ def execute (cls , model , strength = 1.0 ) -> io .NodeOutput :
2733 model = model .clone ()
28- model .set_model_denoise_mask_function (lambda * args , ** kwargs : self .forward (* args , ** kwargs , strength = strength ))
29- return (model , )
34+ model .set_model_denoise_mask_function (lambda * args , ** kwargs : cls .forward (* args , ** kwargs , strength = strength ))
35+ return io . NodeOutput (model )
3036
31- def forward (self , sigma : torch .Tensor , denoise_mask : torch .Tensor , extra_options : dict , strength : float ):
37+ @classmethod
38+ def forward (cls , sigma : torch .Tensor , denoise_mask : torch .Tensor , extra_options : dict , strength : float ):
3239 model = extra_options ["model" ]
3340 step_sigmas = extra_options ["sigmas" ]
3441 sigma_to = model .inner_model .model_sampling .sigma_min
@@ -53,9 +60,13 @@ def forward(self, sigma: torch.Tensor, denoise_mask: torch.Tensor, extra_options
5360 return binary_mask
5461
5562
56- NODE_CLASS_MAPPINGS = {
57- "DifferentialDiffusion" : DifferentialDiffusion ,
58- }
59- NODE_DISPLAY_NAME_MAPPINGS = {
60- "DifferentialDiffusion" : "Differential Diffusion" ,
61- }
63+ class DifferentialDiffusionExtension (ComfyExtension ):
64+ @override
65+ async def get_node_list (self ) -> list [type [io .ComfyNode ]]:
66+ return [
67+ DifferentialDiffusion ,
68+ ]
69+
70+
71+ async def comfy_entrypoint () -> DifferentialDiffusionExtension :
72+ return DifferentialDiffusionExtension ()
0 commit comments