Skip to content

Commit 7f53c5b

Browse files
committed
Update nodes_optimalsteps.py
1 parent 78992c4 commit 7f53c5b

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

comfy_extras/nodes_optimalsteps.py

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# from https://github.com/bebebe666/OptimalSteps
22

3-
43
import numpy as np
54
import torch
65

6+
77
def loglinear_interp(t_steps, num_steps):
88
"""
99
Performs log-linear interpolation of a given array of decreasing numbers.
@@ -18,39 +18,65 @@ def loglinear_interp(t_steps, num_steps):
1818
return interped_ys
1919

2020

21-
NOISE_LEVELS = {"FLUX": [0.9968, 0.9886, 0.9819, 0.975, 0.966, 0.9471, 0.9158, 0.8287, 0.5512, 0.2808, 0.001],
22-
"Wan":[1.0, 0.997, 0.995, 0.993, 0.991, 0.989, 0.987, 0.985, 0.98, 0.975, 0.973, 0.968, 0.96, 0.946, 0.927, 0.902, 0.864, 0.776, 0.539, 0.208, 0.001],
23-
}
21+
NOISE_LEVELS = {"FLUX": [0.9968, 0.9886, 0.9819, 0.975, 0.966, 0.9471, 0.9158, 0.8287, 0.5512, 0.2808, 0.001], "Wan": [1.0, 0.997, 0.995, 0.993, 0.991, 0.989, 0.987, 0.985, 0.98, 0.975, 0.973, 0.968, 0.96, 0.946, 0.927, 0.902, 0.864, 0.776, 0.539, 0.208, 0.001], "SDXL": [12.1769, 9.9182, 7.0887, 4.5944, 2.2473, 0.9020, 0.2872, 0.0738, 0.0197, 0.0020, 0.0]}
22+
2423

2524
class OptimalStepsScheduler:
25+
2626
@classmethod
2727
def INPUT_TYPES(s):
28-
return {"required":
29-
{"model_type": (["FLUX", "Wan"], ),
30-
"steps": ("INT", {"default": 20, "min": 3, "max": 1000}),
31-
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
32-
}
33-
}
34-
RETURN_TYPES = ("SIGMAS",)
28+
return {
29+
"required": {
30+
"model_type": (["FLUX", "Wan", "SDXL"], ),
31+
"steps": ("INT", {
32+
"default": 20,
33+
"min": 1,
34+
"max": 1000
35+
}),
36+
"denoise": ("FLOAT", {
37+
"default": 1.0,
38+
"min": 0.0,
39+
"max": 1.0,
40+
"step": 0.01
41+
}),
42+
},
43+
"optional": {
44+
"custom_sigmas": ("STRING", {
45+
"default": "",
46+
"placeholder": "Comma-separated sigma values"
47+
}),
48+
}
49+
}
50+
51+
RETURN_TYPES = ("SIGMAS", )
3552
CATEGORY = "sampling/custom_sampling/schedulers"
3653

3754
FUNCTION = "get_sigmas"
3855

39-
def get_sigmas(self, model_type, steps, denoise):
56+
def get_sigmas(self, model_type, steps, denoise, custom_sigmas=""):
4057
total_steps = steps
4158
if denoise < 1.0:
4259
if denoise <= 0.0:
43-
return (torch.FloatTensor([]),)
60+
return (torch.FloatTensor([]), )
4461
total_steps = round(steps * denoise)
4562

46-
sigmas = NOISE_LEVELS[model_type][:]
63+
if custom_sigmas:
64+
# Parse the custom_sigmas string into a list of floats
65+
try:
66+
sigmas = [float(s.strip()) for s in custom_sigmas.split(",") if s.strip()]
67+
except ValueError:
68+
raise ValueError("Invalid custom_sigmas format. Ensure it is a comma-separated list of numbers.")
69+
else:
70+
# Use the predefined NOISE_LEVELS
71+
sigmas = NOISE_LEVELS[model_type][:]
4772
if (steps + 1) != len(sigmas):
4873
sigmas = loglinear_interp(sigmas, steps + 1)
4974

5075
sigmas = sigmas[-(total_steps + 1):]
5176
sigmas[-1] = 0
5277
return (torch.FloatTensor(sigmas), )
5378

79+
5480
NODE_CLASS_MAPPINGS = {
5581
"OptimalStepsScheduler": OptimalStepsScheduler,
5682
}

0 commit comments

Comments
 (0)