We study how the placement of quantization levels affects 2–4-bit weight-only quantization of large language models. At equal bit width, a grid fitted to the weight distribution and to channel saliency lowers perplexity more than the choice between uniform and fixed non-uniform alphabets. For each weight tensor we fit a 2b-level lookup table with a four-parameter Kumaraswamy quantile function (one pair per half-distribution), optimized by compass search on a Hessian-diagonal-weighted squared error. The table costs 32 fp16 bytes per tensor, fitting takes under a second on CPU, and the decoder is unchanged. The procedure is deterministic: with the histogram objective the grid is an exact function of the tensor, with no random subsampling, training, or gradient computation. It changes the alphabet rather than the rounding rule, so it composes with GPTQ, rotation-based preconditioning, sparse corrections, and mixed-precision allocation. On SmolLM-135M and Qwen2.5-0.5B (WikiText-2, activation-based calibration, float64 GPTQ) the fitted grid lowers perplexity at equal width: 7–15 % over uniform at 4 bits (Qwen: 22.65 → 19.23) and up to three orders of magnitude at 3 bits (Qwen: 55.703 → 68.5; SmolLM: 1.580 → 52.6). Equal-mass grids are 31–331 % worse than uniform, consistent with the Zador–Gersho p1/3 level-density law. Fixed NF4 and FP4 E2M1 grids lose to fitted ones. The method rests on classical Lloyd–Max quantization theory; the contribution is a cheap parametric fit. Results cover two small models and one corpus; larger models, broader benchmarks, and kernel optimization remain open.
Keywords: weight quantization, large language models, GPTQ, non-uniform grids, Kumaraswamy distribution, Lloyd–Max algorithm, deterministic quantization, perplexity.
Weight quantization of large language models (LLMs) has become the primary way to reduce inference memory requirements: weights occupy a volume proportional to the number of parameters and do not depend on the context length. The working standard is the weight-only mode: weights are represented by low-bit-width integer codes (3–4 bits) with a scale per group of 64–128 weights, while activations stay in fp16. In this mode, quality is determined by which values the weights are encoded with, and hardly depends on these codes being "integers".
Traditionally, the value grid is chosen uniform-representative: after subtracting the zero point, weights are normalized by the group maximum and rounded onto a uniform lattice (the NF4 variant from QLoRA [3] takes a fixed Gaussian grid). Meanwhile, the transformer weight distribution is sharply peaked, with heavy tails and strong channel anisotropy; a mere exponent shift of the group scale does not cope with this. In this paper we test the hypothesis that the grid shape — the placement of levels relative to the weight density — is an independent quality lever, comparable in effect to the rounding algorithm.
We call the method SHAPEQ (shape-adaptive quantization). For each weight tensor we fit a table of 2b levels (for 4 bits — 16 numbers stored as 32 fp16 bytes per tensor), generated by the quantile function of the Kumaraswamy distribution [10] with four parameters (one (a, b) pair for the positive and negative halves). The parameters are fitted by compass search on a weighted objective in which each weight's error contribution is weighted by the Hessian diagonal of the loss — that is, what is optimized is not the "average distance to a weight", but a proxy for the model's actual degradation. Rounding is performed by GPTQ [1] with the unchanged uniform code: grid shape and smart rounding add up.
The approach is conservative by design. It relies on scalar quantization theory that has been established for decades [8, 9, 16] and adds only a parametric description of the level density. No model training, no gradient computation, and no search over the full tensor are involved: the fit is a coordinate descent over four numbers on a one-dimensional objective. With the histogram implementation (Section 7.7) the grid is an exact function of the tensor, so the same checkpoint always produces the same table. Because the method changes only the alphabet, it is orthogonal to the rest of the quantization pipeline: GPTQ and AWQ rounding, rotation-based preconditioning, sparse corrections, and mixed-precision bit allocation can all use the fitted grid unchanged. We test the combination with GPTQ here; the other combinations are discussed in Section 7.4.
Contributions of this work:
Optimal grids. The problem of choosing levels that minimize the mean squared deviation for a given density is classical: Lloyd's necessary conditions (1957 [8]) and Max's independent solution (1960 [9]) yield an iterative "centroids–nearest regions" algorithm — what is known in machine learning as Lloyd–Max / k-means for 1D; for a large number of levels, the optimal level placement becomes asymptotically quantile. NF4 from QLoRA [3] uses this idea in "frozen" form — quantiles of the normal density without fitting to the data. We use a parametric family instead of Lloyd iterations, because (a) our objective is Hessian-weighted and includes the GPTQ stage, for which there are no reference "centroids", and (b) a cheap online procedure per tensor is required.
Rounding algorithms. OBS/GPTQ [1] minimize the quadratic form tr(ΔW H ΔWᵀ) with the Hessian from calibration activations; AWQ [2] protects "important" channels by scaling; sparse hybrids (SpQR [6], SqueezeLLM [4]) move outliers into sparse corrections — effectively adding more bits to the model, but locally. Our method is orthogonal to this entire list: it changes the alphabet, not the rounding order, and in this paper it is combined only with GPTQ.
Fixed microformats. The OCP Microscaling family (MXFP8/MXFP4, [14]) standardizes block formats with e4m3/e8m0 scales and a fixed E2M1 grid for 4 bits; GGUF/IQ4_NL in llama.cpp [15] is the de facto standard of a "fixed non-uniform" grid in production CPU inference. These formats choose the grid once for "average weights"; we show that per-tensor fitting is cheap and consistently outperforms them at equal storage cost.
Let W ∈ ℝm×n be the weight tensor of a linear layer, X — the calibration activations (T × n), H = XᵀX/T — their Gram (approximate Hessian) matrix. Second-order loss degradation of a layer is estimated as tr(ΔW H ΔWᵀ) [1]; we use its diagonally corrected version at the grid-fitting stage (weights wi = diag(H), with smoothing and a correction for GPTQ error propagation), and the full quadratic form — at the rounding stage.
minG, idx Σi,j diag(H)j · (Wij − s · Gidx(i,j))²,
where G is a table of L = 2b levels (shared across the tensor), s is the group scale (fp16 per 128/96 weights), idx are integer codes. Storage: b bit/weight + 16 bits per group + 32 bytes of LUT per tensor (16×fp16) — on an 896×4864 tensor this is 0.0006 bit/weight, i.e. free for any b ≤ 8.
As the quantile function (mapping the uniform grid uk = (k+0.5)/L to the "magnitudes" of the levels) we adopt the Kumaraswamy inverse distribution function [10]:
Q(u; a, b) = ( 1 − (1 − u)1/b )1/a,
which for a = b = 1 yields a uniform grid, for a, b > 1 an S-shaped one (densification toward the modal zones and rarefaction in the tails), for a, b < 1 a reverse-S one (densification toward both poles). With one pair (a, b) per half of the distribution, the shape is described by four numbers; this family covers all bend types observed in the weight histograms of 21 SmolLM layers (Section 6.4). The negative and positive halves are built independently and joined at zero; the zero level is always present in the table.
Input: W (m×n), h = diag(H) with smoothing h ← (h + ε·mean h)/(1+ε),
L, group g.
1 For each group, weights are normalized by absmax → y ∈ [−1, 1];
magnitudes |y| with weights w = repeated h form the sample (≤150 000 points).
2 θ = (a₋, b₋, a₊, b₊) ← (1, 1, 1, 1) // uniform as the starting point
step d ← 0.5
while d > 0.02:
for each of the 8 compass directions:
θ' ← θ ± d·eᵢ (probes ≥ 0.05 only)
θ ← argmin C(θ'), where C is the objective of Alg. 2 with L levels
d ← d/2
3 κ ← scale search (Alg. 2, item 4): shift the whole table by a factor κ
on a 0.90…1.10 grid, minimizing the same objective // "tail" trade-off
4 G ← shapeq_grid(L, θ) · κ, normalize by the absmax of the table.
The objective is the normalized weighted MSE Σ w·(y − G[idx(y)])² / Σ w·y², computed over 150 thousand subsample points in ~1 ms; a full compass descent (≈60 objective evaluations per side) costs < 1 s per tensor. Weighting by diag(H) is what makes the method "Hessian-aware": channels with large activations get denser levels. The ε smoothing guards against zero weights; without it the fitting degenerates.
Input: W, h, G (after Alg. 1), number of rounds R (we use R = 3).
repeat R times:
1 idx ← nearest level (in the group scale);
2 for each level k: Gₖ ← Σ w·y / Σ w over all points of bucket k
(weighted centroid; empty buckets are not moved);
3 renormalize G by absmax;
return the best G under the objective C.
This is the classic Lloyd step with Hessian weights: it does not change the shape family; it "polishes" the levels to optimal for the real data shape and the real bucket partition. The refit is cheap (one pass over the tensor per round) and was used in our experiments as a booster for the winner (the "+refit3" configurations).
We use the reference GPTQ implementation [1] with the diagonal correction: cholesky of H⁻¹, sequential column-by-column rounding with error propagation to unprocessed columns. The only change relative to the canon is that the level weighting grid is not uniform but G from Algorithm 1 (for fixed grids — NF4/FP4 — its own table with no fitting). Numerical operations run in float64 on CPU; this matters: f32 GPTQ variants on GPU give a discrepancy of order 10⁻² from f64 at rare level boundaries (Section 5.4).
A weight tensor after quantization: codes (b bit/weight) + group scales (fp16 per 128 Qwen / 96 SmolLM weights = 0.125–0.167 bit/weight) + a 16×fp16 LUT = 32 bytes per tensor + 4 bytes of group zero point (absorbed into the scale). The final cost for our runs is the "bit/weight" column of Tables 1–2: 3.25 and 4.25 bits. Decoding at inference is a table lookup (as IQ4_NL in llama.cpp [15]), latency O(1); matrix multiplication remains weight-only (activations fp16), so 4-bit hardware FP4 matrices [14] do not compete with our method but complement it (Section 7.4).
SmolLM-135M [13] (30 layers, hidden 576, llama-type architecture) and Qwen2.5-0.5B [12] (24 layers, hidden 896, GQA with 2 kv heads). Calibration: 2048 (SmolLM) / 1024 (Qwen) sequences of 512 tokens from WikiText-2 [11]; evaluation — the same chunks (96 / 64 sequences with a sliding window, without overlap), perplexity over all tokens. Groups: 96 and 128 weights. All linear layers (q/k/v/o, gate/up/down) are quantized simultaneously, embeddings and layernorms remain fp16/fp32 — the standard weight-only scheme.
First the cheap proxy — relative layer error tr(ΔW H ΔWᵀ)/tr(W H Wᵀ) over 21 sampled layers (runtime < 1 min per configuration), then full perplexity (10–90 min per configuration). The proxy was used to cull shapes that were clearly doomed (Section 6.5); final conclusions rest on ppl only.
All configurations in one comparison row use the same Hessian (shared calibration), the same GPTQ code, and the same evaluation chunks. A known simplification: the Hessian is computed once for the fp16 model and is not rebuilt after quantization ("stale Hessian" — standard GPTQ practice [1]); for severely degraded configurations (b2/b3 uniform) this may underestimate the real damage — in our favor, and we note it. The GPU branch of the ppl evaluation (NVIDIA MX250 under WSL2) gives ppl matching CPU with an accuracy of 10⁻³ (17.067 vs 17.066); the discrepancy of the f32-GPTQ quantization itself — see 5.4.
Grid fitting, refit, and GPTQ are carried out by a reference numpy implementation (float64). The pipeline's GPU shadow was verified by a separate gate: the discrepancy of weighted layer errors between CPU and GPU quantization ≤ 0.03 %, the ppl discrepancy — 0.006 %; on this basis part of the rows (fp8, the Qwen b4 family) were computed by the shadow front and marked in the tables as "gpu". The full set of artifacts (CSV, JSON, codes) is attached (Section A).
| Configuration | bit/weight | WikiText-2 ppl | vs fp32 | within its bit-width | quant., s |
|---|---|---|---|---|---|
| fp32 | 32.0 | 23.358 | — | — | 0 |
| b8 shapeq | 8.333 | 23.355 | ±0.0 % | best | 871 |
| b8 shapeq+refit3 | 8.333 | 23.362 | +0.0 % | +0.0 % | 4 557 |
| b6 shapeq | 6.333 | 23.463 | +0.4 % | best | 405 |
| b6 shapeq+refit3 | 6.333 | 23.531 | +0.7 % | +0.3 % | 3 333 |
| b4 uniform | 4.333 | 33.806 | +44.7 % | +30.4 % | 175 |
| b4 shapeq | 4.333 | 31.385 | +34.4 % | +21.1 % | 698 |
| b4 shapeq+refit3 | 4.333 | 25.924 | +11.0 % | best | 1 846 |
| b4 fp4 | 4.333 | 27.067 | +15.9 % | +4.4 % | 173 |
| b4 eqmassk | 4.333 | 44.295 | +89.6 % | +70.9 % | 173 |
| b4 eqmass | 4.333 | 186.694 | ×8.0 | +620.2 % | 169 |
| b3 uniform | 3.333 | 1 580.159 | ×67.6 | +3928.9 % | 278 |
| b3 uniform_k | 3.333 | 29 068.159 | ×1244.5 | +74013.8 % | 265 |
| b3 shapeq | 3.333 | 52.563 | ×2.3 | +34.0 % | 938 |
| b3 shapeq+refit3 | 3.333 | 39.221 | +67.9 % | best | 1 799 |
| b3 eqmass | 3.333 | 2 829.929 | ×121.2 | +7115.3 % | 153 |
| rco 3.5 form | 3.833 | 31.372 | +34.3 % | — | 1 031 |
| b2 uniform_k | 2.333 | 45 302 916.186 | ×1939503.2 | +1160898.8 % | 305 |
| b2 shapeq | 2.333 | 306 235.929 | ×13110.5 | +7748.0 % | 1 051 |
| b2 shapeq+refit3 | 2.333 | 3 902.064 | ×167.1 | best | 930 |
| b2 eqmass | 2.333 | 1 308 910.264 | ×56036.9 | +33444.0 % | 132 |
Table 1. SmolLM-135M, group 96, WikiText-2 ppl (96 evaluation chunks). "bit/weight" is the full storage cost. The 8/6-bit and fp4 rows are a continuation of the run.
At 4 bits the gap between forms is still modest (33.8 vs 31.4, the fitted grid's gain ≈ 7 % in ppl loss against fp32), but it explodes as bit-width drops: at 3 bits the uniform grid yields ppl 1 580 (68 times worse than the base), whereas the fitted one — 52.6 (only ×2.3). The gap is ×30. At 2 bits uniform ceases to be a language model at all (ppl ~1010), while shapeq, though it degrades, preserves the structure.
| Configuration | bit/weight | WikiText-2 ppl | vs fp16 | within its bit-width | quant., s |
|---|---|---|---|---|---|
| fp16 | 32.0 | 17.066 | — | — | 0 |
| fp8 e4m3 | 8.125 | 17.230 | +1.0 % | — | 1 |
| b4 uniform | 4.25 | 22.649 | +32.7 % | +19.2 % | 704 |
| b4 fp4 | 4.25 | 20.211 | +18.4 % | +6.3 % | 952 |
| b4 shapeq | 4.25 | 19.225 | +12.7 % | +1.2 % | 1 152 |
| b4 shapeq+refit3 | 4.25 | 19.005 | +11.4 % | best | 4 786 |
| b4 eqmassk | 4.25 | 43.960 | ×2.6 | +131.3 % | 662 |
| b4 eqmass | 4.25 | 412.556 | ×24.2 | +2070.8 % | 688 |
| b3 uniform | 3.25 | 55 703.448 | ×3264.0 | +166482.3 % | 498 |
| b3 uniform_k | 3.25 | 19 285.489 | ×1130.1 | +57573.6 % | 544 |
| b3 shapeq | 3.25 | 68.517 | ×4.0 | +104.9 % | 1 098 |
| b3 shapeq+refit3 | 3.25 | 33.439 | +95.9 % | best | 3 834 |
| b2 uniform | 2.25 | 4 834 445.700 | ×283279.4 | +24447.7 % | 458 |
| b2 shapeq | 2.25 | 103 854.597 | ×6085.5 | +427.3 % | 951 |
| b2 shapeq+refit3 | 2.25 | 19 694.082 | ×1154.0 | best | 2 875 |
| b3 lloyd rtn hist | 3.25 | 39.904 | ×2.3 | +19.3 % | 132 |
| b2 lloyd rtn hist | 2.25 | 31 813.388 | ×1864.1 | +61.5 % | 97 |
Table 2. Qwen2.5-0.5B, group 128, 1024 calibration rows, 64 evaluation chunks. The fp8/b4 rows were computed by the GPU branch (ppl evaluation on the MX250, bitwise-identical CPU quantization).
The effect reproduces on a second architecture and is confirmed in amplified form: b3 uniform 55 703 vs shapeq 68.5 — a gap of ×813 (on SmolLM — ×30). The behavior of the "almost-safe" rungs also matters: fp8 e4m3 costs only 1.0 % in ppl, while 4 bits with a fitted form already cost 12.7 %; further compression is territory where the form decides everything.
The form and GPTQ compensation add up rather than compete: on b3 the "uniform + κ" configuration (search over only the global table scale) yields 19 285 on Qwen — 3 times better than pure uniform, but 281 times worse than the fitted form under the same GPTQ. Lloyd refit of the table (Alg. 2, 3 rounds) adds on top: SmolLM b3 52.6 → 39.2 ppl (−25.4 %).
And a separate observation on the safety of the fitting itself. The κ range (fit_scale) has been clamped from the very start ([0.40; 1.25]) — yet on SmolLM uniform_k fails at almost every rung: b7 — 44.0; b6 — 55.5 vs 23.7 for pure uniform; b5 — 389; b3 — 29 068; b2 — 45 million (fp32 ladder; base 23.4). The fp16-GPU trace reproduces this (b6 — 90.6; b4 — 1 665). The issue is not the width of the range: in one tensor (layer 11, mlp.down_proj) the Hessian weights in the heavy tail are nearly zero, and the surrogate objective treats truncating the tail as free (κ ≈ 0.66, raw tensor error 0.008 % → 11.8 %), while the model needs the tails. On Qwen uniform_k stays adequate at the top rungs and falls from b4 (159 → 19 285 → 7.5 million). Conclusion: besides range clamping, scale fitting needs a tail guard — a fallback to κ = 1 when the quantiles' weight mass is near zero; without it the method is unpredictable on the rungs where it promises improvement.
| Grid | variant | compression cost | what the form captures |
|---|---|---|---|
| 8 levels | 4p — shapeq | 0.03738 | baseline: absolute objective Σwy²r²/Σwy² |
| 8 levels | 3a | +0.53 % | shared a (tail curvature); worst tensor +3.6 % |
| 8 levels | 3b | +0.11 % | shared b (starting curvature); worst tensor +1.3 % |
| 8 levels | 2s | +1.03 % | symmetric form (shapeq-sym); worst tensor +5.8 % |
| 16 levels | 4p — shapeq | 0.00796 | baseline: absolute objective Σwy²r²/Σwy² |
| 16 levels | 3a | +1.53 % | shared a (tail curvature); worst tensor +10.1 % |
| 16 levels | 3b | +1.13 % | shared b (starting curvature); worst tensor +20.3 % |
| 16 levels | 2s | +2.49 % | symmetric form (shapeq-sym); worst tensor +25.8 % |
Table 3. Compressing the form description: mean normalized objective over 21 layers.
Compressing the form description to three coefficients comes cheap: +1.13 % (shared b) or +1.53 % (shared a) at 16 levels, but the full transition to the symmetric 2s form rises to +2.5 % on average and +26 on the worst tensor — the asymmetry of the halves of the weight distribution is real, and different (a, b) pairs catch it. This is also visible on the θ map of all tensors (gridmap): the sign patterns of the deviations (a−1) and (b−1) occupy 3 of the 4 quadrants [SmolLM — [(a, b): 7 / (ā, b): 13 / (ā, b̄): 1]; Qwen — [(a, b): 2 / (ā, b): 19]] — a single "correct form" for all layers does not exist, per-tensor fitting is mandatory.
The intuitively attractive idea of "placing levels so that an equal number of weights falls between neighbors" (by analogy — optimality for a uniform objective under a non-uniform density) has been experimentally refuted: the equal-mass grid gives +139 % of error against uniform at 3 bits and +331 % at 4 (Fig. 3; the κ-scale correction — eqmassk — does not save it: +113 %). The reason is that equal masses equalize the number of weights in a bin, while the quadratic weighted objective pays for distance: densifying toward the modal zone without letting the tail steps stretch punishes the heavy tails intolerably. The only "fair" compromise — lloydhess (full weighted Lloyd without parameterization) — beats our formula by units of a percent of the objective, but requires iterations over the whole tensor; the Kumaraswamy formula gives the same result in a single compass descent.
At equal storage cost, fixed grids lose to fitting, and the ranking is informative: NF4 (Gaussian quantiles) — better than uniform (−28 % of the objective at 3 bits), but worse than shapeq (−40 %); the hardware FP4 E2M1, with its geometric ladder ±{½, 1, 1½, 2, 3, 4, 6}/6, is denser than NF4 near zero and coarser in the tails — by our hypothesis it should land between uniform and shapeq (the b4 fp4 row in Tables 1–2).
The hypothesis "reserve the top code for an outlier with a low-bit correction after linearization" did not hold: scheme D loses to both baselines (~+6 % of the objective vs B) while making the group 0.07–0.09 bit/weight more expensive, and oracle C shows that the ceiling of the whole "channel for the outlier" family lies below current solutions — because saving a level in the table costs more than the accuracy of one weight per group (a 96–128-weight group "buys" outlier accuracy at the price of coarsening the grid for all).
| Tier | kum | shapeq | lloyd | lloydhess | nf4 | uniform |
|---|---|---|---|---|---|---|
| 2 bits | 0.1263 | 0.0954 | 0.1002 | 0.0727 | 0.1564 | 0.2093 |
| 3 bits | 0.0226 | 0.0182 | 0.0230 | 0.0169 | 0.0242 | 0.0381 |
| 4 bits | 0.0049 | 0.0040 | 0.0059 | 0.0045 | 0.0049 | 0.0083 |
Table 4. Mean relative layer error tr(ΔHΔᵀ)/tr(WHWᵀ).
So that the ppl numbers would not remain "fake quantization in fp32", the b4 shapeq
configuration was assembled as a genuine packed file (https://huggingface.co/RomanPokora/shapeq-q4lut-models): 4-bit codes (two per byte), fp16 group
scales, a 16×fp16 LUT per tensor. The experiment answers two questions: (1) how much memory the
format costs and (2) whether LUT dequantization loses anything beyond the error of quantization
itself. The second answer is exact: the ppl of the packed model and of fake-quant
(weights snapped to the same grid, computed as fp32) matched to all 14 significant
digits (Table 5), i.e. all of the ppl damage comes from the 4 bits, not from the runtime.
Speed was not measured here: a correct speed comparison is given only by a
mature fused decoder with equal conditions for all methods (including the fixed NF4/IQ4_NL);
numbers from a homegrown python prototype would characterize the prototype, not the method.
This measurement was taken in the llama.cpp fork with a kernel for our format
(https://github.com/stiggigy-jpg/shapeq-q4lut) —
see the "q4lut" row in Table 7 (§6.11).
| Implementation | linear-layer weights, MB | ppl (16 chunks) | process RSS, MB |
|---|---|---|---|
| fp32 weights (base) | 425 | 28.083 | 1477 |
| b4 packed (codes+LUT, decoded at forward) | 56 | 32.961 | 978 |
| fake-quant fp32 (weights snapped to the grid, fp32 path) | 425 | 32.961 | — |
Packing: 56 MB on disk (~4.18 bit/weight including overhead) vs ≈425 MB for the same 106 million weights in fp32 (×7.7); embeddings are not part of the pack. Quantization + packing of the whole model took 1 529 s. Process RSS drops from 1477 to 978 MB. Greedy generation at ppl≈33 is plausible but thematically smeared and prone to repetition — the expected behavior of a 4-bit weights-only quant on a model of this size.
Table 5. SmolLM-135M b4 shapeq: format cost and dequantization accuracy (CPU, batch 1).
The final demonstration of the pipeline end to end: GSQ grid fitting and assignment (GPTQ for 4 bits, GPTQ+refit-3 for 3 bits), then RCO — Lagrangian allocation of bitness (3, 4) across layers under an average budget. At a budget of 4.0 bits the allocation degenerates into uniform 4-bit (a correctness check of the optimizer); at 3.5 — some layers get 3 bits without going over budget. Inference uses the packed model (3-bit codes packed bitwise, decode via LUT), with the fp32 base on the same chunks for comparison.
| Configuration | layers at 3/4 bits | bit/weight | ppl (16 chunks) | RSS, MB | pack, MB |
|---|---|---|---|---|---|
| RCO @ 4.0-bit budget | {'3': 1, '4': 209} | 4.33 | 31.526 | 1241 | 55 |
| RCO @ 3.5-bit budget | {'3': 120, '4': 90} | 3.83 | 37.968 | 1175 | 49 |
Table 6. Full GSQ/RCO mode on SmolLM-135M: quality and memory cost (speed is out of scope, as in §6.9).
To calibrate "what our b4 costs" against industrial quants, the same models were run through llama.cpp (CPU-only build, AVX2; corpus — the first 240 KB of WikiText-2, ctx 512; ppl via llama-perplexity, speed via llama-bench in one session, -t 6, r=4). This is a different corpus and a different pipeline than the pytorch section §6.2—6.9, so the numbers are not mixed with Tables 1—6: Table 7 is self-contained and shows the "size ↔ ppl ↔ speed" frontier of a mature runtime.
| Quant (llama.cpp) | file, MB | ppl | pp512, tok/s | tg128, tok/s | Δppl vs f16 |
|---|---|---|---|---|---|
| SmolLM-135M | |||||
| f16 | 259 | 18.12 | 322 | 51 | — |
| Q8_0 | 139 | 18.18 | 353 | 87 | +0.3 % |
| Q4_K_M | 101 | 19.06 | 269 | 99 | +5.2 % |
| IQ4_NL | 88 | 20.43 | 565 | 98 | +12.8 % |
| Q4_0 | 88 | 21.64 | 533 | 105 | +19.5 % |
| Q3_K_M | 90 | 20.79 | 496 | 111 | +14.8 % |
| Q2_K | 85 | 23.53 | 577 | 129 | +29.9 % |
| q4lut | 114 | 20.73 | 229 | 54 | +14.4 % |
| Q2_K+imat | 88 | 21.12 | 561 | 112 | +16.6 % |
| Q3_K_M+imat | 93 | 19.37 | 476 | 110 | +6.9 % |
| Q4_K_S+imat | 102 | 18.87 | 276 | 108 | +4.1 % |
| Q4_K_M+imat | 105 | 18.74 | 265 | 83 | +3.4 % |
| Qwen2.5-0.5B | |||||
| f16 | 994 | 14.09 | 92 | 13 | — |
| Q8_0 | 531 | 14.12 | 113 | 28 | +0.2 % |
| Q4_K_M | 397 | 14.51 | 98 | 29 | +2.9 % |
| IQ4_NL | 354 | 15.17 | 220 | 35 | +7.6 % |
| Q4_0 | 352 | 15.93 | 202 | 38 | +13.1 % |
| Q3_K_M | 355 | 15.26 | 166 | 26 | +8.3 % |
| Q2_K | 338 | 16.91 | 231 | 37 | +20.0 % |
| Q2_K+imat | 338 | 16.40 | 241 | 33 | +16.4 % |
| Q3_K_M+imat | 355 | 14.93 | 217 | 36 | +5.9 % |
| Q4_K_S+imat | 385 | 14.44 | 97 | 31 | +2.5 % |
| Q4_K_M+imat | 397 | 14.36 | 100 | 29 | +1.9 % |
q4lut — our format in the llama.cpp fork (type q4_lut, 4.17 bit/weight in the linear layers, embeddings and norms kept in f16, hence the file is larger than the pure-quant rows). Accuracy matches the pytorch pack (ppl[11] 22.6088 vs the f16-dequant reference 22.606); speed — the first fused-decoder implementation (no repack and no asm); it is below llama.cpp's tuned kernels and is reported as a measure of the format under equal conditions, not as an achievement.
Table 7 (continued — the "+imat" rows = k-quants with an importance matrix
(imatrix), Unsloth-GGUF recipe). Standard llama.cpp quants on a small corpus (pp512 —
prefill speed, tg128 — decode; without GGML_LLAMAFILE, so tg for some quants is
understated). Our packed b4 (shapeq) is the "q4lut" row: 55.5 MB of linear layers + f16 embeddings,
in this same pipeline and on the same runtime (llama.cpp fork with an AVX2 kernel for the format, v3,
https://github.com/stiggigy-jpg/shapeq-q4lut):
ppl 20.73 vs 21.64 for Q4_0 at the same byte price; speed −57 % on prefill
and −49 % on decode against Q4_0 — this is the price of LUT dequantization without repack-GEMM (see §8 on v4).
The speeds of the whole table were remeasured in one session (-t 6, r=4): the previous values were measured
under competing load and do not reproduce.
Unsloth Dynamic (the XL presets in llama.cpp and their GGUFs on imatrix) distributes bits as follows: all tensors go to the target bitness, and the top X% of "important" ones are automatically promoted in precision — ranking by tensor importance/error, the percentage fixed by the rubric. Our RCO takes tensors by marginal benefit (error drop at +1 bit) up to the average budget. We compared both strategies on a proxy metric (mean relative tensor error, GPTQ, fitted step — error matrix §6.4) at the same ebw:
| base → budget | allocation method | ebw | mean layer error | bit layout |
|---|---|---|---|---|
| SMOLLM · 21 tensors | ||||
| b2 → budget 2.6 | uniform bits | 2.33 | 3.01 % | {'2': 21, '3': 0, '4': 0, '5': 0} |
| b2 → budget 2.6 | top-k by importance (Unsloth ranking) | 2.57 | 1.81 % | {'2': 16, '3': 5, '4': 0, '5': 0} |
| b2 → budget 2.6 | XL rule: top 16% get +2 bits | 2.62 | 1.99 % | {'2': 18, '3': 0, '4': 3, '5': 0} |
| b2 → budget 2.6 | marginal criterion (RCO) | 2.57 | 1.81 % | {'2': 16, '3': 5, '4': 0, '5': 0} |
| b2 → budget 3.1 | uniform bits | 2.33 | 3.01 % | {'2': 21, '3': 0, '4': 0, '5': 0} |
| b2 → budget 3.1 | top-k by importance (Unsloth ranking) | 3.10 | 0.85 % | {'2': 5, '3': 16, '4': 0, '5': 0} |
| b2 → budget 3.1 | XL rule: top 16% get +2 bits | 2.62 | 1.99 % | {'2': 18, '3': 0, '4': 3, '5': 0} |
| b2 → budget 3.1 | marginal criterion (RCO) | 3.10 | 0.85 % | {'2': 5, '3': 16, '4': 0, '5': 0} |
| b3 → budget 3.4 | uniform bits | 3.33 | 0.70 % | {'2': 0, '3': 21, '4': 0, '5': 0} |
| b3 → budget 3.4 | top-k by importance (Unsloth ranking) | 3.38 | 0.61 % | {'2': 0, '3': 20, '4': 1, '5': 0} |
| b3 → budget 3.4 | marginal criterion (RCO) | 3.38 | 0.61 % | {'2': 0, '3': 20, '4': 1, '5': 0} |
| b3 → budget 3.83 | uniform bits | 3.33 | 0.70 % | {'2': 0, '3': 21, '4': 0, '5': 0} |
| b3 → budget 3.83 | top-k by importance (Unsloth ranking) | 3.81 | 0.25 % | {'2': 0, '3': 11, '4': 10, '5': 0} |
| b3 → budget 3.83 | marginal criterion (RCO) | 3.81 | 0.25 % | {'2': 0, '3': 11, '4': 10, '5': 0} |
| b3 → budget 4.33 | uniform bits | 3.33 | 0.70 % | {'2': 0, '3': 21, '4': 0, '5': 0} |
| b3 → budget 4.33 | top-k by importance (Unsloth ranking) | 4.29 | 0.16 % | {'2': 0, '3': 1, '4': 20, '5': 0} |
| b3 → budget 4.33 | marginal criterion (RCO) | 4.29 | 0.16 % | {'2': 0, '3': 1, '4': 20, '5': 0} |
| QWEN · 21 tensors | ||||
| b2 → budget 2.6 | uniform bits | 2.25 | 2.62 % | {'2': 21, '3': 0, '4': 0, '5': 0} |
| b2 → budget 2.6 | top-k by importance (Unsloth ranking) | 2.58 | 1.44 % | {'2': 14, '3': 7, '4': 0, '5': 0} |
| b2 → budget 2.6 | XL rule: top 16% get +2 bits | 2.54 | 1.93 % | {'2': 18, '3': 0, '4': 3, '5': 0} |
| b2 → budget 2.6 | marginal criterion (RCO) | 2.58 | 1.44 % | {'2': 14, '3': 7, '4': 0, '5': 0} |
| b2 → budget 3.1 | uniform bits | 2.25 | 2.62 % | {'2': 21, '3': 0, '4': 0, '5': 0} |
| b2 → budget 3.1 | top-k by importance (Unsloth ranking) | 3.06 | 0.66 % | {'2': 4, '3': 17, '4': 0, '5': 0} |
| b2 → budget 3.1 | XL rule: top 16% get +2 bits | 2.54 | 1.93 % | {'2': 18, '3': 0, '4': 3, '5': 0} |
| b2 → budget 3.1 | marginal criterion (RCO) | 3.06 | 0.66 % | {'2': 4, '3': 17, '4': 0, '5': 0} |
| b3 → budget 3.4 | uniform bits | 3.25 | 0.59 % | {'2': 0, '3': 21, '4': 0, '5': 0} |
| b3 → budget 3.4 | top-k by importance (Unsloth ranking) | 3.39 | 0.45 % | {'2': 0, '3': 18, '4': 3, '5': 0} |
| b3 → budget 3.4 | marginal criterion (RCO) | 3.39 | 0.45 % | {'2': 0, '3': 18, '4': 3, '5': 0} |
| b3 → budget 3.83 | uniform bits | 3.25 | 0.59 % | {'2': 0, '3': 21, '4': 0, '5': 0} |
| b3 → budget 3.83 | top-k by importance (Unsloth ranking) | 3.82 | 0.20 % | {'2': 0, '3': 9, '4': 12, '5': 0} |
| b3 → budget 3.83 | marginal criterion (RCO) | 3.82 | 0.20 % | {'2': 0, '3': 9, '4': 12, '5': 0} |
Table 8. On a tensor-separable metric, ranking "by importance" and the marginal criterion give the same layout (both promote the same layers), while the rigid XL rule "top 16% gets +2 bits" loses — it pays for a fixed percentage at any budget. The true difference between strategies is visible only on a metric that does not separate tensors — perplexity: our RCO@3.5 (Table 6) holds ppl 37.968 where uniform 3-bit yields a garbage model; the imatrix rows of Table 7 show the same effect in the mature runtime.
To compare all variants at equal bitness (grid × rounding × refit), we ran the full 8/6/4-bit ladder on the MX250: quantization by the numpy reference, forward pass and perplexity in fp16 on GPU. The fp16-GPU base gives 23.358 and matches the fp32 base of Tables 1–4 to the third digit; the uniform rows of the two traces also agree (b4: 33.796 vs 33.806). SHAPEQ diverges by 1.2 ppl (32.618 vs 31.385). The cause is fitting variance in the legacy fitter: it fitted the shape to a random subsample, and after fp16 rounding the grid shifts, which on a coarse b4 grid flips the rounding decision for some weights. The fixed FP4 grid shows no such variance (27.102 vs 27.067). This motivates the deterministic histogram fitter of Section 7.7; the legacy numbers are reported as measured.
| Configuration | bit/weight | WikiText-2 ppl | vs fp16 gpu | vs best in its bit-width | quant., s |
|---|---|---|---|---|---|
| fp16 gpu | 16.0 | 23.358 | — | — | 0 |
| fp8 e4m3 | 8.167 | 23.569 | +0.9 % | — | 0 |
| b8 uniform | 8.333 | 23.380 | +0.1 % | +0.1 % | 952 |
| b8 uniform rtn | 8.333 | 23.383 | +0.1 % | +0.1 % | 15 |
| b8 shapeq | 8.333 | 23.367 | +0.0 % | +0.1 % | 2 146 |
| b8 shapeq rtn | 8.333 | 23.350 | ±0.0 % | best | 1 182 |
| b8 shapeq+refit3 | 8.333 | 23.369 | +0.0 % | +0.1 % | 5 389 |
| b6 uniform | 6.333 | 23.679 | +1.4 % | +0.8 % | 314 |
| b6 uniform rtn | 6.333 | 24.097 | +3.2 % | +2.5 % | 14 |
| b6 uniform_k | 6.333 | 90.559 | ×3.9 | +285.3 % | 349 |
| b6 shapeq | 6.333 | 23.502 | +0.6 % | best | 1 276 |
| b6 shapeq rtn | 6.333 | 23.634 | +1.2 % | +0.6 % | 837 |
| b6 shapeq+refit3 | 6.333 | 23.525 | +0.7 % | +0.1 % | 4 724 |
| b4 uniform | 4.333 | 33.796 | +44.7 % | +29.6 % | 313 |
| b4 uniform rtn | 4.333 | 43.846 | +87.7 % | +68.1 % | 17 |
| b4 uniform_k | 4.333 | 1 665.275 | ×71.3 | +6284.0 % | 429 |
| b4 shapeq | 4.333 | 32.618 | +39.6 % | +25.0 % | 717 |
| b4 shapeq rtn | 4.333 | 28.747 | +23.1 % | +10.2 % | 601 |
| b4 shapeq+refit3 | 4.333 | 27.228 | +16.6 % | +4.4 % | 1 863 |
| b4 fp4 | 4.333 | 27.102 | +16.0 % | +3.9 % | 181 |
| b4 fp4 rtn | 4.333 | 28.941 | +23.9 % | +10.9 % | 12 |
| b4 shapeq unsloth16 | 4.648 | 30.127 | +29.0 % | +15.5 % | 959 |
| b4 shapeq marg16 | 4.648 | 33.115 | +41.8 % | +27.0 % | 2 242 |
| b4 shapeq rco3.5 | 3.835 | 31.937 | +36.7 % | +22.4 % | 2 339 |
| b6 shapeq rco5.5 | 5.833 | 25.144 | +7.6 % | +7.0 % | 3 354 |
Table 9. SmolLM-135M, fp16-GPU base: the full cross of variants at equal bitness (b4 group: 10 configurations). The "in its own bitness" column — relative to the best in the group.
The b4 group reverses the usual rounding hierarchy, but only on this model. On the warped SHAPEQ grid, GPTQ compensation hurts: RTN gives 28.747 against 32.618 for GPTQ, whereas at b6 and b8 the order is opposite. On the fixed FP4 grid GPTQ helps (27.102 vs 28.941): error feedback appears to break against the fitted grid and its long shelves. Qwen2.5-0.5B shows no reversal on the same numerical trace (b4 SHAPEQ RTN 19.389 vs 19.225 for GPTQ, within fitting variance), so this is a property of the specific model–grid pair, not a general law. Refit (SHAPEQ+refit3) reaches 27.228, level with FP4 on this trace; on the fp32 ladder (Table 1) the edge is clearer: 25.924 vs 27.067 for FP4 (−4.2 %). At 6–8 bits refit adds nothing (b6: 23.525 vs 23.502): the grid is already close to optimal.
Mixed-bitness allocation does not change this picture. At an equal budget of 4.65 effective bits, the Unsloth XL rubric (top 16 % of tensors by H-weighted error promoted by +2 bits) gives 30.127 and the marginal criterion 33.115; both lose to whole-grid SHAPEQ+refit3 at 4.33 bits (27.228). Part of the gap comes from the GPTQ base, which loses to RTN on this grid, but the ordering is stable. Pure RCO allocation (3/4 bits) at a smaller budget of 3.835 bits gives 31.937 — better than uniform b4 GPTQ (32.618) but worse than plain RTN (28.747); the fp32 ladder reproduces the result (31.372 vs 31.385 at 4.33 bits). Bit allocation does not repair GPTQ compensation on the fitted grid; a cheap whole-grid refit does.
Inference engines love table-free formats: decode w = s·q — one FMA per weight, no gather and no 32 bytes of fp16 per tensor. We measured the price of such a simplification on the main protocol (fp32 trace, gptq rounding, group 96/128): the same 4-bit depth and three families of decodes — scale-only (symmetric uniform grid, Q4_0-style, "uniform_k"), scale with shift (Q4_1-style, "uniform") and full dequantization via the fitted table (our method):
| Decode (4 bits/weight) | SmolLM-135M | Qwen2.5-0.5B |
|---|---|---|
| scale only (no LUT) | 345.5 | 159.3 |
| scale + shift (no LUT) | 33.81 | 22.65 |
| LUT of the fitted grid | 26.00 | 19.23 |
Table 9b. The price of dropping the LUT at an equal bit budget (WikiText-2 ppl, fp32 trace; SmolLM group 96, Qwen group 128). Uniform grids do not depend on the fitting engine (they are fixed), the rows are from the fp32-CPU traces; the SmolLM LUT row is from the hist era, Qwen from the legacy ladder. For reference: on the rtn trace the drop is cheaper (Qwen b4 uniform_k rtn 55.65), but it fails too; fp32 base: 23.36 / 19.37.
At 4 bits "scale-only" costs ×13 ppl on SmolLM (345.5 vs 26.0) and ×8 on Qwen; almost everything is lost not by the table as such but by the zero shift — with a shift the uniform grid gets to +30 %/+17 % over the base. But at 3 bits without a table the model is no longer salvageable by anything: 29 068 vs 52.6 with the LUT (×553). For a practitioner: a table of 16 levels costs 32 bytes per tensor and one gather in the decoder — and it is what keeps the model on coherent text at 4 bits; "pure Q4_0 on our own indices" is a saving that pays with an order of magnitude of ppl.
The classical quantization asymptotics for the error order r=2 prescribes a level density λ(x) ∝ p(x)1/3 — where p is the data density (Zador's high-resolution quantization result as presented by Gersho [16]). A uniform grid takes λ = const (under-packed at the mode); an equal-mass one — λ ∝ p (exponent 1 instead of 1/3). That is why eqmass is not "nearly optimal" but worse than uniform (Section 6.5): it packs levels at the mode too densely and pays with distances in the tails, and a quadratic objective pays with the square of the distance. The Kumaraswamy family is not, strictly speaking, a family of p1/3-grids, but its two-parameter bends cross the required profile freely — and, unlike the theorem, they work at small L (16 levels is not asymptotics) and with a weighted, not uniform, objective.
The diagonal of the Hessian is the mean squared channel activation; weighting by it tells the grid where an error hurts most: channels through which large signals pass (the well-known source of outlier trouble — LLM.int8 [5]) receive a denser grid. The full matrix H is left out of the fit: off-diagonal crossings are already handled by the GPTQ compensation, and the fit-matrix experiments showed an almost complete agreement of the diag(H) objective with the full quadratic form. The name SHAPEQ denotes the two ingredients of the method: a shape fitted per tensor, and quantization that keeps the existing code and scale machinery.
The non-parametric lloydhess beats the formula by 1–2 % of the objective — and we give up these percents: 4 parameters fitted over 150k points are a hard regularization; they do not overfit calibration noise and give equally predictable behavior on all tensors (full Lloyd on "skinny" groups sometimes drops levels into empty bins). Refit (Alg. 2) is a dosed compromise: 3 rounds of Lloyd over the formula gave −25 % ppl at b3 and almost nothing at b4: the fewer levels, the more polishing is worth it.
The method changes the alphabet, not the pipeline: the decode stays a table lookup (like IQ4_NL [15]), so the cost is equal and the quality is above fixed alphabets. Rotation methods (QuIP [7]) fight the same problem — non-isotropy and tails — by rotating the weight space; this is an orthogonal lever, and the combination "rotation + fitted shape" is the natural next step. There is no competition with hardware FP4/MX [14]: they pay off in the compute-bound W4A4 regime, our method — in the memory-bound weight-only one, where a table of 16 fp16 numbers per tensor costs nothing. Our data also suggest a "shape library" compromise: keep K=8…16 pre-fitted tables per layer type and pick one for the group with a 3-bit pointer — a price of ~0.05 bits/weight instead of 0.0006 bits per tensor, should LUT memory ever become a problem.
Shape fitting is one-off: <1 s per tensor at quantization time (a full model run — minutes), storage — 32 B per tensor, inference — unchanged. The gain concentrates in the 2–4-bit zone, where the bit hunt happens: at 4 bits this is −4.2 ppl on Qwen (22.6 → 19.2, twice as close to the fp16 loss); at 3 bits it moves a configuration from "model broken" to "model works" (55 703 → 68.5). At 8 bits the shape, as theory predicts, is almost unnecessary — the 8/6-bit ladder (rows in progress) probes the saturation point.
The method is designed as a stage of the existing GSQ / RCO quantization pipeline (our GSQ pipeline; in this paper GSQ is represented by its assignment core — GPTQ alternating with table refit, RCO — a Lagrangian 2/3-bit allocation across layers under an exact budget). The integration changes neither the file format nor the decoder: (1) table fitting inserts before assignment as one new stage (fractions of a second per tensor with the compass-descent fit, seconds — with refit; the calibration run for the immatrix/GPTQ is already shared); (2) GSQ assignment works on the fitted grid as on a parameter — the code and masks do not change; (3) for RCO the LUT cost (32 B per tensor) is noise in the budget problem, and layer ranking by proxy error only benefits from a uniform alphabet. The synergy hypothesis: RCO, distributing bits across layers, gets a fairer layer comparison when all layers share one grid methodology; testing it is planned.
The original fitter (fit_warp, fit_scale, weighted_lloyd) rotated parameters over a random 150k-point subsample, seeded from the tensor hash. This is cheap but introduces result variance and a cost linear in tensor size. The current fitter builds a weighted histogram of group values (8192 bins) once in O(n); each trial then costs O(bins), while the objective is unchanged up to a bin bias of order (bin width)2/12. On real tensors and heavy-tailed synthetic data the histogram grids are no worse (worst deviation +0.01 %, typically 0.5–4 % better), the result is fully deterministic, and fitting is 1.3–16× faster. On the model, SmolLM b4 takes 66 s instead of 1039 s; perplexity changes by −4.9 % on SmolLM b4 (27.047 vs 28.440), −0.8 % on Qwen b6 and +0.8 % on Qwen b4 (the last within the old subsample variance). Three independent implementations (OpenCL, host numpy, VM numpy) agree within 0.40 %. Since 19 November 2026 the histogram path is the default; QB_LEGACY_FIT=1 reproduces the old one, and all numbers measured on it are reported as measured.
The RCO method (Helcig and Alistarh, 2026 [17]) allocates bit widths across layers on an exact-budget manifold by optimizing a layered discrete Gumbel-softmax. We reproduced its quantize–search–checkpoint stage on CPU (gloo and a device patch), with 32×2048 calibration tokens and 60 search steps instead of 300. The search took about 22 hours of a single-threaded slot and was limited by the 7.6 GB RAM of the machine.
Allocation. Both learned allocations degenerated to two extreme widths: at a 3.5-bit target, 155 layers at 3 bits and 55 at 5 bits; at 4.0 bits, 104 layers at 3, one at 4 and 105 at 5. At the top of a linear budget the simplex vertex wins, so no intermediate width appears.
Numerical failure in the CPU reproduction. The OBQ stage silently diverged: 4-bit scales were inflated 7.7-fold, the dequantized norm exceeded the weight norm by 1.64×, per-layer NMSE reached 2.07 (worse than a zero approximation), and the search objective started at 10.9 against a fp32 cross-entropy of 3.2. OBQ error feedback scales by chol(H−1) and explodes on a degenerate Hessian; the Hessians are not persistent, so the basis cannot be recovered from the corrupted database. This is not an upstream defect — their GPU pipeline agrees — but a reproduction should check the NMSE of the fake-quant checkpoint before launching the search.
The useful comparison is not their quantizer against ours (broken above), but their bit allocation over our grid and rounding (Table 10, protocol of Table 1, group 96).
| Configuration | bit/weight | ppl (legacy fit) | ppl (hist fit) |
|---|---|---|---|
| uniform 4 bits (our grid, no refit) | 4.33 | 31.39 | 26.00 |
| RCO allocation 3.5 (our grid) | 3.83 | 32.27 | 32.27 |
| RCO allocation 4.0 (our grid) | 4.33 | 29.74 | 29.74 |
| RCO allocation 4.0 + refit-3 | 4.33 | 29.16 | — |
| uniform 4 bits + refit-3 | 4.33 | 25.92 | 26.22 |
Table 10. RCO bit allocation over our grid (SmolLM-135M, WikiText-2). Without refit the legacy and histogram fits agree to the third digit. With refit the histogram engine is slightly worse (26.22 vs 25.92): histogram fitting already exhausts the table's degrees of freedom, and a Lloyd step under a different weighting only spoils them.
At equal 4.33 effective bits the RCO allocation without refit beats flat 4 bits (29.74 vs 31.39). Refit over the flat allocation gives −2 % (29.16), while refit over a flat bit width gives −17 % (25.92). Flat 4 bits plus refit is therefore cheaper and better than RCO allocation plus refit. The allocation spends budget on 5-bit layers with small marginal gain, and the 104 three-bit layers are not rescued by refit; refit also flattens per-layer differences, so the allocator's lever degenerates. This refines Conclusion 7: the synergy appears at the grid-methodology level (Section 7.6), not at the level of adding bits.
Ternary negative result. We also tested whether assigning weights to {−1, 0, +1} with equal masses per level [18] plus a three-value group LUT gives a usable weight-only PTQ at ≈1.9 bits. On all 210 SmolLM layers (group 96, MSE proxy), nearest-level assignment gives NMSE 0.1893; equal thirds 0.2136 (12.9 % worse); the best outer-level share p=0.26 gives 0.1970, and even a per-group oracle over p (0.1916) does not reach nearest level. The optimum p≈0.26 matches the Gaussian level-density law (22–28 % on the outer levels), so equal thirds is optimal only under the Gaussian prior. End-to-end on Qwen2.5-0.5B (fp32, group 128, Table 11) pure ternary loses about three orders of magnitude of perplexity at a weight NMSE of 0.19–0.23, and the arm order repeats the MSE order. Ternary quantization therefore needs training or activation awareness; pure assignment is not enough.
| Arm | weight NMSE | WikiText-2 ppl | vs base |
|---|---|---|---|
| fp32 base | 0.0000 | 13.05 | — |
| nearest level | 0.2009 | 80 365 | 6 158× |
| share p=0.26 | 0.2083 | 81 337 | 6 232× |
| equal thirds (1/3) | 0.2297 | 229 286 | 17 570× |
Table 11. Ternary arms on Qwen2.5-0.5B; the perplexity order repeats the weight-MSE order. The base NMSE is the fp32 error against itself.
Reference implementation: Python 3 with numpy float64 on CPU; GPTQ and Hessian
caching also run in float64. The grid fitter, the packing script, the evaluation
drivers, and all raw CSV/JSON artifacts are in https://github.com/stiggigy-jpg/shapeq-paper.
The Q4_LUT/Q4_LUT64 kernels are at https://github.com/stiggigy-jpg/shapeq-q4lut; the packed GGUFs
and fitted packs are at https://huggingface.co/RomanPokora/shapeq-q4lut-models, with hashes in
SHA256SUMS.txt. The SmolLM pack uses the legacy engine; the Qwen pack
uses the histogram engine. A rerun is gated by those hashes and by the perplexity
and greedy-64 anchors in b4_qwen_shapeq.pt.json.
python fit_b4.py --model HuggingFaceTB/SmolLM-135M --engine legacy --test-chunks 96 \\
--out b4_smollm_shapeq.pt
python fit_b4.py --model Qwen/Qwen2.5-0.5B --dtype fp16 --group 64 --test-chunks 16 \\
--out b4_qwen_shapeq.pt
python pack_q4lut.py --pack b4_smollm_shapeq.pt \\
--base smollm-f16.gguf --out smollm-135m-q4lut.gguf
python run_ppl_grid.py --model HuggingFaceTB/SmolLM-135M --engine legacy \\
--out results_ppl.csv
Environment used for the reported numbers: WSL2, Linux kernel 5.15, 12 CPU cores, 7.6 GB RAM, 2 GB swap; NVIDIA MX250 2 GB (CUDA 11.8, torch 2.4.1+cu118) for GPU perplexity only. The GPU perplexity evaluation was cross-checked against CPU (17.067 vs 17.066). The GPU quantization gate required weighted layer-error divergence ≤ 0.03 %. Absolute perplexity can shift in the last decimal or two with BLAS reduction order.
Artifacts: results_ppl.csv, results_ppl_qwen.csv,
results_layers.csv, the probe JSON files, the ternary scans, and the RCO
search configurations. results/MANIFEST.md maps each file to a table and a
regeneration command.