1
1
#from: https://research.nvidia.com/labs/toronto-ai/AlignYourSteps/howto.html
2
2
import numpy as np
3
3
import torch
4
+ from typing_extensions import override
5
+
6
+ from comfy_api .latest import ComfyExtension , io
7
+
4
8
5
9
def loglinear_interp (t_steps , num_steps ):
6
10
"""
@@ -19,25 +23,30 @@ def loglinear_interp(t_steps, num_steps):
19
23
"SDXL" :[14.6146412293 , 6.3184485287 , 3.7681790315 , 2.1811480769 , 1.3405244945 , 0.8620721141 , 0.5550693289 , 0.3798540708 , 0.2332364134 , 0.1114188177 , 0.0291671582 ],
20
24
"SVD" : [700.00 , 54.5 , 15.886 , 7.977 , 4.248 , 1.789 , 0.981 , 0.403 , 0.173 , 0.034 , 0.002 ]}
21
25
22
- class AlignYourStepsScheduler :
26
+ class AlignYourStepsScheduler ( io . ComfyNode ) :
23
27
@classmethod
24
- def INPUT_TYPES ( s ) :
25
- return { "required" :
26
- { "model_type" : ([ "SD1" , "SDXL" , "SVD" ], ) ,
27
- "steps" : ( "INT" , { "default" : 10 , "min" : 1 , "max" : 10000 }) ,
28
- "denoise" : ( "FLOAT" , { "default" : 1.0 , "min" : 0.0 , "max" : 1.0 , "step" : 0.01 }),
29
- }
30
- }
31
- RETURN_TYPES = ( "SIGMAS" ,)
32
- CATEGORY = "sampling/custom_sampling/schedulers"
33
-
34
- FUNCTION = "get_sigmas"
28
+ def define_schema ( cls ) -> io . Schema :
29
+ return io . Schema (
30
+ node_id = "AlignYourStepsScheduler" ,
31
+ category = "sampling/custom_sampling/schedulers" ,
32
+ inputs = [
33
+ io . Combo . Input ( "model_type" , options = [ "SD1" , "SDXL" , "SVD" ]),
34
+ io . Int . Input ( "steps" , default = 10 , min = 1 , max = 10000 ),
35
+ io . Float . Input ( "denoise" , default = 1.0 , min = 0.0 , max = 1.0 , step = 0.01 ),
36
+ ],
37
+ outputs = [ io . Sigmas . Output ()],
38
+ )
35
39
36
40
def get_sigmas (self , model_type , steps , denoise ):
41
+ # Deprecated: use the V3 schema's `execute` method instead of this.
42
+ return AlignYourStepsScheduler ().execute (model_type , steps , denoise ).result
43
+
44
+ @classmethod
45
+ def execute (cls , model_type , steps , denoise ) -> io .NodeOutput :
37
46
total_steps = steps
38
47
if denoise < 1.0 :
39
48
if denoise <= 0.0 :
40
- return (torch .FloatTensor ([]), )
49
+ return io . NodeOutput (torch .FloatTensor ([]))
41
50
total_steps = round (steps * denoise )
42
51
43
52
sigmas = NOISE_LEVELS [model_type ][:]
@@ -46,8 +55,15 @@ def get_sigmas(self, model_type, steps, denoise):
46
55
47
56
sigmas = sigmas [- (total_steps + 1 ):]
48
57
sigmas [- 1 ] = 0
49
- return (torch .FloatTensor (sigmas ), )
58
+ return io .NodeOutput (torch .FloatTensor (sigmas ))
59
+
60
+
61
+ class AlignYourStepsExtension (ComfyExtension ):
62
+ @override
63
+ async def get_node_list (self ) -> list [type [io .ComfyNode ]]:
64
+ return [
65
+ AlignYourStepsScheduler ,
66
+ ]
50
67
51
- NODE_CLASS_MAPPINGS = {
52
- "AlignYourStepsScheduler" : AlignYourStepsScheduler ,
53
- }
68
+ async def comfy_entrypoint () -> AlignYourStepsExtension :
69
+ return AlignYourStepsExtension ()
0 commit comments