Grid shape as an independent lever in 2–4-bit weight-only LLM quantization
fitting non-uniform grids from the weight distribution and the Hessian

Roman S. Pokora · Independent researcher · Preprint, November 2026

Abstract

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.

1. Introduction

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:

  1. a formulation of grid fitting as a weighted Lloyd–Max quantization problem with a parametric family of shapes (Section 4), and a practical fitting algorithm costing under a second per tensor (Algorithm 1);
  2. an experimental "layer-MSE → perplexity" protocol on two models (SmolLM-135M, Qwen2.5-0.5B) and the full bit-width ladder 8/6/4/3/2 for the fitted grid (Section 6);
  3. an experimental refutation of the popular "equal-mass" grid idea (Section 6.5) and a quantitative assessment of the contribution of Hessian weighting, symmetry, and the number of shape parameters (Sections 6.2–6.4);
  4. a comparison with fixed "smart" grids — NF4 [3] and the hardware FP4 E2M1 from the OCP MX format [14]: per-tensor shape fitting gives a stable −15…−17 % of weighted error relative to NF4; the FP4 comparison is included in the protocol (Section 6.6).

2. Related 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.

3. Problem statement

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.

4. Algorithms

4.1. Family of shapes

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.

4.2. Hessian-guided grid fitting (Algorithm 1)

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.

4.3. Table refit (Algorithm 2, "Hessian Lloyd")

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).

4.4. GPTQ rounding (Algorithm 3)

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).

4.5. Storage and cost

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).

5. Experimental protocol

5.1. Models and data

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.

5.2. Two-level metric

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.

5.3. Fairness of comparisons

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.

5.4. Validation of the numbers

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).

6. Results

6.1. Main bit-width ladder (SmolLM-135M)

Configurationbit/weightWikiText-2 pplvs fp32within its bit-widthquant., s
fp3232.023.358——0
b8 shapeq8.33323.355±0.0 %best871
b8 shapeq+refit38.33323.362+0.0 %+0.0 %4 557
b6 shapeq6.33323.463+0.4 %best405
b6 shapeq+refit36.33323.531+0.7 %+0.3 %3 333
b4 uniform4.33333.806+44.7 %+30.4 %175
b4 shapeq4.33331.385+34.4 %+21.1 %698
b4 shapeq+refit34.33325.924+11.0 %best1 846
b4 fp44.33327.067+15.9 %+4.4 %173
b4 eqmassk4.33344.295+89.6 %+70.9 %173
b4 eqmass4.333186.694×8.0+620.2 %169
b3 uniform3.3331 580.159×67.6+3928.9 %278
b3 uniform_k3.33329 068.159×1244.5+74013.8 %265
b3 shapeq3.33352.563×2.3+34.0 %938
b3 shapeq+refit33.33339.221+67.9 %best1 799
b3 eqmass3.3332 829.929×121.2+7115.3 %153
rco 3.5 form3.83331.372+34.3 %—1 031
b2 uniform_k2.33345 302 916.186×1939503.2+1160898.8 %305
b2 shapeq2.333306 235.929×13110.5+7748.0 %1 051
b2 shapeq+refit32.3333 902.064×167.1best930
b2 eqmass2.3331 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.

6.2. Arbitration on a larger model (Qwen2.5-0.5B)

Configurationbit/weightWikiText-2 pplvs fp16within its bit-widthquant., s
fp1632.017.066——0
fp8 e4m38.12517.230+1.0 %—1
b4 uniform4.2522.649+32.7 %+19.2 %704
b4 fp44.2520.211+18.4 %+6.3 %952
b4 shapeq4.2519.225+12.7 %+1.2 %1 152
b4 shapeq+refit34.2519.005+11.4 %best4 786
b4 eqmassk4.2543.960×2.6+131.3 %662
b4 eqmass4.25412.556×24.2+2070.8 %688
b3 uniform3.2555 703.448×3264.0+166482.3 %498
b3 uniform_k3.2519 285.489×1130.1+57573.6 %544
b3 shapeq3.2568.517×4.0+104.9 %1 098
b3 shapeq+refit33.2533.439+95.9 %best3 834
b2 uniform2.254 834 445.700×283279.4+24447.7 %458
b2 shapeq2.25103 854.597×6085.5+427.3 %951
b2 shapeq+refit32.2519 694.082×1154.0best2 875
b3 lloyd rtn hist3.2539.904×2.3+19.3 %132
b2 lloyd rtn hist2.2531 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).

b3 uniform55 703.45b3 uniform_k19 285.49b3 shapeq68.52b4 uniform22.65b4 fp420.21b4 shapeq19.23b4 eqmass412.56b4 eqmassk43.96fp8 e4m317.23fp1617.07
Fig. 1. Qwen2.5-0.5B: WikiText-2 ppl on a logarithmic scale. Gray — uniform grid, orange — fitted (shapeq), gold — fixed "smart" grids (FP4/eqmass), blue/black — references.

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.

6.3. Form vs rounding

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.

6.4. How many parameters the form needs

Gridvariantcompression costwhat the form captures
8 levels4p — shapeq0.03738baseline: absolute objective Σwy²r²/Σwy²
8 levels3a+0.53 %shared a (tail curvature); worst tensor +3.6 %
8 levels3b+0.11 %shared b (starting curvature); worst tensor +1.3 %
8 levels2s+1.03 %symmetric form (shapeq-sym); worst tensor +5.8 %
16 levels4p — shapeq0.00796baseline: absolute objective Σwy²r²/Σwy²
16 levels3a+1.53 %shared a (tail curvature); worst tensor +10.1 %
16 levels3b+1.13 %shared b (starting curvature); worst tensor +20.3 %
16 levels2s+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.

uniformNF4 (quantiles N(0.1))FP4 E2M1shapeq (fitted)-1.0-0.50.00.51.0frequency
Fig. 2. Weight histogram of model.layers.0.mlp.down_proj (SmolLM, absmax normalization) and level positions of the four grids. The fitted grid densifies in the modal zone and leaves rare levels in the tails; NF4 and FP4 densify the center "by eye", ignoring the data.

6.5. Refutation of equal-mass grids

uniformNF4shapeqeqmass (equal-mass)20.217.414.426.52 bits5.84.23.513.93 bits1.61.00.86.74 bits
Fig. 3. Mean relative layer error over 21 SmolLM layers. eqmass (red) — a grid with equal probability masses between neighboring levels — loses even to the uniform one; the fitted form wins by −28…−47 %.

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.

6.6. Fixed "smart" grids: NF4 and FP4 E2M1

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).

6.7. Outliers vs group scale

A uniformB fittedC symm.D manual14.414.510.415.42 bits3.53.62.83.63 bits0.80.80.70.84 bits
Fig. 4. The absmax group scheme (A), free fp16 scale (B), exact-outlier oracle (C), and the scheme with a low-bit outlier correction (D). M — the metric tr(ΔHΔᵀ)/tr(WHWᵀ), %.

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).

6.8. Layer errors: summary over 21 layers

Tierkumshapeqlloydlloydhessnf4uniform
2 bits0.12630.09540.10020.07270.15640.2093
3 bits0.02260.01820.02300.01690.02420.0381
4 bits0.00490.00400.00590.00450.00490.0083

Table 4. Mean relative layer error tr(ΔHΔᵀ)/tr(WHWᵀ).

6.9. True 4-bit packing: memory and format accuracy

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).

Implementationlinear-layer weights, MBppl (16 chunks)process RSS, MB
fp32 weights (base)42528.0831477
b4 packed (codes+LUT, decoded at forward)5632.961978
fake-quant fp32 (weights snapped to the grid, fp32 path)42532.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).

6.10. Full GSQ / RCO mode: mixed-bitness inference

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.

Configurationlayers at 3/4 bitsbit/weightppl (16 chunks)RSS, MBpack, MB
RCO @ 4.0-bit budget{'3': 1, '4': 209}4.3331.526124155
RCO @ 3.5-bit budget{'3': 120, '4': 90}3.8337.968117549

Table 6. Full GSQ/RCO mode on SmolLM-135M: quality and memory cost (speed is out of scope, as in §6.9).

6.11. The mature runtime as a scale yardstick

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, MBpplpp512, tok/stg128, tok/sΔppl vs f16
SmolLM-135M
f1625918.1232251—
Q8_013918.1835387+0.3 %
Q4_K_M10119.0626999+5.2 %
IQ4_NL8820.4356598+12.8 %
Q4_08821.64533105+19.5 %
Q3_K_M9020.79496111+14.8 %
Q2_K8523.53577129+29.9 %
q4lut11420.7322954+14.4 %
Q2_K+imat8821.12561112+16.6 %
Q3_K_M+imat9319.37476110+6.9 %
Q4_K_S+imat10218.87276108+4.1 %
Q4_K_M+imat10518.7426583+3.4 %
Qwen2.5-0.5B
f1699414.099213—
Q8_053114.1211328+0.2 %
Q4_K_M39714.519829+2.9 %
IQ4_NL35415.1722035+7.6 %
Q4_035215.9320238+13.1 %
Q3_K_M35515.2616626+8.3 %
Q2_K33816.9123137+20.0 %
Q2_K+imat33816.4024133+16.4 %
Q3_K_M+imat35514.9321736+5.9 %
Q4_K_S+imat38514.449731+2.5 %
Q4_K_M+imat39714.3610029+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.

6.12. Unsloth-style vs RCO: how to rank "whom to save with a bit"

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 → budgetallocation methodebwmean layer errorbit layout
SMOLLM · 21 tensors
b2 → budget 2.6uniform bits2.333.01 %{'2': 21, '3': 0, '4': 0, '5': 0}
b2 → budget 2.6top-k by importance (Unsloth ranking)2.571.81 %{'2': 16, '3': 5, '4': 0, '5': 0}
b2 → budget 2.6XL rule: top 16% get +2 bits2.621.99 %{'2': 18, '3': 0, '4': 3, '5': 0}
b2 → budget 2.6marginal criterion (RCO)2.571.81 %{'2': 16, '3': 5, '4': 0, '5': 0}
b2 → budget 3.1uniform bits2.333.01 %{'2': 21, '3': 0, '4': 0, '5': 0}
b2 → budget 3.1top-k by importance (Unsloth ranking)3.100.85 %{'2': 5, '3': 16, '4': 0, '5': 0}
b2 → budget 3.1XL rule: top 16% get +2 bits2.621.99 %{'2': 18, '3': 0, '4': 3, '5': 0}
b2 → budget 3.1marginal criterion (RCO)3.100.85 %{'2': 5, '3': 16, '4': 0, '5': 0}
b3 → budget 3.4uniform bits3.330.70 %{'2': 0, '3': 21, '4': 0, '5': 0}
b3 → budget 3.4top-k by importance (Unsloth ranking)3.380.61 %{'2': 0, '3': 20, '4': 1, '5': 0}
b3 → budget 3.4marginal criterion (RCO)3.380.61 %{'2': 0, '3': 20, '4': 1, '5': 0}
b3 → budget 3.83uniform bits3.330.70 %{'2': 0, '3': 21, '4': 0, '5': 0}
b3 → budget 3.83top-k by importance (Unsloth ranking)3.810.25 %{'2': 0, '3': 11, '4': 10, '5': 0}
b3 → budget 3.83marginal criterion (RCO)3.810.25 %{'2': 0, '3': 11, '4': 10, '5': 0}
b3 → budget 4.33uniform bits3.330.70 %{'2': 0, '3': 21, '4': 0, '5': 0}
b3 → budget 4.33top-k by importance (Unsloth ranking)4.290.16 %{'2': 0, '3': 1, '4': 20, '5': 0}
b3 → budget 4.33marginal criterion (RCO)4.290.16 %{'2': 0, '3': 1, '4': 20, '5': 0}
QWEN · 21 tensors
b2 → budget 2.6uniform bits2.252.62 %{'2': 21, '3': 0, '4': 0, '5': 0}
b2 → budget 2.6top-k by importance (Unsloth ranking)2.581.44 %{'2': 14, '3': 7, '4': 0, '5': 0}
b2 → budget 2.6XL rule: top 16% get +2 bits2.541.93 %{'2': 18, '3': 0, '4': 3, '5': 0}
b2 → budget 2.6marginal criterion (RCO)2.581.44 %{'2': 14, '3': 7, '4': 0, '5': 0}
b2 → budget 3.1uniform bits2.252.62 %{'2': 21, '3': 0, '4': 0, '5': 0}
b2 → budget 3.1top-k by importance (Unsloth ranking)3.060.66 %{'2': 4, '3': 17, '4': 0, '5': 0}
b2 → budget 3.1XL rule: top 16% get +2 bits2.541.93 %{'2': 18, '3': 0, '4': 3, '5': 0}
b2 → budget 3.1marginal criterion (RCO)3.060.66 %{'2': 4, '3': 17, '4': 0, '5': 0}
b3 → budget 3.4uniform bits3.250.59 %{'2': 0, '3': 21, '4': 0, '5': 0}
b3 → budget 3.4top-k by importance (Unsloth ranking)3.390.45 %{'2': 0, '3': 18, '4': 3, '5': 0}
b3 → budget 3.4marginal criterion (RCO)3.390.45 %{'2': 0, '3': 18, '4': 3, '5': 0}
b3 → budget 3.83uniform bits3.250.59 %{'2': 0, '3': 21, '4': 0, '5': 0}
b3 → budget 3.83top-k by importance (Unsloth ranking)3.820.20 %{'2': 0, '3': 9, '4': 12, '5': 0}
b3 → budget 3.83marginal criterion (RCO)3.820.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.

6.13. All variants at equal bitness: the fp16-GPU ladder for SmolLM

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.

Configurationbit/weightWikiText-2 pplvs fp16 gpuvs best in its bit-widthquant., s
fp16 gpu16.023.358——0
fp8 e4m38.16723.569+0.9 %—0
b8 uniform8.33323.380+0.1 %+0.1 %952
b8 uniform rtn8.33323.383+0.1 %+0.1 %15
b8 shapeq8.33323.367+0.0 %+0.1 %2 146
b8 shapeq rtn8.33323.350±0.0 %best1 182
b8 shapeq+refit38.33323.369+0.0 %+0.1 %5 389
b6 uniform6.33323.679+1.4 %+0.8 %314
b6 uniform rtn6.33324.097+3.2 %+2.5 %14
b6 uniform_k6.33390.559×3.9+285.3 %349
b6 shapeq6.33323.502+0.6 %best1 276
b6 shapeq rtn6.33323.634+1.2 %+0.6 %837
b6 shapeq+refit36.33323.525+0.7 %+0.1 %4 724
b4 uniform4.33333.796+44.7 %+29.6 %313
b4 uniform rtn4.33343.846+87.7 %+68.1 %17
b4 uniform_k4.3331 665.275×71.3+6284.0 %429
b4 shapeq4.33332.618+39.6 %+25.0 %717
b4 shapeq rtn4.33328.747+23.1 %+10.2 %601
b4 shapeq+refit34.33327.228+16.6 %+4.4 %1 863
b4 fp44.33327.102+16.0 %+3.9 %181
b4 fp4 rtn4.33328.941+23.9 %+10.9 %12
b4 shapeq unsloth164.64830.127+29.0 %+15.5 %959
b4 shapeq marg164.64833.115+41.8 %+27.0 %2 242
b4 shapeq rco3.53.83531.937+36.7 %+22.4 %2 339
b6 shapeq rco5.55.83325.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.

6.14. The cost of the table at decode: "scale-only" vs LUT dequantization

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-135MQwen2.5-0.5B
scale only (no LUT)345.5159.3
scale + shift (no LUT)33.8122.65
LUT of the fitted grid26.0019.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.

7. Discussion

7.1. Why the shape works: high-rate quantization theory vs. equal mass

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.

7.2. Hessian weighting

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.

7.3. Parametrics vs. Lloyd

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.

7.4. Where this plugs in

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.

7.5. Economic framing

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.

7.6. Plugging into the GSQ / RCO pipeline

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.

7.7. A histogram instead of a subsample

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.

7.8. Reproducing RCO: bit allocation over our grid

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).

Configurationbit/weightppl (legacy fit)ppl (hist fit)
uniform 4 bits (our grid, no refit)4.3331.3926.00
RCO allocation 3.5 (our grid)3.8332.2732.27
RCO allocation 4.0 (our grid)4.3329.7429.74
RCO allocation 4.0 + refit-34.3329.16—
uniform 4 bits + refit-34.3325.9226.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.

7.9. Mass-balance ternary quantization: theory, scan, negative result

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.

Armweight NMSEWikiText-2 pplvs base
fp32 base0.000013.05—
nearest level0.200980 3656 158×
share p=0.260.208381 3376 232×
equal thirds (1/3)0.2297229 28617 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.

8. Limitations

9. Conclusions

  1. Grid shape is an independent and cheap quality lever in weight-only quantization. Fitting four parameters per tensor costs 32 B of storage and under a second of CPU time, and yields from −7…−15 % perplexity at 4 bits to orders of magnitude at 3 bits against a uniform grid at equal cost.
  2. The effect reproduces on different architectures and grows as the bit width shrinks; at 8 bits, as the asymptotics predict, it tends to zero.
  3. Equal-mass grids, although intuitively optimal, are 31–331 % worse than uniform ones. The result is consistent with over-concentration relative to Zador's p1/3 level-density law.
  4. Fixed smart grids (NF4, FP4 E2M1) lose to per-tensor fitting: one shape for all tensors carries a constant quality tax.
  5. Shape and GPTQ compensation add up; Lloyd refit amplifies the shape at low bit widths.
  6. The fitted shape justifies the LUT decode: dropping the table in favor of "scale only" at 4 bits costs ×8…×13 perplexity, and at 3 bits the model is not saved at all (×553). The compromise with a group shift (Q4_1-style) costs +17…+30 % perplexity (Section 6.14).
  7. The method is a ready-made stage of a GSQ/RCO pipeline: table fitting before assignment, with no change to the file format or the decoder. With RCO's per-bit allocation the gain does not add up (Section 7.8).
  8. The method is deterministic, needs no training, and changes only the quantization alphabet, so it composes with existing quantizers. The next steps are validation on 7B+ models and broader benchmarks, comparison with AWQ and sparse corrections, and an optimized LUT kernel with a repack-GEMM path.

References

  1. Frantar E., Ashkboos S., Hoefler T., Alistarh D. GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers. ICLR 2023. arXiv:2210.17323.
  2. Lin J., Tang J., Tang H. et al. AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration. MLSys 2024. arXiv:2306.00978.
  3. Dettmers T., Pagnoni A., Holtzman A., Zettlemoyer L. QLoRA: Efficient Finetuning of Quantized LLMs. NeurIPS 2023. arXiv:2305.14314.
  4. Kim S., Hooper C., Gholami A. et al. SqueezeLLM: Dense-and-Sparse Quantization. ICML 2024. arXiv:2306.07629.
  5. Dettmers T., Lewis M., Belkada Y., Zettlemoyer L. LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale. NeurIPS 2022. arXiv:2208.07339.
  6. Dettmers T., Svirschevski R., Egiazarian V. et al. SpQR: A Sparse-Quantized Representation for Near-Lossless LLM Weight Compression. ICLR 2024. arXiv:2306.03078.
  7. Chee J., Cai Y., Kuleshov V., De Sa C. QuIP: 2-Bit Quantization of Large Language Models With Guarantees. NeurIPS 2023. arXiv:2307.13304.
  8. Lloyd S. P. Least Squares Quantization in PCM. IEEE Trans. Inf. Theory, 1982, v. 28, n. 2 (reprint of the 1957 Harvard doctoral dissertation).
  9. Max J. Quantizing for Minimum Distortion. IRE Trans. Inf. Theory, 1960, v. 6, n. 1, p. 7–8.
  10. Kumaraswamy P. A generalized probability density function for double-bounded random processes. Journal of Hydrology, 1980, v. 46, n. 1–2, p. 79–88.
  11. Merity S., Xiong C., Bradbury J., Socher R. Pointer Sentinel Mixture Models. ICLR 2017. arXiv:1609.07843.
  12. Yang A., Yang B., Zhang B. et al. Qwen2.5 Technical Report. arXiv:2412.15115 (2024).
  13. Allal L.-B., Lozhkov A., Tunstall L. et al. SmolLM — blazingly fast and remarkably powerful. Hugging Face blog, Jul 16, 2024 (model HuggingFaceTB/SmolLM-135M).
  14. Rouhani B. D., Nasr M., Lou A. et al. Microscaling Data Formats for Deep Learning (MXFP8/MXFP4). arXiv:2310.10537 (2023).
  15. Gerganov G., llama.cpp contributors. llama.cpp: the GGUF format and the K-quant / IQ4_NL quantization schemes. Open source, github.com/ggml-org/llama.cpp, 2023–2025.
  16. Gersho A. Asymptotically Optimal Block Quantization. IEEE Trans. Inf. Theory, 1979, v. IT-25, n. 4, p. 373–380.
  17. Helcig F., Alistarh E. Model Compression with Exact Budget Constraints via Riemannian Manifolds. arXiv:2605.00649 (2026). Implementation IST-DASLab/RCO.
  18. Yvinec O., Dapogny P., Bailly B. Designing strong baselines for ternary neural network quantization through support and mass equalization. arXiv:2306.17442 (2023).

Appendix A. Reproducibility

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.