Repository navigation
fix(schedulers): add set_begin_index to PNDMScheduler for img2img timestep alignment - #15431
Open
shravansumanthanan wants to merge 1 commit into
Open
shravansumanthanan wants to merge 1 commit into
shravansumanthanan wants to merge 1 commit into
Conversation
…estep alignment PNDMScheduler was missing the set_begin_index / begin_index interface that img2img pipelines call when they skip the first t_start timesteps (scheduler.timesteps[t_start:]). Without it, hasattr(scheduler, 'set_begin_index') returns False, so pipelines silently skip the call, and the internal counter stays at 0 while the denoising loop starts mid-schedule. This causes step_plms to fire the PLMS corrector branch (counter == 1, the two-step average) at the wrong position, shifting all subsequent multi-step estimates by one slot and producing subtly wrong outputs. Fix: - Add _begin_index = None to __init__ and to set_timesteps (reset on each new run, matching DPMSolverMultistepScheduler behaviour). - Add begin_index property and set_begin_index() method, copied from DPMSolverMultistepScheduler (the canonical source for this interface). - In step_plms, compute effective_counter = counter - begin_index (falls back to counter when begin_index is None / 0) and use it for all counter-relative checks (counter != 1, counter == 0, counter == 1). Closes huggingface#15429
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?
Closes #15429.
PNDMSchedulerwas the only common scheduler missing theset_begin_index/begin_indexinterface. Every img2img and inpaint pipeline already callsset_begin_indexvia:Because
PNDMSchedulerlacked the method, thehasattrguard silently skipped the call. The denoising loop then started fromscheduler.timesteps[t_start:]withcounter = 0, so the PLMS corrector branch (counter == 1) fired at the wrong denoising step — one slot off — producing subtly incorrect samples for all img2img runs withPNDMScheduler.Root cause
step_plmshas two critical counter-based branches:counter != 1counter == 1When
t_start > 0andcounteris never offset, the corrector fires at the second global call instead of the second call within the sub-loop, shifting all subsequent multi-step estimates.Fix
_begin_index = Nonein__init__and reset it inset_timesteps(matchingDPMSolverMultistepScheduler).begin_indexproperty +set_begin_index()method (copied fromDPMSolverMultistepScheduler, the canonical source).step_plms, computeeffective_counter = counter - begin_index(falls back tocounterwhenbegin_indexisNone/0) and use it for all counter-relative comparisons.No behaviour change when
set_begin_indexis never called (defaultbegin_index = None,effective_counter == counter).Who can review?
@sayakpaul @DN6 @yiyixuxu
Checklist
set_begin_index/begin_indexinterface matching other schedulers_begin_indexinset_timestepsfor clean re-usetest_set_begin_index_existsandtest_set_begin_index_img2img_plmsset_begin_indexis not called (backward compatible)