fix(scheduler): store sigma_min/max before shifting to prevent double-shift in FlowMatchEulerDiscreteScheduler (#13243)#13962
Open
adhavan18 wants to merge 1 commit into
Conversation
…-shift (huggingface#13243) FlowMatchEulerDiscreteScheduler.__init__ computed sigma_min and sigma_max from the already-shifted sigmas. When set_timesteps regenerated the sigma grid from those bounds via _sigma_to_t -> linspace -> /num_train_timesteps, it recovered the shifted values and then applied the shift formula a second time, producing a doubly-shifted (and therefore incorrect) schedule. Fix: record sigma_min and sigma_max from the raw linear sigmas (timesteps / num_train_timesteps) before the shift formula is applied, so set_timesteps starts from the correct unshifted bounds and the shift is applied exactly once. Regression test: test_set_timesteps_no_double_shift verifies that set_timesteps(num_inference_steps=1000) reproduces the same sigma grid that __init__ stored, for a scheduler with shift=3.0.
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 fix?
Fixes #13243 —
FlowMatchEulerDiscreteScheduler.set_timestepswas applying the shift formula twice, producing an incorrect (doubly-shifted) sigma schedule.Root cause
In
__init__,sigma_minandsigma_maxwere stored after the shift formula was applied:Then in
set_timesteps(default path,sigmas=None,timesteps=None):Because
_sigma_to_t(σ) = σ × Nand the division byNis its exact inverse,sigmasinset_timestepsends up equal to the already-shiftedsigma_min…sigma_maxrange — and then the shift formula runs a second time on those values.Fix
Record
sigma_minandsigma_maxfrom the raw linear sigmas, before the shift is applied. The shift formula inset_timestepsthen runs exactly once on the correct unshifted inputs.Impact
Any model that calls
set_timestepswithout passing explicitsigmasortimesteps— the default inference path for FLUX, Stable Diffusion 3, Wan, HiDream, CogVideoX, and all other FlowMatch-based models — was affected. Withshift > 1, the schedule was always more compressed than intended.Tests
Added
test_set_timesteps_no_double_shift: verifies thatset_timesteps(num_inference_steps=1000)produces the same sigma grid that__init__stores, for a scheduler withshift=3.0. All 14 tests pass.