From 34f60b1e080ab3ce4c82332543fb60bf99e01854 Mon Sep 17 00:00:00 2001 From: Sonny Box Date: Mon, 17 Aug 2026 18:37:39 -0700 Subject: [PATCH] minor changes to add to 0.3.4 release --- sampling/dual_sampler_custom_advanced.py | 29 +++++++++++++++++------- tools/image_size_calculator.py | 6 ++--- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/sampling/dual_sampler_custom_advanced.py b/sampling/dual_sampler_custom_advanced.py index 4a3891f..1f1f6a2 100644 --- a/sampling/dual_sampler_custom_advanced.py +++ b/sampling/dual_sampler_custom_advanced.py @@ -4,6 +4,7 @@ import comfy.model_management import comfy.nested_tensor import comfy.sample import comfy.utils +import numpy from comfy_api.latest import io import latent_preview @@ -16,23 +17,35 @@ from .utils import DualSampler, DualSamplerType, check_schedules END_SIGMAS_KEY = "dual_end_sigmas" -def check_resume(latent, video_sigmas, audio_sigmas): +def decimals(value): + """How many decimals the value was written with, at float32 precision.""" + text = numpy.format_float_positional(numpy.float32(value), unique=True, trim="-") + return len(text.partition(".")[2]) + + +def check_resume(latent, video_sigmas, audio_sigmas, noise): previous = latent.get(END_SIGMAS_KEY) if previous is None: return - for stream, was, now in ( - ("video", previous[0], float(video_sigmas[0])), - ("audio", previous[1], float(audio_sigmas[0])), + for stream, was, now, added in ( + ("video", previous[0], float(video_sigmas[0]), noise[0]), + ("audio", previous[1], float(audio_sigmas[0]), noise[1]), ): - if abs(was - now) <= 1e-6 or was == 0.0: + if was == 0.0 or bool(added.any()): + # re-noised, so whatever noise level the latent was left at no longer matters + continue + # a schedule written to fewer decimals than the one it resumes still matches, so + # compare both at the coarser of the two, never coarser than the 4 decimals the + # sigma widgets expose + places = max(4, min(decimals(was), decimals(now))) + if round(was, places) == round(now, places): continue logging.warning( - "%s sigma at index 0 (%g) does not match the %s latent (%g), expect bad %s quality.", + "%s sigma at index 0 (%g) does not match the %s latent (%g).", stream, now, stream, was, - stream, ) @@ -138,7 +151,7 @@ class DualSamplerCustomAdvanced(io.ComfyNode): streams[1] = stream_noise(noise_audio, latent).unbind()[1] noise = comfy.nested_tensor.NestedTensor(streams) - check_resume(latent, video_sigmas, audio_sigmas) + check_resume(latent, video_sigmas, audio_sigmas, streams) noise_mask = latent.get("noise_mask", None) x0_output = {} diff --git a/tools/image_size_calculator.py b/tools/image_size_calculator.py index 83a4274..886c8ce 100644 --- a/tools/image_size_calculator.py +++ b/tools/image_size_calculator.py @@ -108,9 +108,9 @@ class ImageSizeCalculator(io.ComfyNode): target_h = math.sqrt(target_pixels / ratio) target_w = target_h * ratio - # Round to nearest multiple - final_w = int(round(target_w / multiple_of)) * multiple_of - final_h = int(round(target_h / multiple_of)) * multiple_of + # Round to nearest multiple, breaking exact ties downwards + final_w = math.ceil(target_w / multiple_of - 0.5 - 1e-9) * multiple_of + final_h = math.ceil(target_h / multiple_of - 0.5 - 1e-9) * multiple_of # Ensure we don't return 0 if the size is very small relative to multiple_of final_w = max(multiple_of, final_w)