Skip to content

Add validation for non-positive num_inference_steps in DDPMScheduler#14155

Open
sridhar-3009 wants to merge 1 commit into
huggingface:mainfrom
sridhar-3009:fix/13394-ddpm-zero-steps-validation
Open

Add validation for non-positive num_inference_steps in DDPMScheduler#14155
sridhar-3009 wants to merge 1 commit into
huggingface:mainfrom
sridhar-3009:fix/13394-ddpm-zero-steps-validation

Conversation

@sridhar-3009

Copy link
Copy Markdown

What

DDPMScheduler.set_timesteps(0) (or any negative value) silently produced a zero-length timestep tensor. Downstream, this caused a ZeroDivisionError or produced NaN values in the step loop, with no useful error message pointing to the scheduler.

DDIMScheduler already guards against this with an explicit ValueError. This PR adds the same check to DDPMScheduler.

Changes

src/diffusers/schedulers/scheduling_ddpm.py — add a two-line guard in the else branch of set_timesteps, before the existing num_train_timesteps upper-bound check:

if num_inference_steps <= 0:
    raise ValueError(f"`num_inference_steps`: {num_inference_steps} must be a positive integer.")

Closes #13394.

Calling `scheduler.set_timesteps(0)` or a negative value silently
produced a zero-length timestep array that later caused a ZeroDivisionError
or division-by-zero NaN inside the step loop. Add an explicit guard
matching the pattern already present in DDIMScheduler.

Fixes huggingface#13394.
@github-actions github-actions Bot added fixes-issue schedulers size/S PR with diff < 50 LOC and removed fixes-issue labels Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

schedulers size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DDPMScheduler allows num_inference_steps=0 without validation (inconsistent with DDIMScheduler)

1 participant