From 821238284ac93136ac6d091b71f0873ad7d21d0e Mon Sep 17 00:00:00 2001 From: filipstrand Date: Fri, 14 Feb 2025 05:21:35 +0100 Subject: [PATCH] Fix: Handle edge case for img2img --- src/mflux/config/runtime_config.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/mflux/config/runtime_config.py b/src/mflux/config/runtime_config.py index 2ae1a8c..5c7d9d2 100644 --- a/src/mflux/config/runtime_config.py +++ b/src/mflux/config/runtime_config.py @@ -53,14 +53,16 @@ class RuntimeConfig: @property def init_time_step(self) -> int: - if self.config.init_image_path is None: - # For text-to-image, always begin at time step 0. + is_txt2img = self.config.init_image_path is None or self.config.init_image_strength == 0.0 + + if is_txt2img: return 0 else: - # For image-to-image: higher strength means we skip more steps. + # 1. Clamp strength to [0, 1] strength = max(0.0, min(1.0, self.config.init_image_strength)) - t = max(1, int(self.num_inference_steps * strength)) - return t + + # 2. Return start time in [1, floor(num_steps * strength)] + return max(1, int(self.num_inference_steps * strength)) @property def controlnet_strength(self) -> float | None: