Unit 2 of 12 · about 4 hours · derive, implement

Symmetric and asymmetric quantization, scales, zero points and granularity

Every quantized serving path is this map plus metadata. If you cannot predict what a scale does to small values, calibration and method comparisons stay mysterious.

You'll be able to

  • Derive symmetric and asymmetric quantize and dequantize maps, with scale, zero point and clipping.
  • Compute representable range and worst-case rounding error for a stated width and granularity.
  • Implement per-tensor, per-channel and grouped affine quantization on a small tensor and report error per choice.

Covers

Symmetric and asymmetric quantizationScale, zero point and representable rangePer-tensor, per-channel and group granularity
1

Read

In this order, only the parts listed

0 of 3 done

  1. Day 13 Part 1: scale and zero point100 Days of LLM Inference - Days 13, 14 and 15

    Notebook day13/quantization-number-formats.ipynb, Part 1 Quantization Math: quantize_symmetric, dequantize_symmetric and the error |x - xhat| cells, with the outliers exercise

  2. Quantization preliminaries: symmetry, static versus dynamic, granularitySmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language Models

    SmoothQuant arXiv:2211.10438v7, Section 2 Preliminaries: symmetric versus asymmetric cases with zero point, static versus dynamic quantization, and per-tensor, per-token, per-channel and group-wise granularity

  3. Granularity: tensor, channel and block scalesInference Engineering - Section 5.1, Quantization

    Section 5.1.1, Number Formats: the Granularity paragraphs (tensor single scale, channel per-vector, block of N values) and the MXFP8, MXFP4 and NVFP4 block sizes

2

Focus on

  • Symmetric maps with and zero point 0. Asymmetric maps use with , rounded and clamped to range.
  • One outlier stretches and crushes the bulk: every value below rounds to zero. Clipping the range trades saturation error against rounding error.
  • Finer granularity lowers error but adds scale storage. Group-128 INT4 with FP16 scale and zero point adds bits per weight.
  • Weights normally take per-channel or grouped scales while activations take per-tensor static or per-token dynamic scales, because activation ranges move with the input.
Common mistakes · 3
  • Leaving the zero point unrounded or unclamped. It must be an integer code in range, not a float; otherwise dequantization shifts every value.
  • Quoting nominal width as served width. Scales, zero points and alignment padding are real bytes; state effective bits per value.
  • Copying per-channel scales to activations. Activation ranges depend on the input, so static per-channel activation scales go stale while per-token dynamic scales track them.
3

Try it yourself

Closed-book, before checking anything

From a blank file, implement symmetric and asymmetric INT8 quantize and dequantize. On , show one group gives and maps 0.1 to 0, then split into groups and and show 0.1 survives as code 4 with .
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.What are the symmetric INT8 scale and codes for ?Answer

    Scale . Then 100 maps to 127 and dequantizes to 100.0, and any value below about 0.39 maps to 0.

  2. 2.For range in asymmetric INT8, what are the scale and zero point?Answer

    Scale and zero point . Real zero maps exactly to code 7. The symmetric map also represents zero exactly, at code 0; the asymmetric gain is using the full code range on a skewed interval.

  3. 3.Why does one outlier destroy small values under a per-tensor scale?Answer

    The outlier sets , so the step dwarfs small magnitudes. Splitting the range into groups or channels gives the bulk its own smaller step.

  4. 4.Group-128 INT4 stores an FP16 scale and an FP16 zero point per group. What is the overhead?Answer

    bits per weight, so the served rate is about 4.25 bits per weight before alignment.

5

Practice

You're done when

Your blank-file quantizer reproduces the 0.1-to-0 collapse and its grouped fix, and you can state scale, zero point and overhead for any width and group size.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 10 more in the section

Also in this section