Validate num_inference_steps > 0 in DDPMScheduler.set_timesteps (#13394)#13705
Open
jbbqqf wants to merge 1 commit into
Open
Validate num_inference_steps > 0 in DDPMScheduler.set_timesteps (#13394)#13705jbbqqf wants to merge 1 commit into
num_inference_steps > 0 in DDPMScheduler.set_timesteps (#13394)#13705jbbqqf wants to merge 1 commit into
Conversation
…uggingface#13394) `DDPMScheduler.set_timesteps(num_inference_steps=0)` (or negative) silently left the scheduler with an empty schedule and stale state, instead of failing fast like other schedulers do. This made the bug invisible until a downstream `step()` call produced wrong results. Add the same `num_inference_steps must be a positive integer` check that `scheduling_block_refinement` already has, propagated to `DDPMScheduler` and its `# Copied from` sibling `DDPMSchedulerParallel` via `make fix-copies`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13394.
Summary
DDPMScheduler.set_timesteps(num_inference_steps=0)(or negative) silently accepted the input, rannp.linspace(0, num_train_timesteps - 1, 0)to produce an empty schedule, and left the scheduler in a broken state. The bug only surfaced later whenstep()operated on stale state — instead of failing fast.`scheduling_block_refinement.py` already validates
num_inference_steps > 0. This PR brings DDPM in line.Fix
Add the same guard in
DDPMScheduler.set_timesteps(and propagate to its# Copied fromsibling `DDPMSchedulerParallel` viapython utils/check_copies.py --fix_and_overwrite):(The pre-existing too-large check is preserved.)
Reproduce BEFORE/AFTER yourself (copy-paste)
What I ran locally
The new `test_set_timesteps_rejects_non_positive_num_inference_steps` covers both
0and-1, and verifies the scheduler still works for a positive value afterwards. It fails onorigin/main(no exception raised) and passes on this branch.Notes
# Copied fromconsumers exist forDDPMScheduler.set_timestepsviapython utils/check_copies.py.🤖 Disclosure: Authored with assistance from Claude (Anthropic), reviewed and tested by me.