Skip to content

fix(ddim): validate eta is in [0, 1] in DDIMPipeline#13367

Merged
yiyixuxu merged 4 commits intohuggingface:mainfrom
NIK-TIGER-BILL:fix/ddim-pipeline-validate-eta
Apr 3, 2026
Merged

fix(ddim): validate eta is in [0, 1] in DDIMPipeline#13367
yiyixuxu merged 4 commits intohuggingface:mainfrom
NIK-TIGER-BILL:fix/ddim-pipeline-validate-eta

Conversation

@NIK-TIGER-BILL
Copy link
Copy Markdown
Contributor

What does this PR do?

Adds input validation for the eta parameter in DDIMPipeline.__call__.

Fixes #13362

Context

The DDIM paper defines η (eta) as a value that lies strictly in [0, 1]:

  • η = 0 → deterministic DDIM
  • η = 1 → DDPM

The docstring already documents this constraint:

"eta corresponds to η in paper and should be between [0, 1]"

However, no runtime check existed, so out-of-range values (negative or > 1) were silently accepted and could produce undefined/unintended sampling behaviour.

Change

Add a ValueError guard immediately after the image-shape computation, before the denoising loop:

if not 0.0 <= eta <= 1.0:
    raise ValueError(
        f"`eta` must be between 0 and 1 (inclusive), but received {eta}. "
        "A value of 0 corresponds to DDIM and 1 corresponds to DDPM."
    )

Before submitting

Who can review?

@pcuenca @DN6

The DDIM paper defines η (eta) as a value that must lie in [0, 1]:
η=0 corresponds to deterministic DDIM, η=1 corresponds to DDPM.
The docstring already documented this constraint, but no runtime
validation was in place, so users could silently pass out-of-range
values (e.g. negative or >1) without any error.

Add an explicit ValueError check before the denoising loop so that
invalid eta values are caught early with a clear message.

Fixes huggingface#13362

Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
@sayakpaul sayakpaul requested a review from yiyixuxu March 30, 2026 09:46
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@yiyixuxu
Copy link
Copy Markdown
Collaborator

thanks for the PR, can you change it to a warning?
honestly I think the documentation is sufficient

Per maintainer feedback from @yiyixuxu — the documentation is
sufficient; a hard ValueError is too strict. Replace with a
UserWarning so callers are informed without breaking existing code
that passes eta outside [0, 1].

Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
@NIK-TIGER-BILL
Copy link
Copy Markdown
Contributor Author

Thanks for the feedback, @yiyixuxu! Changed to a warnings.warn (UserWarning) in the latest commit — the validation is still there to inform callers, but no longer raises an exception. Let me know if the wording looks good to you!

image_shape = (batch_size, self.unet.config.in_channels, *self.unet.config.sample_size)

if not 0.0 <= eta <= 1.0:
warnings.warn(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claude what do you think?

image_shape = (batch_size, self.unet.config.in_channels, *self.unet.config.sample_size)

if not 0.0 <= eta <= 1.0:
warnings.warn(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we change it to use logger.warning? to be consistent with all other pipelines

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! Updated in the latest commit — switched from warnings.warn() to logger.warning() to match the convention used in all other diffusers pipelines. Also removed the now-unused import warnings.

…tion

Address review request from @yiyixuxu: switch from warnings.warn() to
logger.warning() to be consistent with all other diffusers pipelines.

The eta validation check itself (0.0 <= eta <= 1.0) is unchanged.

Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
Copy link
Copy Markdown
Collaborator

@yiyixuxu yiyixuxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@yiyixuxu yiyixuxu merged commit 8070f6e into huggingface:main Apr 3, 2026
9 of 11 checks passed
terarachang pushed a commit to terarachang/diffusers that referenced this pull request Apr 30, 2026
* fix(ddim): validate eta is in [0, 1] in DDIMPipeline.__call__

The DDIM paper defines η (eta) as a value that must lie in [0, 1]:
η=0 corresponds to deterministic DDIM, η=1 corresponds to DDPM.
The docstring already documented this constraint, but no runtime
validation was in place, so users could silently pass out-of-range
values (e.g. negative or >1) without any error.

Add an explicit ValueError check before the denoising loop so that
invalid eta values are caught early with a clear message.

Fixes huggingface#13362

Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>

* fix(ddim): downgrade eta out-of-range from error to warning

Per maintainer feedback from @yiyixuxu — the documentation is
sufficient; a hard ValueError is too strict. Replace with a
UserWarning so callers are informed without breaking existing code
that passes eta outside [0, 1].

Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>

* fix(ddim): use logger.warning instead of warnings.warn for eta validation

Address review request from @yiyixuxu: switch from warnings.warn() to
logger.warning() to be consistent with all other diffusers pipelines.

The eta validation check itself (0.0 <= eta <= 1.0) is unchanged.

Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>

---------

Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
Co-authored-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
Co-authored-by: YiYi Xu <yixu310@gmail.com>
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.

DDIMPipeline does not validate eta range despite documented constraint [0, 1]

3 participants