← Inference From First Principles

Quantization and Numerical Precision

Four different things are called quantisation quality: storage, reconstruction error, model behaviour and speed. Measured separately on GPT-2, they disagree.

GPT-2 uses the same 38.6-million-weight table twice: once to look up input tokens, and once to turn the final hidden state into vocabulary scores. I applied the same four-bit rounding (group-128 fake quantisation) to that table in each role separately, on a 12-window test:

Where the table was quantised Perplexity (baseline 60.6)
Input lookup only 61.0 (about +0.7%)
Output projection only 8,123 (about 134 times the baseline)

Same table, same rounding, same reconstruction error (about 12.7% relative). The effect differed by more than two orders of magnitude, depending only on where the table was used. (A simulated quantiser, one GPT-2 checkpoint, one text sample: not a universal property of embeddings.)

So a claim like “quantisation loses one per cent” is meaningless without saying which scheme, which model and evaluation and which metric. This chapter keeps four questions strictly apart:

  1. Storage: how many bits does the representation need?
  2. Reconstruction: how far are the rounded weights from the originals?
  3. Behaviour: how do the model’s predictions change?
  4. Speed: does a particular kernel on a particular device actually get faster?

An answer to one is never an answer to another. Here, briefly, is what the chapter finds under each heading, all on one GPT-2 checkpoint and one local text:

  • Behaviour. Per-channel eight-bit weight-only fake quantisation of GPT-2’s 48 projection matrices changed perplexity by −0.13%. (No test of statistical equivalence was run.) A single eight-bit scale per tensor increased it by 11.2%. Simple group-wise four-bit rounding raised it by 8.5–13.3%, with much lower agreement on the top next token.
  • Speed. Converting stored int8 or packed int4 weights back to fp16 inside every matrix product was up to about 26 times slower than a plain fp16 product. That is evidence against that execution path, not evidence that low-bit inference is inherently slow.

Where this sits

Matrix Multiplication and GPU Execution found that fp16 roughly halved the time of a memory-limited output projection. Memory Bandwidth and Compute Bottlenecks explained the condition: time improves when the execution path actually moves fewer bytes. Quantisation tests both sides of that trade.

Two earlier observations matter here. The Transformer as a Computation found unusually large GPT-2 activations, and Tokens, Embeddings and Probability showed that GPT-2’s logits share a large negative offset. A shared offset cancels in the softmax; differences between vocabulary scores do not. So rather than assume that small weight error means small output error, we test it.

The Inference Lab gains a quantisation workbench: quantize_dequantize, integer packing helpers, activation fake quantisation, a storage estimator, a model evaluator and separate speed probes. It does not yet export a loadable low-bit checkpoint, implement a fused low-bit kernel, or record quantisation settings in the Building Our First Inference Engine manifest. Those remain obligations; the end of the chapter lists what they require.

For the Pi series, this is where “will it fit locally?” becomes a quantitative question. A storage estimate is the first filter. Actual memory use, activation and KV-cache growth, kernel support, accuracy and throughput all still have to be measured.

Formats and what they can represent

Formats and what they can represent

A floating-point format trades range (set mostly by exponent bits) against precision (set mostly by significand bits). From torch.finfo in the recorded environment:

Format Bits Largest value Smallest normal Relative step (epsilon)
fp32 32 \(3.4 \times 10^{38}\) \(1.2 \times 10^{-38}\) \(1.2 \times 10^{-7}\)
fp16 16 65,504 \(6.1 \times 10^{-5}\) \(9.8 \times 10^{-4}\)
bf16 16 \(3.4 \times 10^{38}\) \(1.2 \times 10^{-38}\) \(7.8 \times 10^{-3}\)
fp8 (e4m3) 8 448 0.0156 0.125
fp8 (e5m2) 8 57,344 \(6.1 \times 10^{-5}\) 0.25

(Epsilon is the spacing just above 1, not a guaranteed relative error everywhere. The fp8 rows describe formats only; no fp8 GPT-2 run was done.)

The two 16-bit formats compromise differently. bf16 keeps almost fp32’s range but has only seven fraction bits; fp16 has ten fraction bits but a much smaller range. A cast probe makes this concrete:

Value fp16 bf16
70,000 inf (out of range) 70,144
2,956 exactly 2,956 rounded to 2,960
\(10^{-9}\) 0 (underflow) a nonzero approximation

So range, rounding and underflow can affect different parts of a computation differently.

The largest residual value from The Transformer as a Computation, 2,956, fits within fp16’s range. That does not prove every intermediate in this GPT-2 implementation is safe from overflow, or that fp16 is generally the better choice: accumulation dtype, reductions, kernels and the real activation distribution all matter. In the evaluation below, fp16 happens to preserve GPT-2’s perplexity more closely than bf16. For other models, bf16’s range may matter more.

Integer quantisation

Integer quantisation stores each number as a small integer code plus a scale that maps the code back to a real value. The scheme used here is symmetric, signed and round-to-nearest. For a group of values \(x\) and \(b\) bits:

\[ s = \frac{\max|x|}{2^{b-1}-1}, \qquad q = \operatorname{round}(x/s), \qquad \hat{x} = q\,s \]
A worked example: with \(b=8\), codes run from −127 to 127. If the largest absolute value in a group is 1.27, the scale is 0.01 and every value is rounded to the nearest hundredth. Each value is then off by at most half a step, 0.005 (ignoring floating-point error in the scale, and assuming no clipping).

The catch is the maximum. The scale is set by the largest value in the group. If one outlier is 186, the step becomes about 1.46, and ordinary values near 1 are rounded to 0 or ±1.46. One outlier coarsens every other value in its group. (The half-step bound also says nothing about how those errors add up after matrix multiplication.)

Granularity: who shares a scale?

GPT-2’s Conv1D weights are stored as [input, output]. The workbench can share one scale across:

  • the whole matrix (group=0, “per tensor”);
  • each output column (group=-1, “per channel”);
  • blocks of \(g\) input coordinates within each output column (group=g).

Smaller groups limit the damage an outlier can do, but every group needs its own scale. With a 16-bit scale per group:

\[ \text{bits per weight} = b + \frac{16}{g} \]
So four-bit weights in groups of 128 cost \(4+16/128=4.125\) bits per weight nominally; in groups of 32, 4.5 bits. The asymmetric option adds a zero point, counted at \(b/g\) bits per weight.

These are packing estimates. They exclude headers, padding, alignment and serialisation metadata. More importantly, quantize_dequantize returns floating-point weights, so the estimate is not the memory the evaluated model actually occupies.

Reconstruction error

What the weights look like

The weights being quantised. GPT-2 small has 48 Conv1D projection matrices (four per layer), holding 84,934,656 weights, about 68% of its 124.4 million parameters. (Most of the rest is the tied embedding table.) How extreme are their outliers?

Statistic Median over 48 layers Worst
Largest weight over RMS 20.8 186 (layer 3, feed-forward output)
Excess kurtosis (0 for a Gaussian) 3.2 790 (same layer)

The worst peak-to-RMS ratios belong to the MLP output projections of layers 3, 2 and 1: about 186, 162 and 158. So in some matrices a single maximum is a very poor stand-in for the typical weight. Not every matrix is like that, and the Gaussian comparison is only a heuristic. But it is reason to try finer scales.

What the worst matrix does to per-tensor int8. With its maximum at 186 times the RMS, the int8 step is about \(186/127\approx1.46\) times the RMS. Many ordinary weights collapse towards zero.

Measuring reconstruction. The table reports relative Frobenius error, \(\|\hat W-W\|_F/\|W\|_F\): the size of the whole error matrix as a fraction of the size of the weight matrix. (It is not the fraction of weights that changed, nor an accuracy measure.)

Scheme Bits per weight Median error Worst layer
int8, per tensor 8.00 0.047 0.421
int8, per channel 8.01 0.0089 0.020
int8, group 128 8.13 0.0068 0.0097
int4, per channel 4.01 0.160 0.279
int4, group 128 4.13 0.124 0.148
int4, group 64 4.25 0.110 0.128
int4, group 32 4.50 0.099 0.109
int4, group 128, asymmetric 4.16 0.104 0.119
int3, group 128 3.13 0.287 0.324
int2, group 128 2.13 0.771 0.792

What it shows.

  • Granularity changed the worst-layer error most at eight bits (0.421 to 0.020). One scale per tensor gives a worst-layer error of 0.421 (the error’s norm is 42% of the weight matrix’s norm; not “42% of weights discarded”). Per-channel scales cut the worst case to 0.020, and group-128 further still.
  • At four bits, smaller groups help, at a price. Going from groups of 128 to 32 moves the median error from 0.124 to 0.099 while the nominal cost rises from 4.125 to 4.5 bits per weight.

These numbers are useful for checking the quantiser and understanding outliers. They cannot rank schemes by model quality on their own, as the opening example showed: the same weight error can matter enormously or hardly at all.

Model behaviour

The evaluation. The text of Chapters 6–11, cut into 57 non-overlapping windows of 512 tokens: 29,184 input tokens, of which 29,127 positions are scored (the last token of each window has no successor within it). The full text was 29,288 tokens before truncation. The fp32 reference scores perplexity 62.69. This is a reproducible local comparison on technical prose, not a standard benchmark. (Activation-smoothing calibration below used a separate eight-window sample from Chapters 1–5.)

Three metrics, answering different questions:

Metric What it measures What it does not tell you
Perplexity How well the model predicts the actual next token in this text (\(\exp\) of the mean negative log-probability; lower is better) Whether outputs match the original model
Top-1 agreement How often the altered model’s top next token matches the fp32 reference’s, with the true text fed in at every position Whether freely generated text would match; one different token changes everything after it
KL divergence Mean \(D_{\mathrm{KL}}(p_{\mathrm{fp32}}\|p_{\mathrm{altered}})\) over the vocabulary, in nats per position: how far the whole distribution drifted Task accuracy

Perplexity measures fit to the text; agreement and KL measure fidelity to the original model. They can disagree, as we’ll see.

What was actually run. For the integer rows, the projection weights were quantised and immediately turned back into floating-point; the forward pass used ordinary floating-point arithmetic, not a low-bit kernel. The fp16 and bf16 rows really ran the model in those dtypes, activations included. So the table pairs measured behaviour with estimated storage, and demonstrates neither a deployable checkpoint at that size nor any speed-up.

Scheme Perplexity Change Top-1 agreement KL (nats) Bits per weight (linear) Whole model*
fp32 (reference) 62.69 – – – 32 475 MiB
fp16 62.70 0.00% 98.3% 0.0002 16 237 MiB
bf16 63.74 +1.67% 87.9% 0.0212 16 237 MiB
int8, per tensor 69.73 +11.2% 78.0% 0.136 8.00 156 MiB
int8, per channel 62.61 −0.13% 97.6% 0.0012 8.02 157 MiB
int8, group 128 62.70 +0.02% 98.5% 0.0005 8.13 158 MiB
int4, per channel 88.34 +40.9% 65.6% 0.343 4.02 116 MiB
int4, group 128 71.05 +13.3% 76.3% 0.145 4.13 117 MiB
int4, group 64 69.79 +11.3% 78.6% 0.115 4.25 118 MiB
int4, group 32 67.99 +8.5% 80.6% 0.090 4.50 121 MiB
int4, group 128, asymmetric 68.67 +9.5% 79.5% 0.105 4.16 117 MiB
int3, group 128 274.65 +338% 34.5% 1.59 3.13 107 MiB
int2, group 128 18,575 collapse 4.4% 6.05 2.13 97 MiB

* For the integer rows, “Whole model” is an estimated packed size, not measured memory or a saved file. It assumes the 48 projection matrices use the stated bits per weight and everything else (the tied embedding and output projection, norms, biases) is fp16. The simulated runs actually kept those other tensors in fp32, and held the dequantised projections in floating point too. The fp32 row is the full checkpoint; the 16-bit rows are nominal parameter sizes. No compressed model was written or loaded.

Read the table one row-group at a time.

fp16: very close, not identical. Perplexity changes by only about 0.004% before rounding, but the top token differs at about 1.7% of positions (98.3% agreement). Near-tied logits are one possible reason; margins were not analysed. That 98.3% is a measured comparison for this model, not a floor or ceiling for any other scheme.

bf16: perplexity and fidelity disagree. Perplexity rises only 1.67%, yet the top token changes at about 12.1% of positions and KL is a hundred times fp16’s. So the distributions really did move. That does not mean 12% of tokens in a generated reply would change, or that a reader would notice; generation traces need a separate comparison.

Per-channel int8: promising, not proven equivalent. Perplexity 62.61 against 62.69 (−0.13%), top-1 agreement 97.6%, KL 0.0012. With no resampling, confidence interval or second text, “statistically indistinguishable” or “free” would overclaim. The nominal packed model would be about 157 MiB against 237 MiB in fp16, but no 157 MiB model was actually run. And the contrast with per-tensor int8 (+11.2%) shows how much granularity matters with the same eight bits.

Simple int4: granularity again. Groups of 128, 64 and 32 raised perplexity by 13.3%, 11.3% and 8.5%; per-channel int4 was far worse at +40.9%. Top-token disagreement ranges from about 19% to 34% across these four schemes. The asymmetric group-128 variant beat the symmetric one at small extra cost. All of this is plain round-to-nearest. Methods such as GPTQ and AWQ use information about the model’s behaviour to choose rounding or protect important weights; their published results say nothing about what they would recover on this particular GPT-2 run.

Below four bits, these schemes collapse. Group-128 int3 raised perplexity by 338%; int2 reached 18,575, with the top token matching only 4.4% of the time. That shows these simple schemes fail on this model and text, not that three- or two-bit inference is impossible. Calibrated rounding, mixed precision and other architectures may change the picture.

The matrix that is used twice

Now back to the opening experiment. GPT-2 ties its token embeddings to its output projection: the same 38.6-million-element table is read as vectors at the input and multiplied by the final hidden state at the output. To separate the two roles, the experiment gave the input lookup and output projection separate copies, deliberately breaking the tie for analysis.

On a 12-window subset of the text (baseline perplexity 60.613):

Where int4 (group 128) is applied Perplexity (baseline 60.6)
Input lookup only 61.0 (+0.7%)
Output projection only 8,123
Both (tied) 7,983
Both, int8 per channel 64.7 (+6.7%)
Both, int8 group 128 61.9 (+2.1%)

(Quantising both roles on the full 57-window evaluation gave 7,862. That is a different evaluation with a different baseline, not a contradiction.)

So in this model, the output projection is extraordinarily sensitive to this four-bit rounding, and the input lookup barely notices it. That does not show that quantising input embeddings is always safe, or that every model’s output projection needs high precision.

Why might the output side be so sensitive? A diagnostic using 64 final hidden states from one window:

Value
Spread of exact logits across the vocabulary (std) 3.43
Error std across the vocabulary, int8 group 128 0.24
Error std, int4 group 128 4.74
Error std, int4 per channel 5.25
Mean logit −123.9
Hidden-state norm / embedding-row norm 264 / 4.0

The exact logits vary across the vocabulary with a standard deviation of 3.43. Group-128 int4 adds errors with a standard deviation of 4.74: larger than the spread of the scores themselves. A shared shift would cancel in the softmax, but the mean shift here was only about 0.08; the damage is in token-to-token differences.

Why so large? The final hidden states have a norm of about 264, against about 4 for an embedding row, so errors in the table get multiplied by a long vector. That is a plausible mechanism, but norms alone don’t prove it: the actual logit error depends on how the errors line up with the hidden states. The measured error spread and the collapse in perplexity are the evidence; the precise cause is not yet isolated.

A design rule follows, as a hypothesis: protect highly sensitive uses of shared weights, especially output projections, until a per-role test shows lower precision is acceptable. That is why the main table’s storage estimate keeps the tied table at an assumed fp16, and why its int4 whole-model estimate stays near 117 MiB instead of about 70 MiB. (The simulated runs actually kept it at fp32.) A real implementation should test selective quantisation without accidentally breaking the tie.

Quantising activations

Quantising activations: residual stream range

Weight-only quantisation saves weight storage and weight traffic, if a kernel reads the compressed form directly. W8A8 also quantises the activations, which could allow integer matrix products. Here the effect is simulated: activations are rounded and turned back into floating-point before ordinary Conv1D operations, with a scale recomputed for each tensor or each token row. No real integer W8A8 path was run.

Scheme Perplexity Change Top-1 agreement KL
W8A8, activation scale per tensor 85.95 +37.1% 65.2% 0.383
W8A8, activation scale per token 63.00 +0.49% 94.2% 0.0073
W8A8, per tensor, with smoothing (α = 0.5) 79.69 +27.1% 68.1% 0.300

Granularity matters here too. One scale for the whole activation tensor raised perplexity by 37.1%; one scale per token cut that to 0.49%. But per-token top-1 agreement is still only 94.2%, so “nearly free” holds only for perplexity on this text, not for fidelity to the original model.

Why does per-tensor scaling hurt? Calibration over Chapters 1–5 found large differences between channel maxima: at the input to the last MLP output projection, the largest channel maximum was 28.9 times the median. A single scale sized for the largest channel loses detail in the others. Per-token scaling might help by isolating outlier-heavy rows, but where the outliers sit and how much they matter were not tested.

Smoothing. SmoothQuant moves some of the activation range into the weights. For input channel \(j\), divide the activation by \(s_j\) and multiply the matching weight row by \(s_j\), with \(s_j = (\max |X_j|)^\alpha/(\max |W_j|)^{1-\alpha}\). Before rounding, the product is unchanged, mathematically. After rounding, it is not error-free.

The implementation here is only SmoothQuant-inspired: it smooths the attention QKV and MLP-up projections (c_attn, c_fc) with \(\alpha=0.5\), does not fold the division into the preceding layer norm, and does not cover every projection. It improved per-tensor W8A8 from +37.1% to +27.1%, still far worse than per-token scaling. Whether the remaining damage comes from the unsmoothed layers would need a layer-by-layer ablation and an \(\alpha\) search on calibration data.

Speed: does it run faster?

None of the quality results says anything about speed. So: does storing fewer bits make the matrix product faster?

The benchmark. One query row against an output-projection-shaped matrix (\(768\times50{,}257\)), random inputs, on the RTX 2060, timing GPU execution of four implementations. Two of them unpack or dequantise the weights on every call.

How the weights are used Time Stored size of the weights
fp32 weights 512 µs 147 MiB
fp16 weights 269 µs 74 MiB
int8 weights, converted to fp16 on each call 1,610 – 1,621 µs 37 MiB
packed int4 weights, unpacked and converted on each call 5,477 – 6,925 µs 19 MiB

Plain fp16 was fastest. Converting on every call was about 6× slower for int8 and 20–26× slower for int4 than fp16.

Why? Look at what the code does: q8.half() * scale8.half(), or unpack_int4(p4) followed by scaling, builds a whole new fp16 weight matrix before the @ runs. So each call pays for conversion kernels, a large allocation and extra memory traffic, and then does an ordinary fp16 product anyway. (The “stored size” column describes the compressed weights, not that temporary matrix.)

So this table measures a bad execution path, not the speed of int8 or int4 matrix products on compressed weights. A purpose-built fused kernel would read packed weights and dequantise small tiles in registers or shared memory, never building the full fp16 matrix. Whether that is faster depends on instruction support, group layout, occupancy and shape. No fused int4 kernel was benchmarked here, so nothing in this chapter predicts the speed-up from fourfold compression. GPTQ and AWQ report speeds with their own kernels and hardware; those are context, not measurements on this card.

An isolated integer matrix product

A separate microbenchmark uses PyTorch’s private torch._int_mm: int8 activations times int8 weights, accumulating in integers. It is not the same operation as the fp16 reference: the int8 inputs are independently generated random values, and quantising activations, handling scales and converting results back are all excluded.

Shape fp16 int8 × int8
Output projection (768 × 50,257) 1,150 – 1,178 µs 741 – 747 µs
Feed-forward up (768 × 3,072) 59 – 60 µs 60 – 61 µs
Square (4,096 × 4,096) 284 – 286 µs 289 – 291 µs

At \(M=256\), the wide output-projection shape ran about 1.55× faster in int8 (741–747 µs against 1,150–1,178 µs). The narrower shapes did not improve. (The integer path also padded the width from 50,257 to 50,264 columns.) That is a kernel-only ratio, hinting at a possible hardware advantage for this shape, not a W8A8 model speed-up, and it says nothing about accuracy. torch._int_mm is an internal API with its own compatibility caveats.

The conclusion is conditional. Fewer stored bits only help if the execution path actually reduces its bottleneck. On this RTX 2060, fp16 is a strong baseline, converting on every call is a cautionary failure, and an isolated int8 product suggests an opportunity for one shape. A deployment decision would need a real packed model, a fused kernel that matches the reference, and end-to-end latency and memory measurements on the target device.

Inference Lab increment

The Lab now has:

  • quantize_dequantize(w, bits, group, symmetric): simulates reconstruction and estimates packed bits per weight, including assumed scale and zero-point widths. It does not produce a deployable packed checkpoint.
  • fake_quant_activation, smoothing_scales, pack_int4 and unpack_int4: numerical experiments and an int4 packing round trip. Packing assumes an even first dimension; a real serialiser needs shape, alignment and metadata checks.
  • evaluate(model_q, model_ref, windows): perplexity, teacher-forced top-1 agreement and forward KL on the same fixed windows.
  • formats, weights, quality and speed: runnable experiments with different hardware needs. The tests check the arithmetic helpers, not the GPU quality and performance tables.

What a real quantised artefact must record. This extends the manifest idea from From Training to Execution; the Chapter 12 code does not yet do it. A saved quantised model needs: its parent checkpoint and digest; the quantiser and its version; the numeric format, signedness, scale dtype, zero-point convention, grouping axis and size; exactly which parameters were converted and which protected (including tied embeddings); the packing layout; the calibration data and method; the runtime kernel and accumulation dtype; and the measured quality thresholds. The packed bytes and metadata must be hashed together. Changing any of these can change outputs, or invalidate cached state as described in Key-Value Caching.

The evidence rule: report storage, reconstruction, behaviour and speed separately, and label every result as a packing estimate, a floating-point simulation, an isolated kernel benchmark or an end-to-end deployment measurement. Blurring those stages is the commonest way to turn a promising experiment into an unjustified product claim.

Limits of this chapter’s evidence

About the set-up

  • One GPT-2 checkpoint, one local text. The 57-window evaluation is not a general benchmark; the 12-window embedding diagnostic has its own baseline. Larger or differently trained models were not tested.
  • No statistical testing. One fixed text, no confidence intervals, no held-out domains or task metrics. Small perplexity differences cannot be called either insignificant or equivalent without a defined test.

About what was simulated

  • Integer results are fake quantisation. Weights and activations were reconstructed in floating point; the 97–158 MiB sizes are estimates, not measured or saved model sizes.
  • fp16 and bf16 are full dtype runs, changing activations and kernels as well as stored weights, so they are not a pure weight-only comparison.
  • Smoothing was partial: \(\alpha=0.5\), eight calibration windows, only c_attn and c_fc. Not a SmoothQuant reproduction.

About speed

  • No fused low-bit kernel. The slow int8 and int4 rows dequantise on every call.
  • The int8 product comparison is not like-for-like: independent random inputs, integer accumulation, padded columns, no conversion or rescaling.

Not measured at all: KV-cache quantisation, task accuracy, energy, detailed error attribution and hardware counters.

What you should now be able to do

  • Read the range and precision of fp32, fp16, bf16 and the two fp8 variants, without assuming that a format being available means a kernel supports it.
  • Derive nominal bits per weight including scale and zero-point metadata, and distinguish that estimate from file size and memory use.
  • Explain tensor-, channel- and group-wise quantisation for [input, output] weights, and measure each one’s reconstruction error.
  • Compute perplexity, teacher-forced top-1 agreement and KL on the same positions, and say what none of them tells you about free-running generation.
  • Show why the same weight error can have very different consequences in a tied embedding’s input and output roles.
  • Explain why per-tensor activation scaling failed here, what per-token scaling changed, and which parts of SmoothQuant were not implemented.
  • Separate an isolated int8 kernel timing from a W8A8 model claim, and recognise when on-the-fly dequantisation erases any speed benefit.
  • Specify the metadata, quality gates and kernel-parity tests needed to turn fake quantisation into a real compressed model.

In this chapter’s unfused dequantisation benchmark, the execution path erased the byte saving. Attention has an analogous intermediate-tensor cost, its score matrix. FlashAttention and Optimized Kernels examines kernels that compute the same attention function, up to floating-point differences, without materialising that matrix.

Key terms

  • Quantisation / fake quantisation: mapping real values to a discrete grid; in fake quantisation, reconstructing floating-point values before normal floating-point execution.
  • Scale / zero point: metadata mapping integer codes to real values; its precision and grouping affect reconstruction.
  • Granularity / group size: the tensor, output channel, or input-coordinate block that shares quantisation metadata.
  • Weight-only / W8A8: reducing weight precision alone, or representing both weights and activations in eight bits. The W8A8 result here is numerically simulated, not executed as an integer model.
  • Outlier / calibration: an unusually large value that affects a scale; using representative data to choose scales, smoothing or a quantisation policy.
  • Perplexity / top-1 agreement / KL: reference-text prediction quality; agreement of teacher-forced most likely next tokens; drift in full next-token distributions.
  • Fused dequantisation / packing: direct consumption of packed low-bit weights by an execution kernel, rather than reconstructing a whole floating-point matrix first.
  • Tied embedding: one parameter table serving both input lookup and output projection, whose two uses can have different sensitivity to quantisation.

Reader exercises

  1. Repeat the group-size sweep and graph perplexity and nominal packed bits per weight on the same axes or table. Is reconstruction error alone a reliable selection criterion?
  2. Repeat the 12-window tied-embedding ablation with output-side group-32 and group-64 int4; record top-1 agreement and logit-error standard deviation as well as perplexity.
  3. Change only one projection layer at a time and rank per-layer output sensitivity; compare that ranking with the layers’ Frobenius reconstruction errors.
  4. Expand the W8A8 smoothing experiment to all four projection types in simulation. Then run an \(\alpha\) search only on calibration text and evaluate the chosen value on held-out text once.
  5. Re-run fp16, bf16 and selected int8 schemes on a second corpus and report paired per-window perplexity changes and uncertainty; do not call a difference noise without testing it.
  6. Save and reload a genuinely packed int4 checkpoint with scales, zero points and layout. Verify its byte size, hash, round-trip weight reconstruction and tied-parameter behaviour.
  7. Implement or use a fused weight-only kernel; compare it with the unfused conversion path on the same inputs, separating packing, memory, execution and decoding time.
  8. Quantise the same fp16 activations for an int8 GEMM, rescale its int32 output, and check maximum logit error and end-to-end TTFT/TPOT versus fp16.
  9. Test a context-length and batch-size sweep, including KV-cache residency, before claiming the quantised model fits or runs faster in a serving workload.

References

Evidence in this chapter

Claim Evidence category and limit
Floating-point ranges/epsilon and the symmetric quantisation formula Format documentation and stated arithmetic assumptions; no fp8 execution result
48 projection matrices and their heavy-tailed weight statistics Recorded GPT-2 weight analysis; not the distribution of all parameters
Per-tensor versus per-channel/group weight reconstruction Recorded relative Frobenius errors; not task accuracy
fp32 perplexity 62.69 and all quantisation-quality rows One checkpoint, 57 windows, 29,127 scored positions; teacher-forced perplexity, agreement and KL
fp16 and bf16 model dtype effects Model dtype comparisons including activations, not weight-only fake quantisation
Integer-scheme memory numbers (approximately 97–158 MiB) Hypothetical packed parameter estimates; not measured saved/resident memory
Per-channel int8 perplexity difference of −0.13% Local observation; no significance or equivalence test
Int4 input-only vs output-only tied-embedding results Book experiment on 12 windows; 61.0 versus 8,123; not a general rule for every LM head
Hidden-state norm contributes to output sensitivity Hypothesis; logit-error variance observed, causal role not isolated
W8A8 per-tensor, per-token and partial smoothing quality Fake-quantised model results; no end-to-end integer W8A8 execution
Unfused int8/int4 conversion slows GEMM up to 6×/26× Book microbenchmark of unfused conversion on RTX 2060, not fused low-bit hardware throughput
_int_mm output-projection timing ~1.55× versus fp16 Isolated, non-equivalent-input integer GEMM with padded width; excludes conversion and rescaling
GPTQ, AWQ, full SmoothQuant, real packed checkpoint, KV quantisation, task quality, fused int4 speed Not evaluated or implemented in this chapter