Repository navigation
[Fix] GLM-4.7-Flash: Load compressed-tensors W4A16 checkpoints - #49531
Conversation
|
Tested on 1x H20-3e (SM90), both gaps from the description. Setup: "main" is the PR's base
So the FP8 case from the issue is fixed by the A few comments from reading the diff:
|
|
@HollowMan6 thank you for running both, and for the review. The FP8 numbers are the evidence this PR was missing. Addressed in 930d78d:
Both changes come with regression cases that fail on 0a7a7e4 and pass now. Your H20 table is in the description, credited to you. |
BBuf
left a comment
There was a problem hiding this comment.
[BBuf Review Agent] A few things to fix before this can go in.
|
[BBuf Review Agent] @koladefaj At 930d78d the fusion check still probes only gate_proj, so ignoring just model.layers.1.mlp.shared_experts.down_proj still allows fusion and the BF16 weight gets skipped during loading. Could we check every shared projection against its routed counterpart before allowing fusion? |
…online updates can_fuse_shared_expert compared only gate_proj, so a checkpoint that ignored just shared_experts.down_proj (or up_proj) still fused, and the BF16 down weight was skipped during loading. Compare gate_proj, up_proj and down_proj of the shared expert with the same projection of the routed experts, and refuse fusion on a mismatch in either direction. A loaded compressed-tensors WNA16 kv_b_proj is repacked for the kernel and cannot be dequantized again, so an online weight update wrote the new weights and then failed in post_load_weights. Mark the layer with _derived_weight_cache_error so updates are refused before they write.
|
Thanks @BBuf, both fixed in f542238.
69 tests pass locally across the three test files. |
|
[BBuf Review Agent] @koladefaj Checked f542238: the fusion guard now compares each shared projection with its routed counterpart, covering the down_proj case I raised. The WNA16 cache marker is also checked before online updates mutate weights, including begin_weight_update. |
|
/tag-and-rerun-ci |
BBuf
left a comment
There was a problem hiding this comment.
[BBuf Review Agent] LGTM. Both earlier issues are addressed.
…ling3-vl-fp4 703e763 is the sglang commit in intel/sglang-dev 01ddedc3414a, on which the branch was re-validated. Conflicts: - models/glm4_moe_lite.py: take main. sgl-project#49531 added the same packed_modules_mapping, and fuse_qkv_a_proj_tensors already concatenates packed GPTQ/AWQ/AutoRound tensors on the output dim. - model_runner_components/moe_ep_setup.py: keep both skips, main's quant_method != "fp8" (Fp8MoEMethod decides at weight creation) and this branch's is_fp4_experts.
…zation ignore lists (partial cherry-pick #49531) (#54134) Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Motivation
Fixes #49369, reported by @HollowMan6.
cyankiwi/GLM-4.7-Flash-AWQ-4bit(compressed-tensorspack-quantized, int4 symmetric, group 32) does not load. It quantizesq_a_proj,kv_a_proj_with_mqaandkv_b_projfrom layer 1 on, and keeps layer 0 and the shared experts in BF16 through itsignorelist. On a realsglang serve, it fails in five places, one after the other. Each one only shows up once the one before it is fixed:weight_shape.load_weightsfusesq_a_projandkv_a_proj_with_mqaby concatenating every tensor of the pair on dim 0. Forweight_shape([out, in]), that gives[q_out, in, kv_out, in]instead of[q_out + kv_out, in], and the load asserts.DeepseekV2WeightLoaderMixinhas the same concatenation.kv_b_projinpost_load_weights. The MLA post-load step readskv_b_proj.weight, which a packed layer does not have. This is the issue'sAttributeError.packed_modules_mapping.Glm4MoeLiteForCausalLMdeclares none, soignoreentries that name shards (q_a_proj,gate_proj, ...) never match the fusedfused_qkv_a_proj_with_mqaandgate_up_proj. Layer 0 and the shared experts'gate_up_projget built W4A16 over BF16 weights. With FP8 this fails silently: @HollowMan6 measured 3.4e38 outputs onunsloth/GLM-4.7-Flash-FP8-Dynamic, where 13.0 is expected.FusedMoE, but this checkpoint keeps the shared experts in BF16 beside W4A16 routed experts.fused_a_gemm_weight_eligiblereadslayer.weighton the packedfused_qkv_a_proj_with_mqaduring the first forward (CUDA graph capture).Modifications
models/deepseek_common/utils.py: a newfuse_qkv_a_proj_tensors, used by both the GLM and DeepSeek loaders.weight_shapeadds the output rows.weight_g_idxis kept, and differing ones are rejected.qweight,qzeros,scalesunderawq,awq_marlin,moe_wna16,gptq,gptq_marlinorauto-round) stack on dim 1. A projection that such a checkpoint leaves unconverted keeps a plain[out, in]weight.QuantTrio/GLM-4.7-Flash-AWQkeepsself_attnin BF16, so choosing the dim from the config alone would break it. GGUF also names a tensorqweight, but it is row-major and stays on dim 0.g_idxfollows the same rule asweight_g_idx.compressed_tensors_wNa16.py:CompressedTensorsWNA16.dequantize_weightunpacks the checkpoint layout to a dense weight in the scale dtype.post_load_weights. Reading those tensors would build garbagew_kc/w_vc.deepseek_weight_loader.py:post_load_weightsdequantizes a compressed-tensors WNA16kv_b_projbefore thew_kc/w_vcsplit, next to the AWQ branch. It also sets_derived_weight_cache_erroron that layer: once repacked it cannot be dequantized again, so online weight updates are refused before they write any weight.glm4_moe_lite.py:packed_modules_mappingmapsfused_qkv_a_proj_with_mqaandgate_up_projto their shards.quant_blocks_shared_experts_fusion, as DeepSeek-V2 already does.compressed_tensors.py:CompressedTensorsConfig.can_fuse_shared_expertis false whenignoregives any shared-expert projection (gate_proj,up_proj,down_proj) of a layer a different precision from the same routed-expert projection, in either direction. Each projection is resolved per MoE layer withshould_ignore_layer, so names and regexes match alike. Ashared_expert_gateentry does not count. It probes the layers the ignore list names; a regex, or a bare suffix that could match an expert, addsmodel.layers.0-255. That takes 1.3 ms on the FP8 checkpoint's 601-entry list.fused_a_gemm.py: a layer without a denseweightis not eligible.Behavior change outside GLM:
can_fuse_shared_expertis also read by DeepSeek-V2/V4, MiniMax-M3 and Qwen2-MoE / Qwen3.5. For a compressed-tensors checkpoint whoseignorekeeps any shared-expert projection at a different precision from the matching routed-expert projection, these now skip shared-expert fusion. Fusing such a checkpoint would load BF16 weights into the quantized expert buffers, or quantized weights into BF16 ones. A checkpoint that ignores the same projections on both sides keeps fusion.Accuracy Tests
1x NVIDIA A40 (SM86) for the
cyankiwirow and 1x NVIDIA RTX A6000 (SM86) for theQuantTriorow, imagelmsysorg/sglang:nightly-dev-cu13-20261110-4a5c6b8f. Every file this PR touches is identical between the image's tree and this PR's base533c067689. "main" is that tree unchanged, and "branch" is this PR applied to it. The launch command follows the cookbook (--tp 1 --reasoning-parser glm45):cyankiwi/GLM-4.7-Flash-AWQ-4bit(this issue)QuantTrio/GLM-4.7-Flash-AWQ(regression check)All runs use the command above: greedy (temperature 0, top_p 0.95), thinking off. Every server that loads answers
17*23with391.SM90 run by @HollowMan6 (1x H20-3e, the same commands; comment):
unsloth/GLM-4.7-Flash-FP8-Dynamic17*23answers!!!!!!!!…)cyankiwi/GLM-4.7-Flash-AWQ-4bitThis covers the FP8 case that SM86 cannot run, and the fused-A GEMM path, which is eligible on SM90.
sgl-evalcommand and 200 examples. It's a sanity reference, not a like-for-like comparison. An earlier A6000 run of thecyankiwicheckpoint on this branch is consistent: 0.874 thinking-off and 0.969 thinking-on, both partial runs without a token cap.awq_marlinkernel and the same CUDA graphs. Answers flip both ways (10 questions right only on main, 6 only on the branch), and 51/200 greedy generations match word for word. That looks like batching nondeterminism, though I did not run main twice to confirm.unsloth/GLM-4.7-Flash-FP8-Dynamic) cannot run on SM86 on either tree (bmm_fp8 does not support backend 'cublas' with capability 86); see the SM90 table above.Before: main,
cyankiwi/GLM-4.7-Flash-AWQ-4bit(the same assert on A6000 and A40)With fixes 1–4 applied but not 5, loading completes and the first forward fails:
After: this branch,
cyankiwi/GLM-4.7-Flash-AWQ-4bit(A40)The 778 s prefill capture was the first serve on a fresh pod. The same code captured in 26 s on the A6000 pod after an earlier serve there, so this is most likely cold kernel caches; the log does not show the cause.
Unit tests
New CPU file
test/registered/unit/models/test_mla_compressed_tensors_wna16_loading.py(base-a-test-cpu), plus a GLM case intest_shared_experts_fusion_gates.py. I checked each regression case: it fails with its fix reverted and passes with it. The cases:weight_shape/weight_packed/weight_scale.qweighton dim 1 and keeps unconverted BF16 attention on dim 0.dequantize_weightmatches compressed-tensors' ownpack_to_int32exactly (4-bit group, 4-bit channel, 8-bit).process_weights_after_loadingmarks the layer, and dequantizing it afterwards raises.post_load_weightsbuildsw_kc/w_vcfrom a packedkv_b_proj, and online weight updates are then refused.can_fuse_shared_expertcovers the checkpoint's own ignore list, gate-only, a single sharedup_proj/down_proj, routed-only, the same projection on both sides, both-ignored, regex (includingre:.*mlp\.shared.*and a layer-anchored regex) and bare-suffix cases.qweightstacks on dim 1, GGUF's stays on dim 0, and GPTQg_idxfollows the act-order rule.fused_a_gemm_weight_eligibleis false on a packed layer.f542238 leaves the fusion decision of both real checkpoints unchanged (
cyankiwi: off,unslothFP8: on), so the accuracy runs above still apply.Merge Danger
Door: two-way. Code-only, no format, config or API changes; a revert restores the old behavior.
Blast radius: MLA checkpoint loading.
weight_shape,weight_g_idxand the AWQqweight/qzeros/scaleschoice of dimension behave differently; every other tensor concatenates exactly as before. The unconverted-attention AWQ case is covered by theQuantTriorow above.ignorekeeps any shared-expert projection at a different precision from its routed counterpart (see "Behavior change outside GLM"). That costs throughput where fusion used to run, but such checkpoints loaded weights into buffers of the wrong precision.kv_b_projreloaded through the sharded-state or remote-instance loaders now raisesNotImplementedErrorinstead of computing silently wrongw_kc/w_vc.post_load_weightsafter the new weights were written.Speed Tests and Profiling
No kernel changes. The fused-A GEMM change only makes packed layers take their regular path (before, they crashed). On this checkpoint, disabling shared-expert fusion is required for correctness.
Checklist
CI States
Latest PR Test (Base): ✅ Run #42961238841
Latest PR Test (Extra): ❌ Run #42961237769
Latest PR Test (AMD ROCm 10): ⏳ Run #42961238099
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: