Skip to content

fix: Fix double-shift in FlowMatchEulerDiscreteScheduler.__init__ - #14508

Open
Ricardo-M-L wants to merge 1 commit into
huggingface:mainfrom
Ricardo-M-L:fix/flow-match-scheduler-double-shift-clean
Open

fix: Fix double-shift in FlowMatchEulerDiscreteScheduler.__init__#14508
Ricardo-M-L wants to merge 1 commit into
huggingface:mainfrom
Ricardo-M-L:fix/flow-match-scheduler-double-shift-clean

Conversation

@Ricardo-M-L

Copy link
Copy Markdown
Contributor

Clean rebase of fix/flow-match-scheduler-double-shift

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
@github-actions github-actions Bot added schedulers size/S PR with diff < 50 LOC labels Aug 17, 2026
@github-actions

Copy link
Copy Markdown
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. Fixes #1234) to the PR description so the issue is linked. See the contribution guide for more details. If this PR intentionally does not fix a tracked issue, a maintainer can add the no-issue-needed label to silence this reminder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

schedulers size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant