13.2 Quantization Methods
An 8-billion-weight checkpoint stored at four bits has a 4 GB raw weight payload. That does not mean the complete model serves requests in 4 GB of memory. Scales, unquantized tensors, activations and the KV cache still need space. Nor do two four-bit checkpoints necessarily produce the same answers: the placement of rounding error matters as much as its size.
This section follows two questions: which errors matter for the layer’s output, and what representation can the runtime actually execute? GPTQ and AWQ answer the first through calibration; a format such as GGUF describes how tensors and metadata are stored. These are different parts of a deployment.
1. GPTQ: Compensate for Layer-Output Error
The GPTQ paper reports compressing its evaluated 175B models to three or four bits in a few GPU hours with small perplexity changes [1]. That result is scoped to its models, calibration, quantizers and evaluations. It does not establish a universal safe bit width.
What the Hessian Measures
Let be a linear layer’s weights and contain calibration input vectors as columns. GPTQ approximately solves a quantization-constrained layer reconstruction problem:
Here is the allowed quantized representation and is the Frobenius norm. is the Hessian of one output row’s reconstruction loss with respect to its weights. It captures input-feature interactions through uncentered second moments; no mean subtraction is implied. It is not the full model’s language-model-loss Hessian.
Rounding one weight changes the layer’s output. GPTQ uses the remaining unquantized weights to compensate for that change on the calibration inputs. Rows share this input second-moment matrix, allowing column-wise processing across rows. Correlated inputs permit compensation; diagonal provides no cross-feature correction. Damping stabilizes nearly singular estimates.
A Small Compensation Loop
Deliberately simplified single-layer implementation. CPU FP32 with shaped
[out_features, in_features]and shaped[in_features, in_features]. It omits calibration-data preparation, group-scale search, activation ordering, bit packing, fused kernels, distributed execution and model-level quality gates. The output remains a dense FP32 tensor, so this example does not compress its storage.
import torch
@torch.no_grad()
def gptq_core_loop(W, H, bits=4, damping=0.01):
"""Educational FP32, per-output-row symmetric quantization; no packing."""
if W.ndim != 2 or H.shape != (W.shape[1], W.shape[1]):
raise ValueError("incompatible W/H shapes")
if not 2 <= bits <= 8 or damping <= 0:
raise ValueError("invalid quantization settings")
work = W.detach().float().clone()
hessian = H.detach().to(device=W.device, dtype=torch.float32).clone()
ridge = damping * hessian.diag().mean().clamp_min(1e-6)
hessian.diagonal().add_(ridge)
# U.T @ U = inverse(H); not the unchanged raw inverse Hessian.
chol = torch.linalg.cholesky(hessian)
inverse = torch.cholesky_inverse(chol)
U = torch.linalg.cholesky(inverse, upper=True)
qmax = 2 ** (bits - 1) - 1
scales = (work.abs().amax(dim=1) / qmax).clamp_min(1e-8)
quantized = torch.zeros_like(work)
for i in range(work.shape[1]):
column = work[:, i]
q = (column / scales).round().clamp(-qmax, qmax) * scales
quantized[:, i] = q
error = (column - q) / U[i, i]
work[:, i+1:] -= error[:, None] * U[i, i+1:][None, :]
return quantized
torch.manual_seed(7)
W = torch.randn(16, 32)
X = torch.randn(32, 64) # calibration features x samples
H = 2 * X @ X.T / X.shape[1]
W_q = gptq_core_loop(W, H)
print("Calibration reconstruction MSE:", ((W - W_q) @ X).square().mean().item())
The example measures reconstruction on the same data used to construct . Also measure a separate held-out calibration slice before trusting the choice. A smaller layer error need not preserve generation, tool formatting or rare-domain behavior. Keep evaluation examples and their semantic neighbors out of calibration.
2. AWQ: Protect Sensitive Channels by Rescaling
AWQ studies activation-dependent sensitivity and searches channel scales before weight quantization [2]. Its observation about protecting a small fraction of salient weights, including a 1% example, is an empirical finding for the studied settings. It is not a statement that every model has the same fixed set of indispensable weights.
Why Weight Error Alone Can Mislead
Consider one output with weights and input . The exact output is . With a symmetric four-bit grid whose positive maximum is 7 and whose scale is , the rounded weights are and the output is about . A weight error of only becomes an output error of about because it multiplies an input of 100. This is an authored two-feature example, not a model benchmark.
Activation statistics help identify such sensitivity. They are a proxy tied to the calibration distribution, not a complete measure of a weight’s causal importance.
What Reciprocal Scaling Preserves
Let be a positive vector of input-channel scales and the diagonal matrix containing it. Before rounding,
After quantizing the scaled weights with quantizer , the actual output error is
Scaling changes the rounding grid and the activation multiplier. A shared quantization group also couples neighboring weights: increasing one channel’s range may reduce precision elsewhere. AWQ searches scales to manage that trade-off. The reciprocal identity does not make the quantized output identical to the original.
Deliberately simplified scaling example. CPU FP32; the code verifies only the unquantized reciprocal identity. It omits AWQ’s scale search and clipping, quantization itself, scale folding into neighboring operators, bit packing, runtime kernels and held-out quality evaluation.
import torch
@torch.no_grad()
def awq_scale_weights(W, X, s_x=0.5):
"""Illustrate reciprocal channel scaling, not the AWQ scale search."""
if W.ndim != 2 or X.ndim != 3 or W.shape[1] != X.shape[-1]:
raise ValueError("incompatible calibration shape")
if not 0 <= s_x <= 1:
raise ValueError("s_x must be in [0,1]")
magnitudes = X.float().abs().mean(dim=(0, 1)).clamp_min(1e-6)
scales = magnitudes.pow(s_x)
scales = scales / torch.sqrt(scales.max() * scales.min())
return W.float() * scales[None, :], scales
W = torch.randn(16, 32)
X = torch.randn(2, 8, 32)
X[..., 0] = 0 # inactive channels must not cause division by zero
scaled_W, scales = awq_scale_weights(W, X)
assert torch.allclose(X @ W.T, (X / scales) @ scaled_W.T, atol=1e-5)
AWQ and GPTQ spend calibration effort on different operations. Compare implementations with the same checkpoint, calibration set, quantization configuration and target runtime. Neither method’s name guarantees a speed or quality ranking.
3. TurboQuant: Rotation and Residual Correction
TurboQuant studies online vector quantization for mean-squared and inner-product error. It uses scalar quantization optimized for the rotated distribution and a QJL residual correction for inner-product estimation. A Hadamard rotation followed by uniform rounding is not the complete algorithm [3].
Orthogonal rotation preserves inner products before quantization, not after introducing quantization error. Reported KV quality concerns the tested models and tasks. Concurrency depends on weights, KV, temporary buffers, metadata and kernel costs together; bit width alone cannot establish a doubling. Section 13.5 develops these distinctions.
4. GGUF: Inspect the Stored Tensors
GGUF is a container for tensors and metadata, not a single quantization algorithm [5]. Block size, scales, offsets and code representation depend on tensor type; not every block stores a zero-point.
As of 2026-11-18, the official specification describes typed tensor data and key-value metadata. Separate a block format from a converter’s mixed-tensor policy. A label such as Q4_K_M does not specify every layer’s precision. Inspect actual tensor types and sizes, record the converter commit/configuration and weight hashes, and validate quality and performance on the intended backend.
5. FP8 and Integer Grids
Uniform integer quantization gives equally spaced reconstructed values within one scale. Floating-point formats use exponent and fraction fields, with spacing that changes with magnitude. Neither description implies that every LLM tensor follows a Gaussian distribution, or that one representation always gives smaller error.
The 2022 FP8 proposal defines E4M3 and E5M2 [4]. E4M3 has more fraction bits and less range than E5M2. The paper uses these different trade-offs for forward tensors and gradients in its training schemes; exact format variants, scaling recipes and kernel support must be checked for the chosen implementation. E5M2’s IEEE-style special values do not make the proposal an “IEEE FP8 standard.”
FP8 still has finite range. Scaling, clipping, overflow, accumulation precision and the input distribution affect error. Replacing a 16-bit tensor with 8-bit storage halves that tensor’s raw payload; it need not halve total VRAM or execution time.
6. Count Metadata and Runtime State Separately
For weights at bits, ideal payload is bytes. Suppose a hypothetical format stores all 8 billion weights at four bits and one FP16 scale per 128 weights. There are 62.5 million groups, so the scales add 125 MB. Total weight-plus-scale storage is 4.125 GB, before headers, padding, unquantized tensors or runtime state.
The arithmetic below assumes one uninterrupted group sequence; real formats may start groups independently in every row or tensor. It is not a GGUF size predictor.
parameters = 8_000_000_000
bits, group_size, scale_bytes = 4, 128, 2
weight_bytes = parameters * bits // 8
groups = (parameters + group_size - 1) // group_size
metadata_bytes = groups * scale_bytes
assert weight_bytes == 4_000_000_000
assert metadata_bytes == 125_000_000
print((weight_bytes + metadata_bytes) / 1e9) # 4.125 decimal GB
If that format also stores a two-byte zero-point per group, it adds another 125 MB. This overhead changes when the group size or metadata type changes. Separately budget KV/recurrent state, activations, workspaces and allocator reserve for the intended batch and context length. A W4A16 label describes weight/activation precision; it does not determine KV precision or the treatment of every operator.
Before switching a deployed artifact, preserve the base checkpoint, tokenizer/template, calibration manifest, converter/runtime versions and hashes. Compare domain and base-capability retention, safety, format/tool correctness, peak memory and latency on held-out slices. Reject or roll back when a predeclared quality or service-level gate fails; a smaller file alone is not a release gate.
7. Explore Range and Output Error
Which weight changes the output more, or ? Start with three bits and a symmetric range of . The seven integer codes run from to , so the grid spacing is . Dividing by the spacing gives . At an exact midpoint, round to the even code as in PyTorch: . The reconstructed weight is . [6]
In the row with input , this rounding changes the output by . The weight clips to , but its input is only , so its contribution is . Across all five rows the original output is and the quantized output is about . Try widening the range to and see which weights now round to zero.
All five weights share a uniform grid, and the inputs x stay fixed. As you change the range, the last column shows how much rounding and clipping in each row change the output.
| w | x | Code | Q(w) | (Q(w)−w)x |
|---|---|---|---|---|
| 0.12 | 1 | 1 | 0.167 | 0.047 |
| -0.25 | 8 | -2 | -0.333 | -0.667 |
| 0.08 | 1 | 0 | 0.000 | -0.080 |
| 4.85 | 0.1 | 3 | 0.500 | -0.435 |
| -0.15 | 2 | -1 | -0.167 | -0.033 |
Grid spacing 0.1667 · Original output -1.615 · Quantized output -2.783
Quizzes
Quiz 1: In the two-feature example, why does a small weight error cause a large output error?
The error is multiplied by the corresponding activation: . Activation statistics can reveal this sensitivity, but calibration values do not prove universal importance on every future input.
Quiz 2: Does GPTQ minimize the full model’s language-model loss directly?
No. Its local objective reconstructs a linear layer’s outputs on calibration inputs, using their second moments to compensate rounding error. Better local reconstruction does not guarantee that all downstream capabilities are preserved; held-out model-level evaluation remains necessary.
Quiz 3: Why can a four-bit checkpoint exceed half a byte per parameter?
Scales, zero-points, packing and mixed-precision tensors add storage. In the hypothetical 128-weight groups, one FP16 scale adds bytes per weight, before other costs. The runtime also needs activations, KV state and workspaces.
Quiz 4: Does the reciprocal scaling identity guarantee identical outputs after AWQ quantization?
No. The identity applies before rounding. Quantization leaves , which depends on the scale search, group grid and inputs. Another channel in the same group can also lose precision.
Quiz 5: How do per-tensor and per-token symmetric INT8 scales differ?
For with tokens and channels, choose the symmetric code range . Then , while uses a separate row scale. Use a positive fallback for an all-zero row. Per-token scaling avoids letting one row’s range set every other row’s grid, but it adds scale work/metadata and does not guarantee better end-to-end task accuracy.
References
- Frantar, E., Ashkboos, S., Hoefler, T., & Alistarh, D. (2022). GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers. arXiv:2210.17323.
- Lin, J., Tang, J., Tang, H., et al. (2023). AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration. arXiv:2306.00978.
- Zandieh, A., et al. (2025). TurboQuant: Online Vector Quantization with Near-optimal Distortion Rate. arXiv:2504.19874.
- Micikevicius, P., Stosic, D., Burgess, N., Cornea, M., Dubey, P., … & Wu, H. (2022). FP8 Formats for Deep Learning. arXiv:2209.05433.
- ggml contributors. GGUF specification. Official specification.
- PyTorch.
torch.round, midpoint rounding in PyTorch 2.15.