fix: Fix double-shift in FlowMatchEulerDiscreteScheduler.__init__ - #14508
Open
Ricardo-M-L wants to merge 1 commit into
Open
fix: Fix double-shift in FlowMatchEulerDiscreteScheduler.__init__#14508Ricardo-M-L wants to merge 1 commit into
FlowMatchEulerDiscreteScheduler.__init__#14508Ricardo-M-L wants to merge 1 commit into
Conversation
When `use_dynamic_shifting=False` and `shift != 1.0`, calling
`set_timesteps(num_train_timesteps)` produced sigmas that were
shifted twice, so the schedule visible to inference did not match
the schedule `__init__` already stored on `self.sigmas`.
Root cause: `__init__` applied the static shift to `sigmas` and then
read `self.sigma_min` / `self.sigma_max` from the *post-shift* tensor.
`set_timesteps` later re-derives a sigma schedule by linspace-ing
between `_sigma_to_t(sigma_max)` and `_sigma_to_t(sigma_min)`,
dividing by `num_train_timesteps` (recovering the stored, already-
shifted sigmas), and then applying `shift` again at
sigmas = self.shift * sigmas / (1 + (self.shift - 1) * sigmas)
Concretely with `shift=3.0`, `num_train_timesteps=1000`:
* `__init__`: last sigma = 3 * (1/1000) / (1 + 2 * 1/1000) ≈ 0.00299
* `set_timesteps(1000)` before this fix: last sigma ≈ 0.00893
(≈3× off — the shift applied on top of itself)
Fix: record `sigma_min` / `sigma_max` from the raw, pre-shift sigmas
(which are `1/num_train_timesteps` and `1.0` by construction). The
shift is then applied exactly once — inside `set_timesteps`, on the
caller's chosen inference schedule — matching what the stored
`self.sigmas` represented all along. No external caller reads these
values post-init: the only in-repo writers are the Z-Image pipelines,
which overwrite `scheduler.sigma_min = 0.0` before sampling.
Fixes huggingface#13243
Contributor
|
Hi @Ricardo-M-L, 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. |
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.
Clean rebase of fix/flow-match-scheduler-double-shift