Fix NaN samples from DDPM fixed_large_log variance - #14571
Open
lllakshit wants to merge 1 commit into
Open
Conversation
_get_variance(fixed_large_log) returns log(beta). step() treated that value like a variance and took sqrt(), which is NaN for beta < 1. Convert log variance with exp(0.5 * log) for both DDPMScheduler and DDPMParallelScheduler, matching learned_range and the fixed_large scale. Fixes huggingface#14569
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.
What this PR does
DDPMScheduler._get_variance(..., variance_type="fixed_large_log")(Glide max_log) returnslog(beta).step()treated that value like a linear variance and tooksqrt(), which is NaN forbeta < 1. The same path exists inDDPMParallelScheduler.Sampling now converts log variance with
exp(0.5 * log), the same transform already used forlearned_range. That is equivalent tosqrt(beta)/fixed_large, so the intended Improved-DDPM / Glide scale is restored and samples stay finite.Fixes #14569
Tests
tests/schedulers/test_scheduler_ddpm.py::DDPMSchedulerTest::test_fixed_large_log_sampling_is_finite_and_matches_fixed_largetests/schedulers/test_scheduler_ddpm_parallel.py::DDPMParallelSchedulerTest::test_fixed_large_log_sampling_is_finite_and_matches_fixed_largeBoth assert
fixed_large_logsamples are finite and matchfixed_largeat the same seed.Self-review
mainwith the issue reproduction: both schedulers produced NaNs at t=500 before the change._get_variancestill returns log-space values forfixed_large_log(Glide max_log). Only thestep()noise scale is corrected, so callers of_get_variancekeep the old contract.batch_step_no_noisedoes not add variance, so it did not need a change.fixed_small/fixed_large/fixed_small_log/learned_rangebranches are unchanged.