fix: Fix image_seq_len in Lumina2Pipeline (channel count → patch tokens) - #14514
Open
Ricardo-M-L wants to merge 1 commit into
Open
fix: Fix image_seq_len in Lumina2Pipeline (channel count → patch tokens)#14514Ricardo-M-L wants to merge 1 commit into
image_seq_len in Lumina2Pipeline (channel count → patch tokens)#14514Ricardo-M-L wants to merge 1 commit into
Conversation
`Lumina2Pipeline.__call__` computed `mu = calculate_shift(image_seq_len, ...)`
with `image_seq_len = latents.shape[1]`. Unlike Flux / QwenImage, Lumina2
does **not** pack latents before handing them to the transformer, so
`latents.shape` is `(B, C, H, W)` and `shape[1]` is the VAE channel count
(typically 16) rather than the post-patch sequence length.
The transformer itself computes the real value:
post_patch_height, post_patch_width = H // p, W // p
image_seq_len = post_patch_height * post_patch_width
(`src/diffusers/models/transformers/transformer_lumina2.py:264-267`, with
`p = self.patch_size`, default 2).
At 512×512 this means the pipeline was shifting based on `image_seq_len = 16`
instead of `1024`. Since `calculate_shift` is a linear interpolation over the
range `[base_image_seq_len, max_image_seq_len] = [256, 4096]` clamped to
`[base_shift, max_shift] = [0.5, 1.15]`, `16` lands well below the base and
produces a shift that is independent of resolution — defeating the whole
point of `use_dynamic_shifting`.
Compute the same expression the transformer uses, via
`self.transformer.config.patch_size`, so `mu` scales with the real token
count. No behavior change at 256×256 latents worth of patches (the only size
where `16 == (H/p)·(W/p)`, which is nonsensical for images anyway).
Fixes huggingface#12913
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