Repository navigation
Conversation
…ultistepScheduler Propagates two fixes from DPMSolverMultistepScheduler (scheduling_dpmsolver_multistep.py) to its sibling multistep schedulers: 1. Guard lower_order_final when the last two sigmas are equal (e.g. final_sigmas_type='sigma_min' or algorithm_type in ['sde-dpmsolver++', 'sde-dpmsolver']). Without (len(self.sigmas) > 1 and self.sigmas[-1] == self.sigmas[-2]), taking second- or third-order multistep updates on a zero-width final step divides by h = lambda_t - lambda_s = 0 and corrupts the sample with NaNs. For CosineDPMSolverMultistepScheduler, also guard self.noise_sampler on a zero-width step so BrownianTreeNoiseSampler does not divide by zero (0.0 * NaN = NaN). Unskips the long-standing TestEDMDPMSolverMultistepScheduler.test_solver_order_and_type test. 2. Slice sigmas[-1:] instead of extracting sigmas[-1].item() when final_sigmas_type='sigma_min' in EDMDPMSolverMultistepScheduler and CosineDPMSolverMultistepScheduler, avoiding unnecessary tensor-to-Python scalar extraction during set_timesteps. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Parth Vadera <parthvadera@gmail.com>
Contributor
|
Hi @deep1blue, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. Please note that PRs without a linked issue are likely to be automatically closed 10 days after this notice. Once the PR links an issue (or gets the |
This branch has not been deployed
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 does this PR do?
Propagates two fixes from
DPMSolverMultistepScheduler(scheduling_dpmsolver_multistep.py) to its sibling multistep schedulers (EDMDPMSolverMultistepScheduler,CosineDPMSolverMultistepScheduler, andDPMSolverMultistepInverseScheduler):Prevent
NaNdivision-by-zero on zero-width final step (self.sigmas[-1] == self.sigmas[-2]):DPMSolverMultistepScheduler.step()(scheduling_dpmsolver_multistep.py),lower_order_finalis triggered when:EDMDPMSolverMultistepScheduler,CosineDPMSolverMultistepScheduler, andDPMSolverMultistepInverseSchedulerwere missing theor (len(self.sigmas) > 1 and self.sigmas[-1] == self.sigmas[-2])check.final_sigmas_type="sigma_min"(oralgorithm_type in ["sde-dpmsolver++", "sde-dpmsolver"]inEDMDPMSolverMultistepScheduler), the last two entries ofself.sigmasare identical (sigma_t == sigma_s0), solower_order_final=Falsewithsolver_order >= 2, takingdpm_solver_second_order_updateordpm_solver_third_order_updatedivides byh = 0(1.0 / h,(exp(-h) - 1.0) / h,r0 = h_0 / h) and producesNaNs across the entire output tensor.CosineDPMSolverMultistepScheduler.step(), even with first-order update on a zero-width final step (sigma_t == sigma_s),self.noise_sampler(sigma_s, sigma_t)(BrownianTreeNoiseSampler) divides bysqrt(|t1 - t0|) = 0, producingNaNnoise (0.0 * NaN = NaNin IEEE-754). Guardingself.noise_samplerwhenself.sigmas[self.step_index + 1] == self.sigmas[self.step_index]avoids theNaNnoise.@unittest.skip("TODO (patil-suraj): Fix this test")onTestEDMDPMSolverMultistepScheduler.test_solver_order_and_type.Avoid unnecessary scalar
.item()extraction inset_timesteps():final_sigmas_type == "sigma_min",EDMDPMSolverMultistepSchedulerandCosineDPMSolverMultistepSchedulercalledsigma_last = sigmas[-1].item()followed bytorch.tensor([sigma_last], ...), whereasDPMSolverMultistepSchedulerslicessigmas[-1:]directly (torch.cat([sigmas, sigmas[-1:]])).Before submitting
TestEDMDPMSolverMultistepScheduler.test_solver_order_and_typeand addedtest_zero_width_final_stepintests/schedulers/test_scheduler_edm_dpmsolver_multistep.pyandtests/schedulers/test_scheduler_dpm_multi_inverse.py(66 passed).Credits & Acknowledgments
sigma_minentries (h = 0) causeNaNdivision-by-zero in higher-order multistep updates whenlower_order_final=False, which led to auditing and fixing the sibling schedulers (EDMDPMSolverMultistepScheduler,CosineDPMSolverMultistepScheduler, andDPMSolverMultistepInverseScheduler).