Set begin_index for flow-matching pipelines to avoid slow index_for_timestep#13206
Open
kirillsst wants to merge 1 commit intohuggingface:mainfrom
Open
Set begin_index for flow-matching pipelines to avoid slow index_for_timestep#13206kirillsst wants to merge 1 commit intohuggingface:mainfrom
begin_index for flow-matching pipelines to avoid slow index_for_timestep#13206kirillsst wants to merge 1 commit intohuggingface:mainfrom
Conversation
…r_timestep` The `_init_step_index` method falls back to `index_for_timestep()` which uses `.nonzero()` causing an expensive DtoH sync when `begin_index` is not set. This was already fixed in Flux and a few other pipelines but was missing across most flow-matching pipelines. Add `scheduler.set_begin_index(0)` before the denoising loop in all text-to-image/video pipelines that use FlowMatch schedulers. For img2img pipelines with strength-based schedule truncation (wan_video2video, ltx_condition), set the begin index to the appropriate start offset inside `get_timesteps()`. Fixes huggingface#9417
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.
Summary
scheduler.set_begin_index(0)before the denoising loop in all flow-matching pipelines that were missing itwan_video2video,ltx_condition), set the begin index to the appropriate start offset insideget_timesteps()begin_index,_init_step_index()falls back toindex_for_timestep()which uses.nonzero()causing an expensive DtoH sync on every firstscheduler.step()callDetails
The
FlowMatchEulerDiscreteScheduler._init_step_indexmethod has two paths:This PR ensures all flow-matching pipelines take the fast path, matching the pattern already established in
pipeline_flux.py.Fixes #9417
Test plan
ruff checkpasses on all 56 modified filesruff format --checkpasses on all 56 modified files