fix(ltx2): use actual video sequence length for dynamic timestep shift#14266
Open
sergioperezcheco wants to merge 1 commit into
Open
fix(ltx2): use actual video sequence length for dynamic timestep shift#14266sergioperezcheco wants to merge 1 commit into
sergioperezcheco wants to merge 1 commit into
Conversation
calculate_shift() was being called with max_image_seq_len as its first argument (image_seq_len), which collapses mu to a constant max_shift regardless of resolution or frame count. With use_dynamic_shifting=True this had no effect. Pass the sample's packed sequence length (latent_num_frames * latent_height * latent_width) instead, matching the Flux/SD3 pipelines and the LTX reference (math.prod(latent.shape[2:])). Fixes huggingface#14243 Signed-off-by: Sergio Perez <sergio@checo.cc>
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.
LTX2Pipeline computed the dynamic-shift mu with max_image_seq_len as the image_seq_len argument to calculate_shift(), which collapses mu to a constant (the max_shift value) regardless of resolution or frame count. With use_dynamic_shifting=True enabled this had no effect at all — the shift never actually varied with the sample.
The fix passes the sample's real packed sequence length (latent_num_frames * latent_height * latent_width) as image_seq_len, matching the Flux/SD3 pipelines and the LTX reference implementation (math.prod(latent.shape[2:])). This value was already computed earlier in the call (it even existed as a commented-out line), and the latent dims are defined a few lines above the timestep section. I also removed the stale commented line since the variable is now used for real.
This is a behavior change: mu will now scale with the actual sequence length rather than always hitting max_shift, so the timestep distribution will shift for all LTX2 generations. That's the intended behavior of dynamic shifting, but flagging it since it's not a no-op. Fixes #14243.