Fix double timestep shifting in FlowMatchEulerDiscreteScheduler.set_timesteps (#13243)#13706
Open
jbbqqf wants to merge 1 commit intohuggingface:mainfrom
Open
Fix double timestep shifting in FlowMatchEulerDiscreteScheduler.set_timesteps (#13243)#13706jbbqqf wants to merge 1 commit intohuggingface:mainfrom
FlowMatchEulerDiscreteScheduler.set_timesteps (#13243)#13706jbbqqf wants to merge 1 commit intohuggingface:mainfrom
Conversation
…timesteps` (huggingface#13243) `__init__` records `self.sigma_max` / `self.sigma_min` *after* applying the `shift * sigmas / (1 + (shift - 1) * sigmas)` transform. `set_timesteps` then fed those already-shifted endpoints back into `np.linspace(...)` and applied the same shift again, producing a different schedule for the same `(num_train_timesteps, num_inference_steps, shift)` triple than `__init__`. Use the pre-shift `[num_train_timesteps, ..., 1]` range directly when no custom timesteps are provided so the shift is applied exactly once. After the fix, `__init__` and `set_timesteps(num_train_timesteps)` produce identical sigmas (to atol=1e-5) for every value of `shift` (verified for 1.0 and 3.0). `self.sigma_max`/`self.sigma_min` are left as-is to preserve their public attribute semantics for any downstream consumers.
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.
Fixes #13243.
Summary
FlowMatchEulerDiscreteScheduler.__init__recordsself.sigma_max/self.sigma_minafter applying the standard `shift * sigmas / (1 + (shift - 1) * sigmas)` transform:set_timestepsthen fed those already-shifted endpoints back into the linspace and applied the same shift again:So calling
scheduler.set_timesteps(num_train_timesteps)produced a different schedule than the one__init__had already computed, for the same(num_train_timesteps, num_inference_steps, shift)triple.Fix
Use the pre-shift
[num_train_timesteps, ..., 1]range directly when no custom timesteps/sigmas are provided. The shift is then applied exactly once below.self.sigma_max/self.sigma_minare left as-is so any consumer reading them externally keeps the same public semantics.Reproduce BEFORE/AFTER yourself (copy-paste)
I confirmed both runs locally:
origin/main→ match:False(init head[1.0, 0.9997, 0.9993], set_timesteps head[1.0, 0.9991, 0.9982]— visibly different).True.Notes
timesteps/sigmaspaths are unchanged.self.sigma_min/self.sigma_maxkeep their current values.🤖 Disclosure: Authored with assistance from Claude (Anthropic), reproducer run on both refs.