Skip to content

[Bugfix][MoE] Fix fused block-scale orientation - #50727

Merged
AndreasKaratzas merged 16 commits into
mainfrom
akaratza_fix_fused_block_scales
Aug 11, 2026
Merged

AndreasKaratzas merged 16 commits into
mainfrom
akaratza_fix_fused_block_scales

Conversation

@AndreasKaratzas

@AndreasKaratzas AndreasKaratzas commented Aug 2, 2026

Copy link
Copy Markdown
Member

PR #50137 fixed fused per-channel scale loading, but shape-based orientation inference cannot reliably recover the checkpoint layout after both dimensions have been divided by the quantization block size. This causes Qwen3-VL's fused gate/up and down-projection block scales to load in the wrong orientation, producing this large-model acceptance failure.

Represent the fused checkpoint layout explicitly instead of inferring it from tensor shapes.

  • Add an is_fused_checkpoint_transposed setting from the model layer through FusedMoEFactory to RoutedExperts.
  • Enable the transposed layout for Qwen3-VL MoE while preserving the decoder-layer override used by downstream models such as InternS1Pro.
  • Transpose fused weights and canonical block scales, while leaving per-channel scales and other independently laid-out quantization metadata unchanged.
  • Cover standard and transposed w1/w2 weights and scales, including rectangular and square block-scale layouts.

Validation

  • .venv/bin/pre-commit run --files vllm/model_executor/models/qwen3_vl_moe.py
  • .venv/bin/python -m py_compile vllm/model_executor/models/qwen3_vl_moe.py
  • Buildkite CI #82908 is running for commit fc82db14f0686d5709965f868c82d21f5b6b3e5b.
  • No additional model evaluation was run for the constructor compatibility follow-up because it restores the existing decoder-layer injection contract and does not change inference outputs.

Duplicate work

This extends #50137 by handling explicitly transposed fused checkpoints and is not a duplicate of another open fix.

AI assistance

OpenAI Codex was used to inspect the Buildkite failures and prepare the constructor compatibility fix.

Signed-off-by: Andreas Karatzas <akaratza@amd.com>
@mergify mergify Bot added the bug Something isn't working label Aug 2, 2026
@AndreasKaratzas
AndreasKaratzas marked this pull request as ready for review August 2, 2026 05:59

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@AndreasKaratzas AndreasKaratzas added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 2, 2026

@shen-shanshan shen-shanshan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Others LGTM.

# contains the global intermediate dimension. Reconstruct that
# global shape: w1/w3 shard their first data axis and w2 its second.
expected_global_shape = list(target_shape[-2:])
tp_shard_axis = 1 if shard_id == "w2" else 0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assisted-by: OpenAI Codex
Signed-off-by: Andreas Karatzas <akaratza@amd.com>
mergify Bot and others added 2 commits August 4, 2026 04:46
Assisted-by: OpenAI Codex
Signed-off-by: Andreas Karatzas <akaratza@amd.com>
@AndreasKaratzas
AndreasKaratzas enabled auto-merge (squash) August 4, 2026 04:56
@AndreasKaratzas

Copy link
Copy Markdown
Member Author

/ci run

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

✅ Triggered Buildkite CI #82542 for commit c4b51da49a52.

@mgoin mgoin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m concerned this patch is adding another shape heuristic over the underlying layout problem.

Before #47058, the Qwen3-VL loader explicitly knew that fused expert tensors were transposed. After that logic was centralized, RoutedExperts began inferring orientation from tensor dimensions. #50137 fixed one consequence of that inference for per-channel scales, and this PR adds a destination-shape fallback for block scales. The fallback in the PR works for the reported rectangular, unpadded shapes, but it is not generally safe. For instance, square block-scales would be not handled correctly.

My recommendation is to represent the fused checkpoint layout explicitly rather than infer it from shapes. For example, a fused_checkpoint_layout / is_fused_checkpoint_transposed property passed through FusedMoE to RoutedExperts, set by Qwen3-VL or the quantization scheme.

@AndreasKaratzas

Copy link
Copy Markdown
Member Author

I’m concerned this patch is adding another shape heuristic over the underlying layout problem.

Before #47058, the Qwen3-VL loader explicitly knew that fused expert tensors were transposed. After that logic was centralized, RoutedExperts began inferring orientation from tensor dimensions. #50137 fixed one consequence of that inference for per-channel scales, and this PR adds a destination-shape fallback for block scales. The fallback in the PR works for the reported rectangular, unpadded shapes, but it is not generally safe. For instance, square block-scales would be not handled correctly.

My recommendation is to represent the fused checkpoint layout explicitly rather than infer it from shapes. For example, a fused_checkpoint_layout / is_fused_checkpoint_transposed property passed through FusedMoE to RoutedExperts, set by Qwen3-VL or the quantization scheme.

Ok, that actually makes sense, I wanted minimal diff tbh 😅 But instead of just patching this, I took upon your direction, lmk if the new is_fused_checkpoint_transposed makes sense :) Also, should we run all tests on this? Or generally enable some optional ones cause it's a wider diff now.

@mergify mergify Bot added the qwen Related to Qwen models label Aug 6, 2026
Co-authored-by: OpenAI Codex <noreply@openai.com>
Signed-off-by: Andreas Karatzas <akaratza@amd.com>
@AndreasKaratzas
AndreasKaratzas force-pushed the akaratza_fix_fused_block_scales branch from 8552723 to 4bf6ca4 Compare August 6, 2026 17:20
@AndreasKaratzas

Copy link
Copy Markdown
Member Author

/ci run

@AndreasKaratzas

Copy link
Copy Markdown
Member Author

/ci run

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

✅ Triggered Buildkite CI #82795 for commit 54307aad7f00.

@AndreasKaratzas

Copy link
Copy Markdown
Member Author

/ci retry

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

✅ Queued 4 failed job(s) for retry in Buildkite CI #82795.

Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Andreas Karatzas <Andreas.Karatzas@amd.com>

Copy link
Copy Markdown
Member Author

/ci run

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

✅ Triggered Buildkite CI #82908 for commit fc82db14f068.

@AndreasKaratzas

Copy link
Copy Markdown
Member Author

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #83187 for commit 6e2345697d99.

AndreasKaratzas added a commit that referenced this pull request Aug 11, 2026
Leave explicit checkpoint layout handling to #50727.

Assisted-by: OpenAI Codex
Signed-off-by: Andreas Karatzas <akaratza@amd.com>
@AndreasKaratzas

Copy link
Copy Markdown
Member Author

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #83382 for commit b16e4a94584c.

@AndreasKaratzas
AndreasKaratzas merged commit 36f4630 into main Aug 11, 2026
121 checks passed
@AndreasKaratzas
AndreasKaratzas deleted the akaratza_fix_fused_block_scales branch August 11, 2026 20:05
zyp2014 pushed a commit to zyp2014/vllm that referenced this pull request Aug 21, 2026
Signed-off-by: Andreas Karatzas <akaratza@amd.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working qwen Related to Qwen models ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants