Unit 6 of 12 · about 3 hours · measure
Measuring quantized memory, latency and throughput, including KV quantization
Quantization without measurement is a smaller file, not a faster service. Memory, latency and quality must be measured together on the workload that pays for them.
You'll be able to
- Derive KV bytes per token for a stated attention shape and predict what FP8 KV quantization saves.
- Measure weight and KV memory, TTFT, TPOT and throughput for a quantized path against its unquantized baseline.
- Decide where KV quantization belongs in a long-context plan, with a quantized-attention condition.
Covers
Read
In this order, only the parts listed
0 of 3 done
- vLLM quantization support and quantized KV cachevLLM Speculative Decoding and Quantization (v0.31.0)
Supported Hardware table (AWQ, GPTQ, Marlin, FP8 rows against Volta through Hopper) on the quantization page, then the Quantized KV Cache page: FP8 overview, per-tensor versus per-attention-head scales, the two scale-calibration approaches (default scales and dataset calibration with llm-compressor), and
--kv-cache-dtype-skip-layersRead the pages against installed v0.31.0 only. Both flags named below are v0.31.0 flags; older releases differ. Bundled lab expectations for other GPUs are not your targets.
- Quantized serving behavior under concurrencyHands-On LLM Serving and Optimization - Quantization (Chapter 6) and Speculative Decoding (Chapter 7)
Chapter 6: the concurrency charts comparing the original model with GPTQ W4A16 and FP8 W8A8 for TTFT and throughput, and KV cache quantization and attention quantization with the quantized-attention condition; then Chapter 9, Step 6 Benchmark the Quantized Qwen3 Model with vLLM (printed p. 304)
Read the charts as the authors result on their hardware and model. Your unit reproduces the comparison shape, not their numbers.
- KV quantization and prefix cachingInference Engineering - Section 5.1, Quantization
Section 5.1.2: the KV cache paragraphs (prefix caching and disaggregation gains, per-token reuse by later tokens)
Focus on
- KV bytes per token are : two for keys and values, times layers, KV heads, head dimension and bytes per element. FP8 halves against FP16; per-head scales add a small metadata term.
- Weight-only methods improve with concurrency differently from W8A8: GPTQ W4A16 still computes in 16-bit, so its TTFT can lag the baseline while FP8 pulls ahead on throughput.
- Check your GPU row in the vLLM hardware table before planning a run. An unsupported path is not a slow path; it is absent.
- KV quantization error persists across positions because every later token reads the stored values. Calibrate on long sequences and keep sensitive layers skippable.
Common mistakes · 3
- Measuring throughput at one concurrency and generalizing. Weight-only and W8A8 cross over as concurrency rises; sweep it.
- Comparing quantized quality without the engine contract. Keep prompts, output limits, sampling and cache state identical or the comparison is void.
- Treating bundled B200 or GB200 expectation files as targets. They are another machine results; your numbers are labeled with your GPU, engine version and settings.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.For , , , what are KV bytes per token in FP16 and FP8?Answer
bytes in FP16, or 128 KiB, and half that, 64 KiB, in FP8 before scale metadata.
2.Why can GPTQ W4A16 lose on TTFT while winning on memory?Answer
Prefill still computes in 16-bit after dequantization, adding conversion cost without compute savings. The win is weight capacity and decode bandwidth, visible under memory pressure.
3.When does FP8 KV cache need a quantized attention kernel to pay?Answer
Whenever latency, not just capacity, is the goal. Without it the values are dequantized before the dot product; capacity still improves, arithmetic does not.
4.Which layers would you exempt first from KV quantization, and how?Answer
Sliding-window or otherwise sensitive attention layers, via
--kv-cache-dtype-skip-layerswith layer indices or type names.
Practice
- AI Systems Performance Engineering companion code Chapter 19: dynamic quantized cache
baseline_dynamic_quantized_cache.pyagainstoptimized_dynamic_quantized_cache.py: the same refresh steps and cache footprint in FP32 versus adaptive INT8, INT6 and INT4 refresh. The harness only checks that the two outputs agree withinoutput_tolerance=(0.05, 0.5), a loose cache-value check, not model qualityRun on your GPU and report memory traffic beside your own quality check on a fixed workload; bundled B200 expectations are not targets.
You're done when
You derive KV bytes for a new shape without notes and produce a baseline-versus-quantized table with memory, TTFT, TPOT and quality on one fixed workload.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 10 more in the section
- Hands-On LLM Serving and Optimization - Quantization (Chapter 6) and Speculative Decoding (Chapter 7)Chi Wang and Peiheng Hu (O'Reilly) · primary
Read "Model Compression" in Chapter 6 for quantization and "Speculative Decoding" in Chapter 7, with its hands-on example. For each method write its correctness contract, the engine support it needs and a predicted winning and losing workload before running it.
- vLLM Speculative Decoding and Quantization (v0.31.0)vLLM Project · required
Use the speculative decoding page for the supported proposers (draft model, n-gram, EAGLE, MTP) and its losslessness notes, and the quantization page for the hardware support table. Check every method against your GPU's compute capability before planning a run.
- Inference Engineering - Section 5.1, QuantizationPhilip Kiely (Baseten Books) · support
Read 5.1.1 Number Formats for the format table and Precision/Type/Scale-factor with Dynamic range/Granularity, 5.1.2 for PTQ versus QAT and the what-to-quantize decisions, and 5.1.3 for the perplexity, benchmark and custom-eval quality checks.
Also in this section
- MIT 6.5940 TinyML and Efficient Deep Learning Computing - Quantization LecturesMIT Han Lab · required
Use Lectures 5 and 6 for quantization fundamentals and Lecture 13, Efficient LLM Deployment, for SmoothQuant and AWQ with TinyChat. Implement a small affine quantizer and an outlier experiment before using a pre-quantized checkpoint.
- SmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language ModelsMIT and NVIDIA · required
Study activation outliers and the offline smoothing transformation. Reproduce the algebra on one linear layer and compare calibration-sensitive quality with an unmodified reference.
- AWQ: Activation-Aware Weight Quantization for LLM Compression and AccelerationMIT Han Lab · required
Focus on salient-weight protection, group scaling and the distinction between simulated quality and real kernel speed. Compare one supported AWQ path with the same unquantized workload.
- Fast Inference from Transformers via Speculative DecodingDeepMind · required
Derive acceptance and correction probabilities and implement the exact categorical simulator. Prove distributional equality on tiny distributions before adding a model or engine.
- AI Systems Performance Engineering - Chapters 15 and 16, speculation and quantizationChris Fregly (O'Reilly) · support
Read "Speculative Decoding and Parallel Token Generation Techniques" in Chapter 15 (draft models, EAGLE, self-speculation, Medusa) and "Quantization Approaches for Real-Time Inference" in Chapter 16.
- AI Systems Performance Engineering companion code - Chapters 16, 18 and 19 labsChris Fregly · required
Use Chapter 16 AWQ, GPTQ and SmoothQuant pairs, Chapter 18 speculation sweeps and Chapter 19 dynamic quantized cache. Run one family at a time, require quality or numerical parity, and regenerate results on available hardware.
- 100 Days of LLM Inference - Days 13, 14 and 15Elizabeth Thomas · support
Use the numeric-format, quantization-algorithm and speculative-decoding notebooks as compact preparation. Keep their synthetic demos separate from production-engine and hardware evidence.
- TensorTonic Language Modeling from Scratch - Perform Exact Speculative SamplingTensorTonic · support
Solve after the acceptance-rule unit, then check your implementation's output distribution against the target by exact enumeration on a tiny vocabulary.
- LLM Inference: From scratch, one token at a time - Module 08Tushar Amrit · support
Work the Speculative Decoding module's acceptance arithmetic and checkpoint before the speedup-model unit.
- AI Performance Engineering - Quantization and Speculative DecodingWafer · reference
A curated index. Use Section 4 only to find a quantization or speculation paper the other entries lack.