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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
base_model:
|
| 4 |
+
- zai-org/GLM-5.2
|
| 5 |
+
tags:
|
| 6 |
+
- glm
|
| 7 |
+
- moe
|
| 8 |
+
- mxfp4
|
| 9 |
+
- gptq
|
| 10 |
+
- quantization
|
| 11 |
+
- calibrated
|
| 12 |
+
- vllm
|
| 13 |
+
- dgx-spark
|
| 14 |
+
library_name: vllm
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# GLM-5.2 GPTQ-Calibrated MXFP4 Routed Experts
|
| 18 |
+
|
| 19 |
+
**Drop-in replacement expert weights** for [aidendle94/GLM-5.2-Hybrid-FP8-MXFP4](https://huggingface.co/aidendle94/GLM-5.2-Hybrid-FP8-MXFP4):
|
| 20 |
+
the same MXFP4 format, same size, same kernels β but every rounding decision chosen by
|
| 21 |
+
GPTQ against each expert's real routed activations instead of round-to-nearest.
|
| 22 |
+
|
| 23 |
+
**Result: full-model teacher-forced KL divergence vs BF16 drops 0.098 β 0.080 (β17.7%)**
|
| 24 |
+
at byte-identical memory footprint and serving speed.
|
| 25 |
+
|
| 26 |
+
| Metric (10-repeat gate, wikitext window) | RTN experts (v2) | **GPTQ experts** |
|
| 27 |
+
|---|---|---|
|
| 28 |
+
| Mean KLD vs BF16 | 0.0976 | **0.0803 (β17.7%)** |
|
| 29 |
+
| Median per-token KLD | 0.00123 | **0.00083 (β33%)** |
|
| 30 |
+
| Top-1 agreement with BF16 | 0.9325 | **0.9391** |
|
| 31 |
+
| Decode speed (4Γ DGX Spark, TP4+DCP4, MTP) | 24.4 tok/s | 24.4 tok/s |
|
| 32 |
+
| Reasoning-length inflation vs BF16 service | +63% | **+56%** |
|
| 33 |
+
| Per-expert output error (mean of 19,200) | 0.181 | **0.146 (β19.6%)** |
|
| 34 |
+
| Experts regressed vs RTN | β | **0 / 19,200** |
|
| 35 |
+
|
| 36 |
+
## What's in this repo
|
| 37 |
+
|
| 38 |
+
- `L{3..77}.safetensors` β 75 MoE layers Γ 256 routed experts each, HF per-expert layout:
|
| 39 |
+
`model.layers.{L}.mlp.experts.{E}.{gate,up,down}_proj.weight` (uint8 nibble-packed
|
| 40 |
+
MXFP4, low nibble first) + `.weight_scale` (uint8 e8m0, bias 127, block-32 along input dim).
|
| 41 |
+
Byte-compatible with the AMD-Quark MXFP4 layout the base hybrid uses.
|
| 42 |
+
- `L{3..77}_metrics.json` β per-expert held-out validation (RTN vs GPTQ relative output
|
| 43 |
+
error, token counts, mode).
|
| 44 |
+
- `run-logs/` β full quantization run logs.
|
| 45 |
+
|
| 46 |
+
These are **routed experts only** (layers 3β77). Attention, dense MLPs, shared experts,
|
| 47 |
+
router, MTP draft and tokenizer live in the base hybrid repo.
|
| 48 |
+
|
| 49 |
+
## Method
|
| 50 |
+
|
| 51 |
+
Per expert (256 per layer, 19,200 total):
|
| 52 |
+
|
| 53 |
+
1. **Calibration data**: 117 windows Γ 2048 tokens (code-heavy + prose) captured from a
|
| 54 |
+
serving GLM-5.2 hybrid with an MoE-forward hook recording each layer's true input
|
| 55 |
+
hidden states and top-8 routing β so every expert is calibrated on **the tokens it
|
| 56 |
+
actually serves** (~1Kβ20K tokens/expert, traffic-weighted by construction).
|
| 57 |
+
2. **GPTQ** with act-order and error feedback onto the MXFP4 grid; scales fixed
|
| 58 |
+
amax/e8m0 (AMD-compatible). `down_proj` is calibrated against the **quantized**
|
| 59 |
+
gate/up intermediate (within-expert error propagation).
|
| 60 |
+
3. **Heavy damping (`damp=1.0` of mean diagonal)** β the key hyperparameter finding:
|
| 61 |
+
per-expert Hessians are rank-deficient (tokens < 6144 dims; rank β token count), and
|
| 62 |
+
the textbook 1% damping makes GPTQ *worse* than RTN (β13%) by chasing null-space
|
| 63 |
+
compensation that MXFP4 clipping destroys. At damp=1.0 the sweet spot is wide (0.1β10).
|
| 64 |
+
4. **Validation**: 10% held-out routed tokens per expert; every expert β₯ RTN (worst
|
| 65 |
+
single expert: +0.7%).
|
| 66 |
+
|
| 67 |
+
Improvement is depth-graded β early layers gain most (up to β57.9% error at L6), which
|
| 68 |
+
compounds through the network β and traffic-graded (high-traffic experts β14.4% vs
|
| 69 |
+
β8.5% for rare ones, since hot experts get the most calibration tokens automatically).
|
| 70 |
+
|
| 71 |
+
Run on 4Γ rented H200s in ~3.5 h (~$100): layer-streamed BF16 fetches (19.3 GB in flight,
|
| 72 |
+
never the full model), one GPU per layer, 240K-token capture uploaded from the serving
|
| 73 |
+
cluster.
|
| 74 |
+
|
| 75 |
+
## Using these experts
|
| 76 |
+
|
| 77 |
+
With the base hybrid's sharded vLLM deployment, splice per-rank slices into the
|
| 78 |
+
`sharded_state` files (`w13_weight` = per-rank rows of [gate;up] packed, `w2_weight` =
|
| 79 |
+
per-rank input-column bytes of down β row/byte slicing never crosses the nibble packing;
|
| 80 |
+
see the surgery scripts referenced in the base repo). For HF-layout loaders, these tensors
|
| 81 |
+
directly replace the corresponding expert entries in the base repo's index.
|
| 82 |
+
|
| 83 |
+
## Per-layer results
|
| 84 |
+
|
| 85 |
+
<details><summary>75-layer table (mean over 256 experts each)</summary>
|
| 86 |
+
|
| 87 |
+
| Layer | RTN err | GPTQ err | Improvement |
|
| 88 |
+
|---|---|---|---|
|
| 89 |
+
| 3 | 0.1398 | 0.0595 | 57.9% |
|
| 90 |
+
| 4 | 0.1370 | 0.0733 | 47.1% |
|
| 91 |
+
| 5 | 0.1325 | 0.0726 | 45.9% |
|
| 92 |
+
| 6 | 0.1400 | 0.0835 | 41.0% |
|
| 93 |
+
| 7 | 0.1507 | 0.0967 | 36.3% |
|
| 94 |
+
| 8 | 0.1592 | 0.1037 | 35.0% |
|
| 95 |
+
| 9 | 0.1619 | 0.1103 | 31.8% |
|
| 96 |
+
| 10 | 0.1583 | 0.1104 | 30.6% |
|
| 97 |
+
| 11 | 0.1572 | 0.1103 | 30.2% |
|
| 98 |
+
| 12 | 0.1592 | 0.1126 | 29.6% |
|
| 99 |
+
| 13 | 0.1661 | 0.1216 | 26.9% |
|
| 100 |
+
| 14 | 0.1665 | 0.1246 | 25.3% |
|
| 101 |
+
| 15 | 0.1699 | 0.1316 | 22.7% |
|
| 102 |
+
| 16 | 0.1693 | 0.1316 | 22.4% |
|
| 103 |
+
| 17 | 0.1720 | 0.1331 | 22.8% |
|
| 104 |
+
| 18 | 0.1757 | 0.1394 | 20.7% |
|
| 105 |
+
| 19 | 0.1787 | 0.1433 | 19.8% |
|
| 106 |
+
| 20 | 0.1781 | 0.1424 | 20.2% |
|
| 107 |
+
| 21 | 0.1782 | 0.1415 | 20.7% |
|
| 108 |
+
| 22 | 0.1761 | 0.1391 | 21.2% |
|
| 109 |
+
| 23 | 0.1777 | 0.1342 | 24.5% |
|
| 110 |
+
| 24 | 0.1782 | 0.1378 | 22.7% |
|
| 111 |
+
| 25 | 0.1772 | 0.1405 | 20.7% |
|
| 112 |
+
| 26 | 0.1779 | 0.1427 | 19.8% |
|
| 113 |
+
| 27 | 0.1764 | 0.1439 | 18.5% |
|
| 114 |
+
| 28 | 0.1754 | 0.1450 | 17.4% |
|
| 115 |
+
| 29 | 0.1739 | 0.1452 | 16.6% |
|
| 116 |
+
| 30 | 0.1732 | 0.1462 | 15.8% |
|
| 117 |
+
| 31 | 0.1748 | 0.1480 | 15.4% |
|
| 118 |
+
| 32 | 0.1756 | 0.1498 | 14.8% |
|
| 119 |
+
| 33 | 0.1778 | 0.1520 | 14.6% |
|
| 120 |
+
| 34 | 0.1778 | 0.1537 | 13.6% |
|
| 121 |
+
| 35 | 0.1790 | 0.1564 | 12.7% |
|
| 122 |
+
| 36 | 0.1800 | 0.1575 | 12.6% |
|
| 123 |
+
| 37 | 0.1811 | 0.1599 | 11.8% |
|
| 124 |
+
| 38 | 0.1810 | 0.1604 | 11.5% |
|
| 125 |
+
| 39 | 0.1821 | 0.1614 | 11.5% |
|
| 126 |
+
| 40 | 0.1816 | 0.1590 | 12.5% |
|
| 127 |
+
| 41 | 0.1822 | 0.1590 | 12.8% |
|
| 128 |
+
| 42 | 0.1824 | 0.1607 | 12.0% |
|
| 129 |
+
| 43 | 0.1830 | 0.1608 | 12.2% |
|
| 130 |
+
| 44 | 0.1848 | 0.1636 | 11.6% |
|
| 131 |
+
| 45 | 0.1851 | 0.1643 | 11.3% |
|
| 132 |
+
| 46 | 0.1854 | 0.1643 | 11.5% |
|
| 133 |
+
| 47 | 0.1853 | 0.1633 | 12.0% |
|
| 134 |
+
| 48 | 0.1862 | 0.1632 | 12.4% |
|
| 135 |
+
| 49 | 0.1842 | 0.1594 | 13.6% |
|
| 136 |
+
| 50 | 0.1864 | 0.1607 | 13.9% |
|
| 137 |
+
| 51 | 0.1906 | 0.1647 | 13.7% |
|
| 138 |
+
| 52 | 0.1909 | 0.1641 | 14.1% |
|
| 139 |
+
| 53 | 0.1910 | 0.1640 | 14.2% |
|
| 140 |
+
| 54 | 0.1913 | 0.1624 | 15.2% |
|
| 141 |
+
| 55 | 0.1911 | 0.1605 | 16.1% |
|
| 142 |
+
| 56 | 0.1928 | 0.1624 | 15.8% |
|
| 143 |
+
| 57 | 0.1939 | 0.1647 | 15.1% |
|
| 144 |
+
| 58 | 0.1936 | 0.1641 | 15.3% |
|
| 145 |
+
| 59 | 0.1928 | 0.1639 | 15.0% |
|
| 146 |
+
| 60 | 0.1939 | 0.1641 | 15.4% |
|
| 147 |
+
| 61 | 0.1932 | 0.1622 | 16.1% |
|
| 148 |
+
| 62 | 0.1941 | 0.1642 | 15.4% |
|
| 149 |
+
| 63 | 0.1944 | 0.1657 | 14.8% |
|
| 150 |
+
| 64 | 0.1947 | 0.1660 | 14.8% |
|
| 151 |
+
| 65 | 0.1949 | 0.1664 | 14.6% |
|
| 152 |
+
| 66 | 0.1954 | 0.1667 | 14.7% |
|
| 153 |
+
| 67 | 0.1951 | 0.1669 | 14.5% |
|
| 154 |
+
| 68 | 0.1945 | 0.1652 | 15.1% |
|
| 155 |
+
| 69 | 0.1924 | 0.1614 | 16.2% |
|
| 156 |
+
| 70 | 0.1917 | 0.1609 | 16.1% |
|
| 157 |
+
| 71 | 0.1922 | 0.1608 | 16.4% |
|
| 158 |
+
| 72 | 0.1895 | 0.1546 | 18.5% |
|
| 159 |
+
| 73 | 0.1881 | 0.1519 | 19.3% |
|
| 160 |
+
| 74 | 0.1888 | 0.1505 | 20.4% |
|
| 161 |
+
| 75 | 0.1903 | 0.1492 | 21.6% |
|
| 162 |
+
| 76 | 0.1908 | 0.1472 | 22.9% |
|
| 163 |
+
| 77 | 0.1856 | 0.1318 | 29.2% |
|
| 164 |
+
|
| 165 |
+
</details>
|
| 166 |
+
|
| 167 |
+
## Provenance & credits
|
| 168 |
+
|
| 169 |
+
BF16 source weights: [zai-org/GLM-5.2](https://huggingface.co/zai-org/GLM-5.2) (MIT).
|
| 170 |
+
Baseline RTN MXFP4 experts: AMD (Quark) via
|
| 171 |
+
[festr2/GLM-5.2-BF16-AMDMXFP4experts](https://huggingface.co/festr2/GLM-5.2-BF16-AMDMXFP4experts).
|
| 172 |
+
Calibration capture, GPTQ run, validation and packaging by this repo's author, on
|
| 173 |
+
4Γ NVIDIA DGX Spark (GB10) + rented H200s. Credits to the b12x community
|
| 174 |
+
(Koush, David Young, Dooner, Festr, Luke and others).
|
| 175 |
+
|
| 176 |
+
MIT, as inherited from all sources.
|