Skip to content

fix: Fix image_seq_len in Lumina2Pipeline (channel count → patch tokens) - #14514

Open
Ricardo-M-L wants to merge 1 commit into
huggingface:mainfrom
Ricardo-M-L:fix/lumina2-image-seq-len-clean
Open

fix: Fix image_seq_len in Lumina2Pipeline (channel count → patch tokens)#14514
Ricardo-M-L wants to merge 1 commit into
huggingface:mainfrom
Ricardo-M-L:fix/lumina2-image-seq-len-clean

Conversation

@Ricardo-M-L

Copy link
Copy Markdown
Contributor

Clean rebase

`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
@github-actions github-actions Bot added size/S PR with diff < 50 LOC pipelines and removed 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant