Skip to content

[AMD] Critical fix enabling Qwen3.8 FP8: restore dropped fused shared-expert weights - #40754

Merged
HaiShaw merged 1 commit into
sgl-project:mainfrom
yichiche:amd/qwen35-moe-shared-expert-fusion-load
Sep 24, 2026
Merged

HaiShaw merged 1 commit into
sgl-project:mainfrom
yichiche:amd/qwen35-moe-shared-expert-fusion-load

Conversation

@yichiche

@yichiche yichiche commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Text-only Qwen3.5-MoE checkpoints (architecture Qwen3_5MoeForCausalLM, e.g. Qwen3.8-2.4T-A95B-FP8) load into Qwen3_5MoeForCausalLM, whose load_weights was missing the shared-expert fusion remapping that the multimodal Qwen3_5MoeForConditionalGeneration.load_weights already implements. On ROCm with aiter shared-expert fusion enabled (SGLANG_USE_AITER=1), Qwen2MoeSparseMoeBlock serves the shared expert as an extra fused MoE slot at index num_experts, but Qwen3_5MoeForCausalLM.load_weights kept num_experts unchanged and never remapped mlp.shared_expert.* onto that slot. Every layer's shared-expert weights were therefore silently dropped ("Parameter ...mlp.shared_expert... not found in params_dict") and the fused slot was left uninitialized, zeroing the shared expert across all layers and collapsing accuracy (gsm8k near random) while the server still loaded and served.

Modifications

  • python/sglang/srt/models/qwen3_5.py, class Qwen3_5MoeForCausalLM:
    • __init__: compute num_fused_shared_experts / enable_shared_expert_fusion when aiter fusion is active, via a new _get_num_fused_shared_experts() that scans local MoE layers (PP-safe: non-local slots are PPMissingLayer with no .mlp).
    • load_weights: grow make_expert_params_mapping(num_experts=...) by the fused shared count when fusion is on; extend fused_expert_params_mapping with the shared-slot entries; remap mlp.shared_expert.* -> mlp.experts.{num_experts}.*; load the fused shared slot into experts.w13_weight / experts.w2_weight.
  • This mirrors the existing, working handling in Qwen3_5MoeForConditionalGeneration.load_weights (added in [AMD] Enable share expert fusion with router experts for Qwen3.5 BF16 & FP8 #20736 for the multimodal path) so the text-only entry class behaves identically.

Accuracy Tests

Verified on Qwen3.8-2.4T-A95B-FP8, TP8 / PP2, 2x MI300X, --attention-backend aiter, SGLANG_USE_AITER=1, --kv-cache-dtype fp8_e4m3:

Metric Before fix After fix
mlp.shared_expert.* not found in params_dict warnings (per rank set) 1104 0
Shared expert loaded (per layer) dropped (zeroed) loaded into fused slot
Sample gsm8k generations incoherent / wrong coherent and correct

Full gsm8k sweep (sglang few-shot, 1314 questions):

Run gsm8k score
Reference (known-good, pre-regression) 0.9749 (97.49%)
After fix 0.9741 (97.41%)

The shared expert is loaded and accuracy matches the known-good baseline.

Benchmarking and Profiling

N/A - this change only fixes weight loading; it does not alter the compute path or inference speed.

Checklist

Review Process

  1. Ping Merge Oncalls to start the PR flow. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • /tag-run-ci-label, /rerun-failed-ci, /tag-and-rerun-ci
  4. After green CI and required approvals, ask Merge Oncalls to merge.

CI States

Latest PR Test (Base): ❌ Run #35739427018
Latest PR Test (Extra): ❌ Run #35739457890
Latest PR Test (AMD ROCm 10): ❌ Run #35739427563

… aiter fusion

Qwen3_5MoeForCausalLM (text-only entry) was missing the shared-expert fusion
weight remapping that Qwen3_5MoeForConditionalGeneration already has. With aiter
shared-expert fusion enabled (SGLANG_USE_AITER=1), the MoE block serves the
shared expert as an extra fused slot (index == num_experts), but load_weights
kept num_experts unchanged and never remapped mlp.shared_expert.* onto that slot.
The shared-expert checkpoint weights were therefore silently dropped and the
fused slot left uninitialized, zeroing the shared expert on every layer and
collapsing accuracy (gsm8k ~random).

Port the fusion handling into Qwen3_5MoeForCausalLM: detect the fused shared
count (PP-safe scan over local MoE layers), grow the expert params mapping by the
fused count, remap mlp.shared_expert.* to mlp.experts.{num_experts}.*, and load
the fused shared slot into experts.w13_weight / experts.w2_weight.

Verified on Qwen3.8-2.4T-A95B-FP8 (TP8/PP2, MI300X): shared_expert
"not found in params_dict" warnings drop from 1104 to 0.
@yichiche yichiche added the run-ci CI: run the baseline test suite on this PR label Sep 22, 2026
@yichiche yichiche changed the title [AMD] Fix Qwen3.5-MoE text model shared-expert fusion weight load [AMD] Fix for qwen3.8 fp8 Sep 22, 2026
@yichiche yichiche changed the title [AMD] Fix for qwen3.8 fp8 [AMD] Critical fix enabling Qwen3.8 FP8: restore dropped fused shared-expert weights Sep 22, 2026

@HaiShaw HaiShaw 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.

@yichiche Please drive a discussion with Quark to settle on checkpoint naming convention, as current status - every quark field/name change is propagating to upstream common models file, we need a better solution.

@HaiShaw HaiShaw 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.

Please double check

# the checkpoint's mlp.shared_expert.* onto that slot; otherwise the shared
# expert weights are silently dropped and accuracy collapses.
self.num_fused_shared_experts = 0
if _use_aiter and not _disable_shared_experts_fusion():

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.

why _use_aiter not _is_hip, because downstream handling needs to use aiter kernel/imports?

@yichiche yichiche Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

With careful review, I could confirm that _use_aiter is necessary here because this condition should follow whether the shared expert is actually fused, not whether we are simply running on ROCm.

  • The fused shared-expert slot is only created when the AITER path is enabled. So load_weights() should remap shared_expert weights only under the same condition.
  • If we use _is_hip, it would also trigger when SGLANG_USE_AITER=0. In that case there is no fused slot at all, so the loader could remap weights to a layout that was never created.

@HaiShaw

HaiShaw commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Move quark related model file / checkpoint specific handling to ./quark per quark quantized model basis.

@yichiche

yichiche commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

Move quark related model file / checkpoint specific handling to ./quark per quark quantized model basis.

@HaiShaw This PR is different: it's aiter shared-expert fusion, gated on _use_aiter (not the quant format). The model here, Qwen/Qwen3.8-2.4T-A95B-FP8, is FP8, not quark(mxfp4) at all; any checkpoint (bf16/FP8/quark) with SGLANG_USE_AITER=1 runs this part of code.

Quark-related handling is keyed on quant_config.get_name() == "quark" and reads the quark checkpoint layout — e.g.

  • gpt_oss.py:942 → quark/weights.py:load_gptoss_weight_quark (the existing "extract into ./quark" precedent),
  • deepseek_weight_loader.py:748 → quark/utils.py, plus qwen3_5_mtp.py:73,
  • glm4_moe.py:1467, deepseek_v2.py:3009, deepseek_nextn.py:262.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants