Skip to content

Fix missing validation for num_inference_steps in DDPMScheduler and add tests#13395

Open
Akash504-ai wants to merge 1 commit intohuggingface:mainfrom
Akash504-ai:fix-ddpm-num-inference-steps-zero
Open

Fix missing validation for num_inference_steps in DDPMScheduler and add tests#13395
Akash504-ai wants to merge 1 commit intohuggingface:mainfrom
Akash504-ai:fix-ddpm-num-inference-steps-zero

Conversation

@Akash504-ai
Copy link
Copy Markdown

What does this PR do?

This PR fixes a missing validation in DDPMScheduler.set_timesteps.

Currently, passing num_inference_steps=0 does not raise an error and can lead to invalid internal state or unexpected behavior.

This behavior is inconsistent with DDIMScheduler, which already validates this case.

Fix

  • Added validation in DDPMScheduler.set_timesteps:

    if num_inference_steps is not None and num_inference_steps <= 0:
        raise ValueError("num_inference_steps must be > 0")

Tests

Added new unit test:

  • test_num_inference_steps_zero_raises in:
    - test_scheduler_ddpm.py
    - test_scheduler_ddim.py (for consistency)

Result

  • Ensures consistent behavior across schedulers
  • Prevents silent invalid configurations
  • Improves robustness of scheduler API

Fixes #13394

Validation

  • All relevant scheduler tests pass locally:
    • pytest tests/schedulers/test_scheduler_ddpm.py
    • pytest tests/schedulers/test_scheduler_ddim.py

@yiyixuxu

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

Labels

None yet

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