Skip to content

Commit 100c247

Browse files
authored
Add SamplingPercentToSigma node (Comfy-Org#8963)
It's helpful to adjust start_percent or end_percent based on the corresponding sigma.
1 parent 1da5639 commit 100c247

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

comfy_extras/nodes_custom_sampler.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,35 @@ def extend(self, sigmas: torch.Tensor, steps: int, start_at_sigma: float, end_at
301301

302302
return (extended_sigmas,)
303303

304+
305+
class SamplingPercentToSigma:
306+
@classmethod
307+
def INPUT_TYPES(cls) -> InputTypeDict:
308+
return {
309+
"required": {
310+
"model": (IO.MODEL, {}),
311+
"sampling_percent": (IO.FLOAT, {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.0001}),
312+
"return_actual_sigma": (IO.BOOLEAN, {"default": False, "tooltip": "Return the actual sigma value instead of the value used for interval checks.\nThis only affects results at 0.0 and 1.0."}),
313+
}
314+
}
315+
316+
RETURN_TYPES = (IO.FLOAT,)
317+
RETURN_NAMES = ("sigma_value",)
318+
CATEGORY = "sampling/custom_sampling/sigmas"
319+
320+
FUNCTION = "get_sigma"
321+
322+
def get_sigma(self, model, sampling_percent, return_actual_sigma):
323+
model_sampling = model.get_model_object("model_sampling")
324+
sigma_val = model_sampling.percent_to_sigma(sampling_percent)
325+
if return_actual_sigma:
326+
if sampling_percent == 0.0:
327+
sigma_val = model_sampling.sigma_max.item()
328+
elif sampling_percent == 1.0:
329+
sigma_val = model_sampling.sigma_min.item()
330+
return (sigma_val,)
331+
332+
304333
class KSamplerSelect:
305334
@classmethod
306335
def INPUT_TYPES(s):
@@ -887,6 +916,7 @@ def add_noise(self, model, noise, sigmas, latent_image):
887916
"FlipSigmas": FlipSigmas,
888917
"SetFirstSigma": SetFirstSigma,
889918
"ExtendIntermediateSigmas": ExtendIntermediateSigmas,
919+
"SamplingPercentToSigma": SamplingPercentToSigma,
890920

891921
"CFGGuider": CFGGuider,
892922
"DualCFGGuider": DualCFGGuider,

0 commit comments

Comments
 (0)