Repository navigation
[AMD] Let the GLM DSA NextN draft declare its own shared-expert fusion architecture - #41258
Conversation
|
/tag-and-rerun-ci |
BBuf
left a comment
There was a problem hiding this comment.
Reviewed 290787a616. The architecture override fixes the intended gate, but the newly enabled fusion exposes an interaction with SGLANG_GLM_NEXTN_MOE_PTPC=1; details are inline. Local validation: 41 fusion-gate tests and 2 subtests passed; the remaining Pixtral test failed on an unrelated Transformers import in my local environment. The 15 related PTPC/scaling tests passed, but do not cover the fused shared slot.
Added run-ci and reran Base + AMD CI. The Base rerun is now blocked by the required-base check, not the missing label: the branch needs to include 8854857a991e06b3ef9c4caeae34c94fc3588336. Please rebase onto current main and push again; see CI maintenance #21065. The AMD label gate passed; GPU results are still pending.
| @@ -1459,6 +1459,9 @@ class GlmMoeDsaForCausalLM(DeepseekV2ForCausalLM): | |||
|
|
|||
|
|
|||
| class GlmMoeDsaForCausalLMNextN(DeepseekV3ForCausalLMNextN): | |||
| # ModelConfig rewrites a GLM draft's architecture to this class's own name, | |||
| # so the inherited DeepSeek name would never match what the gate compares. | |||
| fused_shared_experts_architecture = "GlmMoeDsaForCausalLMNextN" | |||
There was a problem hiding this comment.
Could we handle SGLANG_GLM_NEXTN_MOE_PTPC=1 before enabling fusion for this draft? For a Quark checkpoint whose MTP routed/shared experts are excluded (BF16), the inherited gate now permits fusion, and _resolve_nextn_quant_config selects PTPC-FP8 for model.decoder.mlp.experts. However, _maybe_quant_glm_nextn_moe_to_ptpc only matches mlp.experts.<id>.*: mlp.shared_experts.* passes through as BF16 without weight scales. The inherited loader subsequently renames it to expert 256 and copies it into FP8 storage, leaving that slot's scales at their initial value of 1.
I reproduced this on CPU using the actual Quark gate, GLM weight iterator, Quark FP8 weight allocation and _load_w13 helper, with the device capability mocked to gfx95: the old architecture returns "Config does not support...", the new one returns None; the routed weight gets FP8 + a scale, while the shared weight stays BF16 with no scale. Shared weights of 1e-4 then become zero when loaded into the fused slot.
Please either keep fusion disabled for this PTPC path or apply the same per-channel conversion and scale emission to the shared expert, with a regression covering both the routed and shared checkpoint names.
There was a problem hiding this comment.
Handled in ba7f238ffb. I took the conservative option: when PTPC applies to the NextN routed experts and shared_experts is excluded (BF16), the fusion gate now returns a PTPC-specific disable reason. Routed PTPC conversion remains unchanged and the shared weight stays in its separate BF16 module. Added coverage for the gate plus both routed and shared checkpoint names.
290787a to
ba7f238
Compare
|
@BBuf thanks for finding this. Rebased onto current |
8f84c90 to
f324118
Compare
|
@BBuf could you please re-review the current head |
|
@BBuf gentle ping for re-review of |
BBuf
left a comment
There was a problem hiding this comment.
The PTPC guard addresses my earlier comment: the shared expert stays out of the fused FP8 slot on that path. The PTPC regression tests pass locally.
|
@BBuf thank you for the approval. Could you merge this when you have a moment? The remaining red checks are unrelated: the Base jobs stopped at a GitHub API |
…fusion Two upstream fixes that our decode path provably hits: 1. sgl-project#35872 (790551c) - skip the full-vocab softmax in the EAGLE topk==1 draft on ROCm. Live decode runs speculative_algorithm=EAGLE with eagle_topk=1 and steps=2 on EAGLEWorkerV2, so every draft step went through renorm_draft_probs + fast_topk over the whole vocabulary. The decode profile measures that softmax at 3.4% and the argmax reduce at 2.9% of decode kernel time. ROCm previously fell through to the generic topk path because of sgl-project#26358 (torch.argmax tie-break on FP8 logits). This uses the triton draft_topk1_postprocess kernel instead of torch.argmax, so the tie-break concern does not apply. A scratch positions buffer absorbs the position advance that draft-extend has already consumed. 2. sgl-project#41258 (db32673) - let the GLM DSA NextN draft declare its own shared-expert fusion architecture. ModelConfig rewrites a GLM draft's architecture to GlmMoeDsaForCausalLMNextN, so the inherited DeepSeek name never matched the gate and the draft's shared expert was never fused into fMoE, costing an extra GEMM per draft step. Measured at 1.1% of decode kernel time (_fused_append_shared_experts_kernel). Only the architecture declaration is ported. The upstream commit's second hunk depends on should_apply_glm_nextn_moe_ptpc, which this tree does not have. Deliberately not included: sgl-project#42982 (FP8 KV saturation). It has no throughput benefit, it changes the values written into the KV cache, and therefore forces the whole rollout into the "changes KV encoding" risk class. It should ship on its own with its own correctness run. Assisted-by: Hy4 preview via CodeBuddy Code
Motivation
ModelConfigrewrites a GLM-5 draft's architecture toGlmMoeDsaForCausalLMNextN. The fusion gate compares that name withfused_shared_experts_architecture, which the class inherited as"DeepseekV3ForCausalLMNextN", so the draft was rejected even though it has the same 256 routed + 1 shared expert layout as the target model.Modifications
Declare
fused_shared_experts_architecture = "GlmMoeDsaForCausalLMNextN"on the draft class.Keep fusion disabled whenever
SGLANG_GLM_NEXTN_MOE_PTPC=1casts the routed experts to per-channel FP8: the cast skips the shared expert, so its weight (BF16 or quantized) would land in the FP8 slot without a matching scale. On GLM-5.2-MXFP4's real layer-78 shared expert that zeroes 7-8% of the weights. GLM-5.3 checkpoints do not exclude MTP routed experts, so PTPC never applies there and the draft fuses.Tests cover the architecture name, the loader-style gate call, the PTPC guard with the shared expert excluded or quantized, and both routed/shared checkpoint names.
Accuracy Tests
Initial GLM-5.3 MXFP4 validation of the architecture override loaded the draft weights and measured MTP accept length 3.56 versus 3.58 on base, with GSM8K unchanged. The final PTPC guard intentionally leaves the unsupported BF16-shared configuration unfused; a real checkpoint load was not rerun after adding that guard.
Local verification:
Result: 58 tests passed. Two broader-suite failures reproduce on current
main: the ROCm EP gate expectation and a local Transformers/Pixtral import mismatch.Speed Tests and Profiling
Not isolated. Supported drafts now use the same fused shared-expert path as the target model; the PTPC + BF16-shared case remains unfused for correctness.
Checklist
CI States
Latest PR Test (Base): ❌ Run #37629578284
Latest PR Test (Extra): ❌ Run #37629578084
Latest PR Test (AMD ROCm 10): ❌ Run #37629578206