Repository navigation
[AMD] Critical fix enabling Qwen3.8 FP8: restore dropped fused shared-expert weights - #40754
Conversation
… 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.
| # 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(): |
There was a problem hiding this comment.
why _use_aiter not _is_hip, because downstream handling needs to use aiter kernel/imports?
There was a problem hiding this comment.
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.
|
Move quark related model file / checkpoint specific handling to |
@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.
|
Motivation
Text-only Qwen3.5-MoE checkpoints (architecture
Qwen3_5MoeForCausalLM, e.g.Qwen3.8-2.4T-A95B-FP8) load intoQwen3_5MoeForCausalLM, whoseload_weightswas missing the shared-expert fusion remapping that the multimodalQwen3_5MoeForConditionalGeneration.load_weightsalready implements. On ROCm with aiter shared-expert fusion enabled (SGLANG_USE_AITER=1),Qwen2MoeSparseMoeBlockserves the shared expert as an extra fused MoE slot at indexnum_experts, butQwen3_5MoeForCausalLM.load_weightskeptnum_expertsunchanged and never remappedmlp.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, classQwen3_5MoeForCausalLM:__init__: computenum_fused_shared_experts/enable_shared_expert_fusionwhen aiter fusion is active, via a new_get_num_fused_shared_experts()that scans local MoE layers (PP-safe: non-local slots arePPMissingLayerwith no.mlp).load_weights: growmake_expert_params_mapping(num_experts=...)by the fused shared count when fusion is on; extendfused_expert_params_mappingwith the shared-slot entries; remapmlp.shared_expert.* -> mlp.experts.{num_experts}.*; load the fused shared slot intoexperts.w13_weight/experts.w2_weight.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:mlp.shared_expert.* not found in params_dictwarnings (per rank set)Full gsm8k sweep (sglang few-shot, 1314 questions):
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
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ciCI States
Latest PR Test (Base): ❌ Run #35739427018
Latest PR Test (Extra): ❌ Run #35739457890
Latest PR Test (AMD ROCm 10): ❌ Run #35739427563