Skip to content

Fix: LCMScheduler advances the generator on the final step of a strength-truncated custom schedule - #15364

Open
SIDDARTHAREDDY8 wants to merge 1 commit into
huggingface:mainfrom
SIDDARTHAREDDY8:oss-bhai-2026-11-20-lcm-15288
Open

SIDDARTHAREDDY8 wants to merge 1 commit into
huggingface:mainfrom
SIDDARTHAREDDY8:oss-bhai-2026-11-20-lcm-15288

Conversation

@SIDDARTHAREDDY8

Copy link
Copy Markdown

Same bug class as #15288 (fixed for TCDScheduler in #15301): with a custom timestep schedule and strength < 1, set_timesteps truncates the schedule but num_inference_steps keeps the pre-truncation count, so the actual final step sampled noise and advanced the generator even though that noise is never used. Guard on the actual schedule length instead.

Follow-up to the review on #15301, which suggested applying the same one-line change to LCMScheduler.step.

Changes:

  • src/diffusers/schedulers/scheduling_lcm.py: step_index != num_inference_steps - 1 -> step_index != len(self.timesteps) - 1
  • tests/schedulers/test_scheduler_lcm.py: regression test test_truncated_custom_timesteps_final_step_preserves_generator covering single-step ([999, 499, 19], strength 0.5 -> [19]) and multi-step ([999, 899, 799, 699, 599], strength 0.6 -> [799, 699, 599]) truncation for epsilon and v_prediction, asserting the generator state is untouched on the final step only.

Verification (CPU, torch 2.14): the new test fails on unpatched code (generator advances on the final step) and passes with the fix; the full test_scheduler_lcm.py suite passes, 35 passed. Ruff clean.

This contribution was developed with AI assistance.

…schedule

Same bug class as huggingface#15288 (fixed for TCDScheduler in huggingface#15301):
`strength < 1` truncates a custom timestep schedule, but
`num_inference_steps` keeps the pre-truncation count, so the actual
final step sampled noise and advanced the generator even though that
noise is never used. Guard on the actual schedule length instead.

Follow-up to the review on huggingface#15301.

Signed-off-by: SIDDARTHA REDDY <75976672+SIDDARTHAREDDY8@users.noreply.github.com>
Signed-off-by: Siddartha Reddy Chinthala <siddarthareddychinthala@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

schedulers size/M PR with diff < 200 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant