Skip to content

Commit f1c3393

Browse files
fix(flux): prevent progress percentage overflow with LCM scheduler
LCM scheduler may have more internal timesteps than user-facing steps, causing user_step to exceed total_steps. This resulted in progress percentage > 1.0, which caused a pydantic validation error. Fix: Only call step_callback when user_step <= total_steps.
1 parent 81739c7 commit f1c3393

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

invokeai/backend/flux/denoise.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -201,33 +201,38 @@ def denoise(
201201
if not in_first_order:
202202
# Second order step completed
203203
user_step += 1
204+
# Only call step_callback if we haven't exceeded total_steps
205+
if user_step <= total_steps:
206+
preview_img = img - t_curr * pred
207+
if inpaint_extension is not None:
208+
preview_img = inpaint_extension.merge_intermediate_latents_with_init_latents(preview_img, 0.0)
209+
step_callback(
210+
PipelineIntermediateState(
211+
step=user_step,
212+
order=2,
213+
total_steps=total_steps,
214+
timestep=int(t_curr * 1000),
215+
latents=preview_img,
216+
),
217+
)
218+
else:
219+
# For Euler, LCM and other first-order schedulers
220+
user_step += 1
221+
# Only call step_callback if we haven't exceeded total_steps
222+
# (LCM scheduler may have more internal steps than user-facing steps)
223+
if user_step <= total_steps:
204224
preview_img = img - t_curr * pred
205225
if inpaint_extension is not None:
206226
preview_img = inpaint_extension.merge_intermediate_latents_with_init_latents(preview_img, 0.0)
207227
step_callback(
208228
PipelineIntermediateState(
209229
step=user_step,
210-
order=2,
230+
order=1,
211231
total_steps=total_steps,
212232
timestep=int(t_curr * 1000),
213233
latents=preview_img,
214234
),
215235
)
216-
else:
217-
# For Euler and other first-order schedulers
218-
user_step += 1
219-
preview_img = img - t_curr * pred
220-
if inpaint_extension is not None:
221-
preview_img = inpaint_extension.merge_intermediate_latents_with_init_latents(preview_img, 0.0)
222-
step_callback(
223-
PipelineIntermediateState(
224-
step=user_step,
225-
order=1,
226-
total_steps=total_steps,
227-
timestep=int(t_curr * 1000),
228-
latents=preview_img,
229-
),
230-
)
231236

232237
return img
233238

0 commit comments

Comments
 (0)