tools: repair int4-converted MTP heads in place; warn on --mtp --ebits <8#397
Merged
Merged
Conversation
β¦rn on --mtp --ebits <8 Per-row int4 quantization of the MTP head's eh_proj [D,2D] zeroes its ENTIRE embedding half: the tensor's two column halves differ in scale by ~20-30x per row (embedding-half absmax ~0.05, hidden-half ~1.5 on GLM-5.2), so a single per-row scale (absmax/7) puts every embedding-half weight below half a quantization step and np.rint rounds it to exact zero (packed bytes 0x88). The draft head then cannot see the input token and MTP acceptance collapses to ~0% β the mechanism behind issue JustVugg#8's measurement (int4: 0-4%; int8: 39-59%), and the reason --mtp already defaults to --ebits 8. This showed up in the wild: a published pre-converted container had its MTP shards made with an explicit --ebits 4 and drafts were pure garbage on every backend (deterministic, data-side; verified byte-for-byte by reproducing the published bytes with quant_int4 on the official BF16 rows). - tools/repair_mtp_int8.py: repairs such a container IN PLACE β finds the MTP layer's per-row-int4 dense tensors (eh_proj, q/kv/o projections, shared experts; routed experts untouched), re-downloads only those from the FP8 source repo (~355 MB of HTTP range reads, no torch, no token), requantizes at int8 with quant_int8's exact math, and rewrites the shards atomically with *.bak-int4 backups. --dry-run to inspect. The engine picks up int8 automatically (qt_from_disk detects format by blob size). Validated on GLM-5.2 744B: MTP acceptance 0% -> 100% (greedy), 1.11 -> 3.20 tokens/forward, decode 0.18 -> 0.30 tok/s (Metal, 4-bit KV). - convert_fp8_to_int4.py: print a warning when --mtp is combined with --ebits <8 and per-row scales (the exact footgun above); --group-size 128 remains a valid int4 alternative since group scales give the embedding half its own scale. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 19, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
tools/repair_mtp_int8.pyβ an in-place repair for colibri containers whose MTP head was quantized at per-row int4 β and a warning inconvert_fp8_to_int4.pywhen--mtpis combined with--ebits <8per-row scales.The bug this repairs (found in a published container)
A pre-converted GLM-5.2 container on HF (jlnsrk/GLM-5.2-colibri-int4) shipped MTP shards made with an explicit
--ebits 4, overriding--mtp's int8 default. Result: MTP acceptance 0% on that container, on every backend, while the main model works perfectly.The mechanism is worse than ordinary quantization loss.
model.layers.78.eh_proj.weight[6144, 12288] multiplies the MTP concat[embedding_norm ; hidden_norm], and its column halves differ in scale ~20-30Γ per row (embedding-half absmax β 0.05, hidden-half β 1.4-1.6). Per-row int4 has one scale per row (absmax/7), so every embedding-half weight sits at 0.24-0.34 of a quantization step βnp.rintrounds the entire embedding half of all 6144 rows to exact zeros (packed bytes0x88). The draft head literally cannot see the input token; drafts are unrelated to context (true next token ranked ~#17,000 of 154,880 in draft logits).Verified byte-for-byte: running this repo's
quant_int4on the officialzai-org/GLM-5.2-FP8BF16 rows reproduces the published bytes exactly, scales included. This is also the mechanism behind issue #8's measurement (int4 MTP: 0-4% acceptance; int8: 39-59%) β the asymmetry explains why int4 doesn't just degrade the head but kills it.Full elimination trail before the data was implicated (engine exonerated): CPU and Metal builds identical garbage; unpatched upstream identical;
IDOT=0exact kernels,ABSORB=0,SPEC_PIN=0, expert pinning β all 0%; stage-by-stage NumPy replay ofmtp_draftmatched the C engine at every step (norms 1e-8, matmuls β€0.9%). The engine computes broken data faithfully.What the repair script does
eh_proj,q_a/q_b/kv_a/kv_b/o_proj, shared experts). Routed experts are left untouched.quant_int8's exact math.*.bak-int4; all untouched tensors stay byte-identical.qt_from_diskinfers format from blob size). Cost: ~+133 MB disk/resident.Validation (GLM-5.2 744B int4 container, macOS ARM, CPU + Metal)
eh_projembedding-half cosine vs official weights: 0.0000 β 0.97.A companion PR replacing the broken shards directly on the HF container: https://huggingface.co/jlnsrk/GLM-5.2-colibri-int4/discussions/3
Converter change
convert_fp8_to_int4.pynow prints a warning when--mtpis used with--ebits <8and per-row scales, pointing at the default (--ebits 8) or--group-size 128(group scales give the embedding half its own scale, making int4 viable).π€ Generated with Claude Code