unitstride
Quantization through the lens of inference acceleration · Part 1 · unitstride

Quantization Basics

Published Oct 22, 2026

While optimizing DeepSeek V4.1 Flash recently, I ran into a case where FP8 GEMM on Hopper was much slower than BF16. Digging into it sent me back over the fundamentals of quantization, and this article is the write-up.

It does not cover the analysis of that DSV4.1 Flash FP8 GEMM issue. It is an introduction to the basics of quantization from an infra perspective.

1Why quantize for inference

Quantization means storing and computing numbers with fewer bits, for example replacing BF16 / FP32 with FP8, FP4, or even a single bit.

This works because large models do not need all the precision BF16 provides. One study ran more than 500,000 evaluations across the Llama-3.1 family (8B, 70B, 405B) and found that FP8 weights and activations (W8A8) cause essentially no accuracy loss. Some teams go further and train in FP8: DeepSeek V4.1 Flash runs its matmuls in FP8 during training, so the model is adapted to that precision from the start. In the technical report, controlled experiments on two validation models (16B and 230B) show the relative loss gap between FP8 and BF16 training stays within 0.25%.

More aggressive approaches push each weight down to 1–2 bits. Microsoft's BitNet restricts weights to two values, −1 and +1; the later BitNet b1.58 uses three values, −1, 0 and +1, about 1.58 bits per weight, and was used to train an open 2B-parameter model from scratch. These models are all trained in low precision from the start; compressing an already-trained BF16 model straight to 1–2 bits usually costs noticeable accuracy. This article covers only the most common step: BF16 → FP8.

At inference time, GPU memory holds the weights and the KV cache, and every decode step has to move the weights to the Tensor Cores for matrix multiplication. Quantization therefore saves three resources: memory capacity, memory bandwidth and compute. Taking BF16 → 8-bit as an example, each number takes half the bytes, and each of the three savings pays off in a different scenario:

BF16: 2 bytes per weightHBM · capacityWeightsKV cacheBandwidth8 blocks per step, 2 units eachChip · computeTensor Core989TFLOPSOutputFP8: 1 byte per weightHBM · capacityWeightsKV cacheBandwidthSame 8 blocks, half the size: fasterChip · computeTensor Core1979TFLOPSOutputWeights free up room for KV cacheMore concurrency → more throughputdecode was bandwidth-bound→ now moves far less dataBottleneck eased → faster decodeprefill was compute-bound→ FP8 = 2× BF16 FLOPS→ faster prefill
Schematic · Proportions of memory usage and block sizes are illustrative; bandwidth (channel width) is the same in both rows (assuming everything else is unchanged and only the weight bytes are halved). Compute figures are from the NVIDIA H100 SXM spec page: BF16 989 / FP8 1979 TFLOPS (dense, without sparsity)

2How numbers are stored in memory

Sign / exponent / mantissa

A floating-point number has three parts:

FP321 + 8 + 23Range ±3.4e38BF161 + 8 + 7Range = FP32FP161 + 5 + 10Range ±65504FP8 E4M31 + 4 + 3Range ±448SignExponent (range)Mantissa (precision)
Schematic · each small cell is 1 bit; cell counts follow the actual bit widths of each format

FP8 E4M3 has only 4 exponent bits and 3 mantissa bits, so both range and precision are tight:

Going from 16 bits to 8 saves capacity and bandwidth. The price is that each number keeps only 3 mantissa bits, with 254 finite values in total. The next section looks at what happens when high-precision numbers are converted into these formats.

3From high precision to low, and back again

The obvious approach: just round

The first idea for going from high to low precision is to round directly. Take FP32 → BF16: BF16 has the same 8-bit exponent as FP32, so the range is identical; only the mantissa shrinks from 23 bits to 7. Rounding directly is therefore fine for FP32 → BF16. You lose precision, but nothing goes out of range. Let's walk through it with 0.0137.

FP32 stores 0.0137 as 1 sign + 8 exponent + 23 mantissa bitsFP32SignExponent: 8 bitsMantissa: 23 bits00111100011000000111010111110111Low 16 mantissa bits: droppedLess than half of the last kept bit, so no round-upFP32 = 0.01370000001
Schematic · actual FP32 / BF16 bits; conversion uses round-to-nearest-even. The low 16 bits dropped from 0.0137 are less than half, so rounding gives the same result as truncation

Another example: 3.14159 becomes 3.140625 in BF16, a relative error of about 0.03%. With 7 mantissa bits, BF16's maximum relative rounding error is within 2-8 ≈ 0.39%, which is usually acceptable for inference.

FP16 needs more care: it has only 5 exponent bits, a maximum of 65504, and a smallest normal number of about 6.1 × 10-5. Weights generally fall within this range and can be converted directly, but activations or intermediate results occasionally fall outside it: large values overflow to inf, small ones underflow. This is often cited as one reason large-model training favors BF16.

Why this intuition breaks down for FP8

Weights and activations in large models are mostly concentrated near 0, with very small magnitudes. Let's look at a set of illustrative small-magnitude data: 100,000 numbers drawn from a normal distribution with mean 0 and standard deviation 0.002. We already saw the error of converting directly to BF16; the trouble is converting directly to FP8.

Cast directly to FP8: values crowd the center, ticks on both sides go unused① No scale: cast directly to FP8Wasted: not a single tick on this side is usedWasted: not a single tick on this side is used−448−2560256448Zoom ±0.0095: all subnormal (red), 9 ticks−0.008−0.00400.0040.008Median rel. error 45.1%, 37.5% → 0, 9 values left② ÷ scale first (scale = absmax ÷ 448), then cast−448−2560256448Median rel. error 2.2%, 0.001% → 0, 231 values used
Schematic · illustrative distribution N(0, 0.002²), 100,000 numbers, random seed 0; the dots in the animation are 120 samples drawn uniformly from it; error, fraction that become 0, and number of distinct values are computed over all 100,000 numbers; FP8 rounding always uses round-to-nearest on the E4M3 grid

The subnormal range marked in red is the stretch below FP8's smallest normal number, 2-6 ≈ 0.0156. Here the exponent bits are all 0 and the implicit leading 1 is gone, so the ticks can no longer get denser by halving intervals toward 0. Instead they are evenly spaced at a fixed 2-9 ≈ 0.00195. The smaller the number, the larger this spacing is relative to it, so relative precision gets worse the closer you get to 0.

The problem with direct conversion is that these numbers are packed within ±0.0085 and use almost none of FP8's ticks. If we first scale the whole set up so that the largest value lands exactly on 448 and then convert to FP8, we get to use the entire ruler. That multiplier is the scale: map the high-precision numbers onto the FP8 grid using it, and map them back when they are used. Two questions follow naturally:

How the mapping works: what a quantized number actually stores

Once the scale is applied, the quantized number is no longer the original number. Say the largest absolute value in a group of weights is 0.05; then 0.02 in that group quantizes to 176 (0.02 ÷ (0.05 ÷ 448) ≈ 179.2, rounded to the nearest tick, 176). On its own, 176 means nothing: it is nearly 9,000 times the real value 0.02.

True value00.05 (absmax)0.02Reading0176448Stored176Reading×0.05 ÷ 448scale≈ 0.0196
Schematic · the ruler ticks are the real E4M3 ticks (positive side only; negatives are symmetric); rounding is round-to-nearest

A quantized number records how large a value is relative to the largest value in its group. Think of the scale as the real length that one unit on the ruler represents, and the quantized number as the reading taken with that ruler. Multiply them (x′ = reading × scale) to get back to real units. So a group of quantized numbers consists of two parts:

The steps of quantization: following 4 numbers

Suppose a tensor contains these 4 numbers: 12, 7.25, −8.95, 1.71. Let's follow them through:

  1. Find the largest absolute value (absmax): here it is 12. Use it to set scale = 12 ÷ 448 ≈ 0.0268.
  2. Divide each number by the scale to move it onto the FP8 ruler: 12 → 448, 7.25 → 270.7, −8.95 → −334.1, 1.71 → 63.8.
  3. Round to the nearest tick to get the quantized numbers: FP8 can only represent those discrete tick values, so anything between ticks must be rounded to the closest one.
    • 448 is itself a tick and stays unchanged.
    • 270.7 and −334.1 sit in a range where adjacent ticks are 32 apart; they round to 256 and −320, a noticeable shift.
    • 63.8 is very close to the tick at 64 and barely moves.
  4. When the values are used, multiply back by the scale to get x′: 12, 6.857, −8.571, 1.714. Compared with the originals, the errors are 0%, 5.4%, 4.2% and 0.25%.

The figure below walks through these four steps. In the last step, dashed lines project the original values onto the output ruler, so you can see the difference directly.

Start: all 4 values sit on the input ruler and will go through each step in turn.1x = 122x = 7.253x = 1.714x = -8.95① Input values (linear axis)-12-60612absmax = 12 (largest magnitude)② ÷ scale  scale = absmax ÷ 448 = 12 ÷ 448 ≈ 0.02679③ FP8 ruler (linear axis −448…448, real E4M3 ticks, symmetric)-448-2560256448④ Round to the nearest tick⑤ × scale  x′ = reading × scale (back to the original units)⑥ Output (same scale as ①; hollow circle = original value)-12-60612
Schematic · 4 toy numbers; the FP8 ruler shows the real E4M3 ticks (symmetric around 0); rounding is round-to-nearest

The error comes from the rounding step: the distance a value moves when snapped to a tick, multiplied back by the scale, is the final error. Where ticks are sparse (large magnitudes), values move more; where ticks are dense, they move less.

absmax ÷ 448 is really one way of mapping the original values onto the FP8 grid, and the simplest one: it guarantees the largest value stays in range and everything else falls proportionally. There are more sophisticated mapping strategies, all aiming to minimize quantization error. They fall roughly into two groups:

For FP8, absmax is usually good enough, because its relative precision is roughly the same everywhere. Sophisticated mapping strategies matter more for formats with very few ticks, such as INT4.

Why FP8 and not INT8

INT8 quantization follows the same steps, except that scale = absmax ÷ 127 and values round to evenly spaced integer ticks (−127…127). Both are 8 bits with 256 encodings; the only difference is how the ticks are laid out. The figure below converts both grids back to original values and plots them on the same horizontal axis; the bottom row shows the values from a real weight matrix.

FP8INT8Weights-0.4-0.200.20.4x = 0.403FP8: abs. error 0.016, rel. 4.0%INT8: abs. error 0.0014, rel. 0.35%FP8INT8Weights-0.01-0.00500.0050.01x = 0.00533FP8: abs. error 0.00021, rel. 3.9%INT8: abs. error 0.0018, rel. 33.3%Zoom ±0.0124: INT8 has only 7 ticks here, yet 54.7% of the matrix falls in this range
Schematic · real tensor: model.layers.12.mlp.down_proj.weight from Qwen/Qwen2.5-0.5B (896 × 4864, 4,358,144 values in total, BF16), absmax = 0.451. Per-tensor scale: FP8 = absmax ÷ 448, INT8 = absmax ÷ 127; dots are 3,000 randomly sampled values, with vertical position only for spreading them out. Error statistics use all elements: FP8 rounds to the nearest E4M3 tick, INT8 rounds to the nearest integer and clamps to ±127; relative error = |dequantized value − original| ÷ |original|, computed over non-zero elements only

The two grids have opposite error patterns:

Values in real tensors are mostly crowded near 0, so FP8 is the better fit. Over all elements of this matrix, the median relative error is 7.2% for INT8 and 2.2% for FP8, and 9.1% of the values become 0 under INT8.

Conversely, if a set of values spans a narrow range with no outliers, INT8's evenly spaced grid (7 magnitude bits) is actually finer than FP8 (3 mantissa bits). FP8's advantage is its large dynamic range; when the data spans a narrow range, it is no more accurate than INT8.

4Granularity: how big a group one scale covers

So far we have said "one scale per group of numbers". That group can be very coarse or very fine. Three choices are common:

A real-world example is DeepSeek-V4.1-Flash: according to its public config and reference code, weights get one scale per 32×32 block, and activations one scale per 32 values.

Finer granularity isolates outliers, i.e. the occasional value in a group that is much larger than the rest. The scale is set by the largest absolute value in the group, so the larger the group, the more likely it contains an outlier that squeezes everything else toward 0. With small blocks, an outlier only hurts its own block. The figure below places the same outlier in each of the three granularities:

per-tensorone scale for the whole tensorAffected: all 64 valuesper-channelone scale per rowAffected: 8 values in this rowper-blockone scale per 4×4 blockAffected: 16 values in this block
Schematic · a small 8×8 matrix; thick borders mark groups that share one scale; the red cell is the outlier, and the light-red cells are the group whose scale it determines

There are two costs:

5What to quantize: W / A / KV, and the WxAy notation

The WxAy notation gives the bit width of the two inputs to the matmul (weights W, activations A); it says nothing about the output. In both schemes below, the output is BF16, and what flows between layers is BF16 as well.

W8A8Activation XBF16Quantize→ FP8 + scaleFP8GEMM FP8 × FP8FP32 accumulate× scaleFP32 → BF16Output YBF16Weights WFP8 + scaleFP8W8A16Activation XBF16not quantized · BF16GEMM BF16 × BF16FP32 accumulatescale applied at dequantOutput YBF16Quantized WFP8 / INT4 + scaleDequantizereading × scale → BF16BF16
Schematic · data flow of W8A8 and W8A16; data types follow DeepSeek's public reference code linear() and common GEMM conventions

Both use FP32 accumulators; the accuracy difference comes from the activations. W8A16's error comes only from the weights, while W8A8 adds the activation quantization error on top.

In addition, W8A8 has to quantize activations on the fly at inference time, which causes two headaches:

What each scheme saves

What is quantizedWhat it savesWhere it helps
Weights only (W8A16 / W4A16, weight-only)Capacity + bandwidth, no compute savingsdecode (bandwidth-bound)
Weights + activations (W8A8)Plus computeAlso prefill (compute-bound)
KV cacheCapacity + attention bandwidth; whether attention computes in FP8 depends on the kernelLong context, high concurrency

6What AWQ / GPTQ are, and how they relate to absmax ÷ 448

If you have looked into quantization at all, you have probably come across terms like "AWQ" and "GPTQ". Here is what they mean.

The "absmax ÷ range + round-to-nearest" recipe above is called RTN (round-to-nearest). With 8 bits there are enough ticks that RTN is usually fine; INT4 has only 16 ticks, and RTN error becomes too large.

AWQ and GPTQ are both designed mainly for 4-bit weights (W4A16). They do not introduce a new data format; what they change is which value each weight ends up with. The output looks the same as RTN: low-bit weights plus scales. Packing formats and zero-point conventions differ between implementations, and frameworks pick the matching kernel based on quant_method, but at inference time they all do W4A16 dequantization plus GEMM.

MethodWhat it minimizesHow
RTN‖W − W′‖ (error of the weights themselves)absmax ÷ range, round to nearest
AWQ (arXiv 2306.00978)‖WX − W′X‖ (error of the output; needs calibration data to obtain X)Weight channels multiplied by large activations matter more: scale them up before quantizing to reduce their relative error
GPTQ (arXiv 2210.17323)Quantize column by column; after each column, adjust the remaining unquantized weights to compensate for the error (using second-order information computed from calibration data)

For infra, all of this happens offline. At inference time, all you see is a quant_method field in the config. What AWQ / GPTQ buy you is keeping accuracy from dropping too much at 4 bits.

7Reading a quantized model's config

Take the public DeepSeek-V4.1-Flash as an example. All quantization-related fields live under quantization_config in config.json:

"quantization_config": { "quant_method": "fp8", "activation_scheme": "dynamic", "weight_block_size": [32, 32], "scale_fmt": "ue8m0", "expert_dtype": "fp4" }
FieldMeaning
quant_methodName of the quantization scheme; the framework picks kernels based on it
activation_schemedynamic = activation scales computed on the fly at inference; static = fixed scales from calibration
weight_block_sizeWeight block granularity; [32, 32] = one scale per 32×32 block
scale_fmt = ue8m0The scale has only 8 exponent bits and no mantissa → it can only be an integer power of 2
expert_dtype = fp4Routed expert weights use FP4 E2M1

The comment in the reference code (linear() in the public inference/model.py) reads:

“Quantized weights need a quantized activation, and both fp4 and fp8 weights take an fp8 one -- for fp4 the kernel handles the mixed precision.”

Following the dispatch rules in linear():

To see exactly which layers stay in BF16, check the safetensors.

Other quantized models commonly have a few more fields: fmt (e.g. e4m3), bits / group_size (INT4-style schemes), and modules excluded from quantization (e.g. lm_head). The safetensors also contain the corresponding scale tensors (e.g. weight_scale_inv).

8How to measure quantization accuracy

As mentioned earlier, the 32x32 quantization granularity of DeepSeek V4.1 Flash hurts performance on Hopper. I tried requantizing the 32x32 quantized weights into 128x128 blocks, and performance improved substantially.

But how do you tell whether a new quantization scheme hurts accuracy? The rough approach is below; I may cover it in a separate article later. In the end, metrics such as top-1 token agreement and KL divergence fell short, the accuracy was not acceptable, and I dropped the 128x128 approach.

LevelHow to measureWhat it catchesOperatorvs. BF16: rel. error, cosine similarityKernel bugs, wrong scalesDistributiontop-1/top-5 token match, KL divergence, NLLError accumulated in the outputTaskBenchmarks such as GSM8K, MMLUWhat users actually notice
Schematic · three levels of accuracy validation; metric definitions follow common practice

At the distribution level, NLL (negative log-likelihood) is the same quantity as cross-entropy in this setting, and perplexity = exp(NLL).

Also, measure accuracy for every inference configuration, including high concurrency. Don't check accuracy only with serial requests and then go straight to benchmarking performance under high concurrency.

Summary: which fields to check in a quantized model

Here is everything above condensed into one table: which field to check, which resource it saves, and where it pays off:

Field to check in a quantized modelWhat it tells youResource savedWhere it pays off
Weight bit width (quant_method / dtype)Bytes per weightCapacity + bandwidthdecode (bandwidth-bound)
activation_scheme, whether activations are quantized (A8 / A16)Whether low-precision Tensor Cores are usedComputeprefill (compute-bound)
KV cache dtypeBytes per KV entryCapacity (+ attention bandwidth)Long context, high concurrency
weight_block_size, scale_fmtScale granularity and formatAccuracy / kernel pathWhether it is actually faster, and whether accuracy drops