Fix FlowMatchEulerDiscreteScheduler double-shift in set_timesteps#13760
Open
Ricardo-M-L wants to merge 1 commit into
Open
Fix FlowMatchEulerDiscreteScheduler double-shift in set_timesteps#13760Ricardo-M-L wants to merge 1 commit into
Ricardo-M-L wants to merge 1 commit into
Conversation
`__init__` was storing `sigma_min`/`sigma_max` from the post-shift sigma
range when `use_dynamic_shifting=False`. `set_timesteps` then rebuilt
sigmas via `linspace(_sigma_to_t(sigma_max), _sigma_to_t(sigma_min), N)`
— already in shifted space — and applied the same static shift again:
sigmas = self.shift * sigmas / (1 + (self.shift - 1) * sigmas)
So calling `scheduler.set_timesteps(num_train_timesteps)` on a scheduler
constructed with the same args produced a different sigma schedule than
the one cached in `__init__`. For `shift=3, N=1000` the smallest sigma
became 0.00893 vs the init value of 0.00299.
Record the pre-shift sigmas in `__init__` and derive
`sigma_min`/`sigma_max` from those, so `set_timesteps` regenerates the
linear range and the shift is applied exactly once. `self.sigmas` is
unchanged (still post-shift). Added a regression test that constructs
the scheduler, snapshots `self.sigmas`, calls `set_timesteps` with the
same `num_inference_steps`, and asserts the two sigma schedules match.
The `use_dynamic_shifting=True` path is unaffected (no static shift in
`__init__`) and a second test pins that.
Fixes huggingface#13243
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?
Fixes #13243 —
FlowMatchEulerDiscreteScheduler.set_timestepsapplies the static timestep shift a second time whenuse_dynamic_shifting=False, so callingset_timesteps(num_train_timesteps)on a scheduler produces a different sigma schedule than the one__init__cached.Root cause
__init__recordssigma_min/sigma_maxfrom the post-shift sigma range:set_timestepsthen rebuilds sigmas vialinspace(_sigma_to_t(sigma_max), _sigma_to_t(sigma_min), N)— already in shifted space — and applies the same shift again:Reproduction
The same args produce two different schedules.
Fix
Record the pre-shift sigmas in
__init__and derivesigma_min/sigma_maxfrom them.set_timestepsthen regenerates the linear sigma range correctly and the static shift is applied exactly once.self.sigmasis unchanged (still post-shift); only the cached endpoints change.Test
Added
tests/schedulers/test_scheduler_flow_match_euler_discrete.py:test_set_timesteps_matches_init_with_static_shift— fails onmain, passes with the fix.test_dynamic_shifting_is_unaffected— pins that theuse_dynamic_shifting=Truepath is untouched (no static shift in__init__, so this code path never had the bug).Before submitting
Who can review?
@yiyixuxu @DN6