Maps to: UC Berkeley EE 290/194 Scalable AI, Spring 2026 Lecture 17, Efficiency with post-training optimization (guest lecture by Pavlo Molchanov, Director of Research, NVIDIA Deep Learning Efficiency Research; slides
lecture_17.pdf). The Fall 2026 offering has no separate lecture on this yet; its inference lectures start with serving (our Lecture 22). The guest lecture marked quantization “not covered”; §3 is written from the public format specifications and papers below. Recommended reading:
- Speculative decoding: Leviathan, Kalman, Matias, Fast Inference from Transformers via Speculative Decoding (ICML 2023); Chen et al., Accelerating LLM Decoding with Speculative Sampling (2023); Cai et al., Medusa (2024); Li et al., EAGLE (2024) and EAGLE-2/3; DeepSeek-AI, DeepSeek-V3 Technical Report §2.2 (multi-token prediction).
- Quantization: Dettmers et al., LLM.int8() (2022); Xiao et al., SmoothQuant (2023); Frantar et al., GPTQ (ICLR 2023); Lin et al., AWQ (MLSys 2024); OCP, Microscaling (MX) Formats Specification v1.0 (2023); NVIDIA, Introducing NVFP4 (technical blog, 2025).
- Pruning, distillation, search: Hinton et al., Distilling the Knowledge in a Neural Network (2015); Muralidharan et al., Compact Language Models via Pruning and Knowledge Distillation (Minitron, NeurIPS 2024); Sreenivas et al., LLM Pruning and Distillation in Practice: The Minitron Approach (arXiv:2408.11796); Men et al., ShortGPT (2024); Bercovich et al., Puzzle: Distillation-Based NAS for Inference-Optimized LLMs (ICML 2025); Molchanov et al., LANA (ECCV 2022).
Code:
code/lecture21/contains:
zoo.py: the trained models of Part IV (a 1.3M-parameter parent and a 0.16M-parameter draft model on Atlas World, cached);deploy_math.py,specdec.py,eagle.py,quant.py,compress.py: the arithmetic and the techniques;- six demos: deployment knobs, speculative math, speculative decoding on real models, quantization, prune and distill, Puzzle search.
Reading time: ~2.5 hours for the prose; ~8 minutes to run all demos (plus ~2.5 minutes once to train the zoo).
0. How to read this lecture
0.1 Learning goals
After this lecture you should be able to:
- Say which term of a decode step each technique attacks: weight bytes, KV-cache bytes, parameter count, or the number of tokens produced per weight read, and therefore when it helps and when it does not.
- Derive speculative decoding: the acceptance rule, why the output distribution is unchanged, the expected tokens per round, the speedup formula, and the best draft length; know the main kinds of drafters.
- Choose a quantization scheme: element format, scale granularity and scale format; weight-only vs weights-and-activations vs KV cache; calibration; GPTQ and SmoothQuant; why MXFP4 and NVFP4 differ.
- Compress a model the Minitron way: rank structures by activation importance, prune width or depth, and heal with distillation; know what the token savings are and where distillation does and does not beat ordinary training.
- Explain post-training architecture search (Puzzle): block libraries, block-level distillation, replace-one-block scores, a knapsack search under a deployment’s cost, and why the result differs per deployment.
0.2 Prerequisites and scope
- Prerequisites:
- Lecture 2: the roofline, and why decode is memory-bound;
- Lecture 9: number formats and Atlas World (the toy web whose entropy is known);
- Lecture 4: GQA and the KV cache;
- Lecture 20: Nemotron 3 Nano’s selective FP8 quantization.
- Scope: techniques applied to a trained model before it is served, without changing what it was trained to do.
- Not in scope: the serving engine itself (Lectures 22–23); quantization-aware training and FP8 training (Lecture 9 touched the formats); hardware built for decode (Lecture 24).
0.3 Section → code map
| Section | Idea | Code in code/lecture21/ |
|---|---|---|
| §1 | what each technique changes in a decode step | deploy_math.py, 01_deployment_knobs.py |
| §2 | speculative decoding: math, drafters, measurements | specdec.py, eagle.py, 02_speculative_math.py, 03_speculative_real.py |
| §3 | quantization: formats, scales, calibration, GPTQ, KV | quant.py, 04_quantization.py |
| §4 | pruning and distillation (Minitron) | compress.py, 05_prune_and_distill.py |
| §5 | architecture search after training (Puzzle) | compress.py, 06_puzzle_nas.py |
0.4 What is modelled and what is measured
Two kinds of numbers appear here.
- Computed (Demo 01 and parts of the others): decode-step bounds for Llama-3 models on H100 and B200, from
deploy_math.decode_step. They assume ideal kernels and no communication. Use them for ratios, not absolute milliseconds. - Measured (Demos 02–06): everything done to the parent, a 1.3M-parameter, 6-layer Transformer trained for 2,000 steps on Atlas World (Lecture 9), whose true entropy is known: 0.719 bits per byte overall; the parent reaches 0.734. The techniques run for real on it: speculative decoding with three drafters, fake-quantized formats, pruning, distillation, block search.
A tiny model on a toy world cannot reproduce the sizes of effects in a 70B model. It does reproduce their directions, and where it does not, the notes say so.
1. Why a trained model needs preparing
1.1 Train once, serve forever
A model is trained once and then generates tokens for as long as it is deployed. Over a model’s life the inference compute usually exceeds the training compute; Lecture 1’s inference-aware scaling made the same point with a formula. The guest lecture’s goal statement is blunt: maximize throughput (tokens/s) and minimize time to first token by post-training optimization.
Its framing of the field is equally clear:
- train large, compress to small: most deployed language models will be small and specialized, derived from a few large ones;
- tool use and instruction following matter more than benchmark knowledge;
- a training pipeline that ends in one checkpoint is not finished: the deployment target (one small GPU, one H100, a node, a context length, a precision) decides what the shipped model should look like.
1.2 Decode is a memory problem
Lecture 2 showed why. To generate one token for each of B sequences, a decode step must:
- read every weight once: N × (bits per weight / 8) bytes;
- read every sequence’s KV cache: B × context × (KV bytes per token);
- do 2N FLOPs per sequence, plus attention over the context.
Divide each by the hardware’s rate and take the larger. For Llama-3-8B on one H100 with 4,096-token contexts (Demo 01 Part A):
| batch | ms per step (bound) | weights’ share of bytes | math time / memory time |
|---|---|---|---|
| 1 | 4.95 | 97% | 0.4% |
| 8 | 6.08 | 79% | 2% |
| 64 | 15.05 | 32% | 7% |
At batch 1 the Tensor Cores are idle 99.6% of the time, waiting for HBM. At batch 64 the KV cache is two thirds of the traffic. At batch 256 it would be 90%, but 256 such sequences do not fit in 80 GB (at most 104 do).
1.3 Four levers, four terms
Each technique of this lecture shrinks one term:
| technique | what it shrinks | helps most when | Demo 01 (Llama-3-8B, H100) |
|---|---|---|---|
| weight quantization (FP8, INT4, NVFP4) | bytes per weight | weights dominate: small batch | FP8: 1.94× at batch 1, 1.19× at batch 64 |
| KV-cache quantization | bytes per cached token | long contexts, big batches | FP8 weights + FP8 KV: 2.00× at batch 64 |
| pruning (width) | number of weights | small batch | half the parameters: 1.94× / 1.19× |
| pruning (depth, fewer KV heads) | weights and KV | everywhere | (Lecture 4’s GQA arithmetic) |
| speculative decoding | weight reads per token | small batch, short context | α = 0.8, k = 3: 2.57× per user at batch 1 |
Two more effects are easy to miss:
- capacity: quantizing the KV cache does not only make each step faster, it doubles how many sequences fit. Llama-3-70B on two H100s holds 2 sequences of 4,096 tokens in BF16 and 155 with NVFP4 weights and an FP8 cache (Demo 01 Part C);
- new hardware formats compound: NVFP4 weights with an FP8 cache on a B200 give 8.3× the H100 BF16 baseline at batch 1 in this model.
1.4 The economics of a model family
Demo 01 Part D recomputes the guest lecture’s table. Training costs 6ND FLOPs. At 12.3M**. Training the 13B model once and compressing the others with 200B tokens each (student training plus the teacher’s forward passes) costs $4.4M. That is 2.8× less overall; the slide says 2.7×. The 10B model alone becomes 52× cheaper (slide: 53×). §4 is about how compression keeps the quality.
2. Speculative decoding
2.1 Intuition: draft, then verify
The guest lecture opens with “Write drunk, edit sober”. At small batch, a decode step reads the whole model to produce one token per sequence. Scoring 5 positions instead of 1 reads the same weights and costs almost the same time. So:
- a cheap drafter guesses the next k tokens;
- the expensive target scores all k (+1) positions in one forward pass;
- keep the drafts the target agrees with, up to the first disagreement; there, emit the target’s own correction.
When the drafter is right most of the time, each expensive forward pass yields several tokens. The decode step turns from memory-bound toward compute-bound: more FLOPs per byte read. The slide’s summary: “we spend more compute and GPU energy but improve user throughput”.
2.2 The rule, and why the output is unchanged
Let p be the target’s next-token distribution and q the drafter’s, and let the drafter propose x ~ q.
- Accept x with probability min(1, p(x)/q(x)).
- On rejection, discard x and every later draft, and sample a replacement from the residual r(y) = max(0, p(y) − q(y)) / Σ_y′ max(0, p(y′) − q(y′)).
- If all k drafts are accepted, sample one bonus token from the target’s distribution at position k+1, which the same forward pass computed.
Why this is exact. The probability that token y comes out of one position is
- accepted as a draft: q(y) · min(1, p(y)/q(y)) = min(p(y), q(y));
- produced by a rejection: (1 − α) · r(y).
Here α = Σ_y min(p(y), q(y)) is the total acceptance probability. The normalizer of r is Σ max(0, p − q) = 1 − α, so the second term is max(0, p(y) − q(y)). The sum is min(p, q) + max(0, p − q) = p(y). Exactly p, for any q.
Demo 02 Part A checks this with fractions. For p = (1/2, 3/10, 1/5, 0) and q = (1/5, 1/5, 2/5, 1/5), α = 3/5, and the emitted token is distributed exactly as p. Part B enumerates every execution of the full algorithm (k = 2) on a 3-token Markov language. The probabilities of all 81 four-token sequences equal target sampling’s exactly, so losslessness per position implies losslessness for whole sequences.
Two consequences follow:
- α = 1 − TV(p, q). The acceptance rate is one minus the total-variation distance between the two distributions. A drafter is good exactly when its distribution overlaps the target’s.
- Under greedy decoding the rule becomes “accept if the draft equals the target’s argmax”. The output is then token-for-token the target’s greedy output (Demo 03 Part D: 32/32 prompts identical for all three drafters).
2.3 How many tokens per round, and the speedup
Assume each draft is accepted with the same probability α, independently. Draft i is used only if drafts 1…i were all accepted, which has probability αⁱ, and every round also emits one token from the target. So
E[tokens per round] = 1 + α + α² + … + αᵏ = (1 − α^(k+1)) / (1 − α).
| α | k = 1 | k = 2 | k = 3 | k = 4 | k = 6 | k = 8 |
|---|---|---|---|---|---|---|
| 0.6 | 1.60 | 1.96 | 2.18 | 2.31 | 2.43 | 2.47 |
| 0.8 | 1.80 | 2.44 | 2.95 | 3.36 | 3.95 | 4.33 |
| 0.9 | 1.90 | 2.71 | 3.44 | 4.10 | 5.22 | 6.13 |
Now the cost. Each drafted token costs c target-steps of time, and the verification costs about one target step while decode is memory-bound. The speedup is
S = (1 − α^(k+1)) / ((1 − α)(c·k + 1)),
the equation on the guest lecture’s slide (from Leviathan et al.). Its two warnings are visible in Demo 02 Part C:
- a large drafter (large c) eats the gain: at α = 0.8, the best speedup is 3.09× with k = 8 when c = 0.05, but only 1.55× with k = 3 when c = 0.3;
- a poorly aligned drafter (small α) wastes the target’s verification work: at α = 0.6 no k gives more than 2.5× even with a free drafter.
The slide quotes typical results of 2.5–3.5 tokens per target pass.
2.4 Where the simple formula breaks
Correlated acceptance (Demo 02 Part D). Real text has easy stretches (boilerplate, code syntax, a quoted passage) and hard ones (a new fact, a number). Suppose half the positions are easy (α = 0.98) and half hard (α = 0.42), in long stretches. The acceptance rate is 0.70 however you average it, yet a round yields 2.64 tokens, not the formula’s 2.77 (k = 4). The reason: a rejection usually happens in a hard stretch, and when stretches persist, the next round starts there too. One α cannot capture this, so measure tokens per round directly.
Temperature (Demo 02 Part E). The same pair of models accepts 0.93 of drafts at T = 2, 0.84 at T = 1, 0.13 at T = 0.1, and 0 under greedy decoding if their top choices differ. Acceptance belongs to the pair and the sampling settings, so benchmark at the temperature you will serve.
Batch size (Demo 01 Part B). The “verification is free” premise holds only while the step is memory-bound. With 512-token contexts, Llama-3-8B’s verify step turns compute-bound at batch 256. There the gain falls from 2.57× to 1.69×, and with k = 6 at batch 768 to 0.90×: slower than not speculating. With 4,096-token contexts the KV reads, which all k+1 verified positions share, keep the step memory-bound up to the largest batch that fits. That is why the slide calls speculative decoding “great for small concurrency setups – agentic AI, personal use”.
2.5 Where drafts come from
The slide orders drafters by complexity: n-gram → MTP → EAGLE/Medusa → external drafter. It orders them by efficiency the other way round: external drafter → MTP (built during training) → EAGLE/Medusa → n-gram.
| drafter | how it drafts | cost | notes |
|---|---|---|---|
| n-gram / prompt lookup | copy what followed the last occurrence of the current n-gram in the context | ~0 | great on copy-heavy text: code edits, RAG, agents re-reading tool output; SuffixDecoding extends it with suffix trees over past outputs |
| external draft model | a small LM with the same tokenizer | k small forward passes per round | needs its own weights and KV cache (“doubles memory overhead”), and the tokenizers must match exactly |
| Medusa | extra heads on the target, head i predicts token t+i from the same hidden state | small | drafts are independent guesses, no chaining |
| EAGLE | one small block reads the target’s features (last hidden state) plus the next token and predicts the next feature, autoregressively | one block + LM head per draft | drafts in feature space; much higher acceptance than token-level drafters (Li et al.) |
| MTP | multi-token-prediction modules trained with the model during pre-training (DeepSeek-V3, Nemotron 3) | like EAGLE | the slide: Nemotron 3 Super drafts 3 and accepts 2.5; Qwen3.5 drafts 8 and accepts 5.5 |
| trees | verify several candidate continuations at once with a tree-shaped attention mask | more verified tokens per pass | raises acceptance with extra verification compute |
Newer ideas on the slide are block-diffusion drafters (DFlash) and models that “think in diffusion, talk in autoregression” (TiDAR). Lecture 28 covers diffusion LMs.
2.6 Measured on real models (Demo 03)
The target is the parent (1.31M parameters). The drafters are:
- the zoo’s draft model: 2 layers, 64 wide, 0.16M parameters, 8× smaller;
- an EAGLE-style head: one block on the parent’s features, 0.23M parameters, trained for 1,500 steps on frozen features;
- prompt lookup with n = 3.
Exact per-position acceptance α = Σ min(p, q) on held-out text (Part A):
| domain | draft model, T = 1 | EAGLE head, T = 1 | draft model greedy agreement |
|---|---|---|---|
| story | 0.962 | 0.978 | 0.966 |
| wiki | 0.949 | 0.938 | 0.936 |
| math | 0.836 | 0.895 | 0.504 |
| code | 0.915 | 0.943 | 0.727 |
Real speculative sampling at T = 1, 32 prompts × 48 tokens (Part B):
| drafter | k | tokens per target pass | acceptance by draft position |
|---|---|---|---|
| draft model | 4 | 4.15 | 0.92 0.94 0.91 0.95 |
| draft model | 6 | 5.24 | 0.91 0.91 0.94 0.93 0.93 0.91 |
| EAGLE head | 4 | 4.03 | 0.93 0.88 0.90 0.91 |
| prompt lookup | 4 | 1.14 (2.14 under greedy) | 0.20 0.33 0.37 0.75 |
What these numbers say:
- Arithmetic is where a small drafter fails. On math the draft model agrees with the target’s greedy choice only half the time. The result tokens must be computed, and the small model computes worse.
- EAGLE’s first draft is its best. The head has the higher per-position α in Part A, but in generation it yields slightly fewer tokens per pass than the draft model. Its first draft reads the target’s true features; later drafts read its own predicted features, which drift.
- Prompt lookup is free but needs repetition. It yields little on sampled prose and helps more on code and under greedy decoding.
- The output really is unchanged. The second token’s distribution from 4,000 speculative samples is 0.0304 (total variation) from the exact distribution. Sets of 4,000 exact samples land 0.025–0.038 away, so the difference is sampling noise (Part C).
Plan vs reality. The first EAGLE head, trained for 600 steps, had α = 0.87 and lost clearly to the draft model. At 1,500 steps it reaches 0.965. A drafter is a model, and an undertrained one looks like a bad method. In this toy world the separate draft model is also unusually good: the world is easy, and a 0.16M-parameter model gets close to its entropy. In real LLMs the gap between target and small drafter is larger, which is where EAGLE and MTP shine.
2.7 Systems implications
The slide lists, and Lectures 22–23 return to, the costs that formulas omit:
- budget: draft tokens use the scheduler’s token budget and KV pages;
- memory: an external drafter needs its own weights and KV cache;
- feature combinations: speculative decoding must combine with continuous batching, with CUDA graphs, and with grammar-constrained decoding, which must roll back the grammar state when drafts are rejected (Lecture 23);
- acceptance under load: it depends on the workload, so “always benchmark under realistic conditions”;
- retraining: after compression or quantization the target’s distribution changes, and a drafter trained against the old target accepts less. Drafters are trained last.
3. Number formats and quantization
3.1 What is stored, and why bits matter
Quantization stores numbers in fewer bits. Three kinds of tensors can be quantized, each for a different reason:
- weights: fewer bytes read per decode step (speed at small batch) and a smaller footprint (fewer GPUs, more KV room);
- activations: matmul inputs in FP8 or INT8 let the step run on low-precision Tensor Cores (H100 FP8: 2× the BF16 peak; B200 FP4: 4×), which matters when compute-bound: prefill and large-batch decode;
- the KV cache: fewer bytes per token of context, so faster attention reads and more concurrent sequences.
The S18 slide on quantization in serving asks the right question. It is not “what is the lowest precision?” but:
- what the hardware supports;
- which kernels are mature;
- what accuracy loss is acceptable;
- whether the memory savings turn into higher concurrency or cheaper hardware.
3.2 Element formats: integer grids and float grids
An integer format places its values uniformly: INT4 has codes −7…7, times a scale. A floating-point format places them logarithmically: dense near zero, sparse far away. For example, FP4 E2M1 (2 exponent bits, 1 mantissa bit) has the magnitudes 0, 0.5, 1, 1.5, 2, 3, 4, 6.
| format | bits | grid | largest value (unscaled) |
|---|---|---|---|
| INT8 | 8 | uniform, ±127 | 127 |
| FP8 E4M3 | 8 | log-spaced, 3 mantissa bits | 448 |
| FP8 E5M2 | 8 | log-spaced, 2 mantissa bits | 57,344 |
| INT4 | 4 | uniform, ±7 | 7 |
| FP4 E2M1 | 4 | 0, 0.5, 1, 1.5, 2, 3, 4, 6 | 6 |
Neural-network tensors are roughly bell-shaped with heavy tails. A log grid spends its codes where most values are and still reaches the rare large ones; a uniform grid is better for flat distributions. Lecture 9 measured rounding error per format; here we measure what it does to a model.
3.3 Scales: granularity and format
A low-bit value means nothing without its scale: real value = code × scale. The scale maps a group’s largest magnitude onto the format’s maximum. Two choices follow:
Granularity: how many values share one scale.
- Per tensor: one scale for everything. One outlier anywhere stretches the grid for all values.
- Per channel: one scale per output row of a weight matrix (or per token for activations).
- Per group (block): one scale per 16–128 consecutive values along the reduction dimension. The scale follows local outliers but costs bits. INT4 with an FP16 scale per 32 values stores 4 + 16/32 = 4.5 bits per weight; per 128, 4.125.
Scale format: how precisely the scale itself is stored.
- FP16/FP32: exact.
- E8M0, a pure power of two, as in the OCP Microscaling (MX) formats: MXFP8, MXFP6, MXFP4 and MXINT8, all with blocks of 32. The shared scale is 2^(⌊log₂ absmax⌋ − emax), where emax is the exponent of the element format’s largest value. Applying it is an exponent add, and it costs 8 bits per 32 values (MXFP4: 4.25 bits). But it is coarse: after scaling, a block’s absmax lands somewhere in [2^emax, 2^(emax+1)). For FP4 that is [4, 8): values between 6 and 8 saturate, and a block that lands near 4 uses only two thirds of the grid.
- E4M3, as in NVFP4 (Blackwell): FP4 elements, an FP8 E4M3 scale per 16 values, plus one FP32 scale per tensor so the E4M3 scales stay in range. That is 4.5 bits per value: finer blocks and more precise scales than MXFP4.
Measured on the parent, weight-only, round-to-nearest, LM head kept (Demo 04 Part A):
| format | bits/weight | KL to parent (nats/token) | top-1 agreement |
|---|---|---|---|
| FP8 E4M3 per channel | 8 | 0.0001 | 99.5% |
| INT8 per channel | 8 | 0.0000 | 99.6% |
| INT4 per channel | 4 | 0.0033 | 95.3% |
| INT4, scale per 128 | 4.125 | 0.0021 | 96.2% |
| INT4, scale per 32 | 4.5 | 0.0014 | 94.5% |
| MXFP4 | 4.25 | 0.0025 | 96.5% |
| NVFP4 | 4.5 | 0.0012 | 97.5% |
| FP4 E2M1 per channel (FP32 scale) | 4 | 0.0013 | 96.4% |
| INT3, scale per 32 | 3.5 | 0.0069 | 93.6% |
Three lessons:
- 8 bits are nearly free;
- at 4 bits the scale decides, more than the element format;
- NVFP4’s E4M3 block scales give half MXFP4’s error for a quarter-bit more. Even one exact scale per channel beats MXFP4’s power-of-two blocks here.
(Top-1 agreement is a noisy metric at this level; KL is the reliable one.)
3.4 Paradigms
| paradigm | what is low-precision | wins when | typical use |
|---|---|---|---|
| weight-only (W4A16, W8A16) | weights; activations stay BF16; weights are dequantized inside the matmul kernel | memory-bound decode | small-batch serving, models that must fit fewer GPUs |
| W8A8 (FP8 or INT8) | weights and matmul inputs | compute-bound prefill, large batches | FP8 on Hopper is the default production choice |
| W4A8, FP4 everywhere (NVFP4) | weights 4-bit, activations 8- or 4-bit | Blackwell FP4 Tensor Cores | the newest deployments |
| KV-cache quantization | K and V entries | long contexts, high concurrency | FP8 KV is common; INT4 KV in research and some engines |
Lecture 20’s Nemotron 3 Nano shipped FP8 weights, activations and KV cache. It kept 6 attention and 6 Mamba layers in BF16 (selective quantization) and recovered about 99% of BF16 accuracy.
3.5 Activations: outliers and calibration
Weights are known before serving; activations are not. Quantizing activations needs scales that work for inputs nobody has seen yet. There are two options:
- dynamic scales, computed per token at run time: accurate, but they cost a reduction per token;
- static scales, fixed from calibration data: cheaper and fusable, but only as good as the calibration set.
LLM activations have outlier channels: a few residual dimensions with values 100× the rest. Dettmers et al. found that they emerge systematically at around 6.7B parameters. With one per-tensor scale, they force a coarse grid on every other channel. Two families of fixes:
- clip: choose the scale from a percentile or by minimizing error, not from the max;
- migrate: SmoothQuant divides activation channel j by s_j and multiplies weight column j by s_j, with s_j = max|X_j|^α / max|W_j|^(1−α). The product X Wᵀ is unchanged before rounding, but the outliers move from the activations (hard to quantize) into the weights (easy). In deployment, s is folded into the preceding norm’s weights, so it costs nothing at run time.
Demo 04 Part C, INT8 weights per channel plus 8-bit activations:
| activation scheme | KL to parent |
|---|---|
| static per-tensor, max | 0.0054 |
| static, 99.99th-percentile clip | 0.0020 |
| static, clip minimizing each tensor’s MSE | 0.0044 |
| static max + SmoothQuant (α = 0.5) | 0.0009 |
| static FP8 (float grid), max | 0.0005 |
| dynamic per-token INT8 | 0.0002 |
This tiny model’s outliers are mild: the largest channel is up to 10× the median, against 100× and more in billion-parameter LLMs. Even so, the ordering is the published one: SmoothQuant and dynamic scales fix static-max INT8, and FP8’s float grid absorbs range by design. The MSE-optimal clip minimizes each tensor’s error, not the model’s: a reminder to judge by the model’s output.
Calibration data is part of the model. Calibrating the static scales on stories only changes little (KL 0.0021 vs 0.0020 with mixed data), because stories and the other domains share their activation ranges. Calibrating on math only doubles the overall KL (0.0039) while making math itself better (Δbpb +0.0086 vs +0.0119). The calibration set decides where the error lands, so it should look like the traffic.
3.6 Smarter rounding: GPTQ (and AWQ)
Round-to-nearest minimizes each weight’s own error. What matters is the error of the layer’s output, ‖XWᵀ − XQᵀ‖². For one output row, its Hessian with respect to the weights is H = 2XᵀX, the second moments of the layer’s inputs. GPTQ, following Optimal Brain Surgeon, quantizes one input column at a time. After quantizing column i, with error e_i, it updates every not-yet-quantized column by −e_i · H⁻¹[i, j] / H⁻¹[i, i]. Columns whose inputs are correlated absorb each other’s rounding errors. With a Cholesky factorization of H⁻¹ the whole procedure is a single pass over the columns; the paper quantized 175B-parameter models to 3–4 bits in a few GPU hours.
Demo 04 Part B (32 × 128 calibration tokens):
| format | KL, round-to-nearest | KL, GPTQ |
|---|---|---|
| INT4 per channel | 0.0033 | 0.0010 (3.3× lower) |
| INT4, scale per 32 | 0.0014 | 0.0005 |
| NVFP4 | 0.0012 | 0.0005 |
| INT3, scale per 32 | 0.0069 | 0.0047 |
GPTQ helps most where one scale covers many weights. Error compensation does not rescue 3 bits here.
AWQ (activation-aware weight quantization) takes a different route. A small share of weights matters most: those multiplying large activations. AWQ scales those input channels up before quantization (and the activations down), searching the scale exponent on calibration data. It is SmoothQuant’s idea applied to weight-only quantization.
3.7 Sensitivity: what to keep in high precision
Demo 04 Part E quantizes one group of weights at a time to INT3 (scale per 32) and leaves the rest in FP32. All MLP weights cost KL 0.0046 and all attention weights 0.0023. The LM head alone costs 0.0138, 19× more per weight than any other group. The output layer maps the final hidden state straight to the logits, with nothing after it to absorb errors. Production recipes therefore keep the embedding and LM head in high precision, and often the first and last blocks too. Lecture 20’s selective FP8 for Nano is the same idea, chosen by measured sensitivity.
3.8 What the bits buy, and what they need
On Llama-3-70B over 8 H100s at batch 1 (Demo 04 Part F, computed):
| weights | memory | decode-step bound | tokens/s/user |
|---|---|---|---|
| BF16 | 141 GB | 5.32 ms | 188 |
| FP8 | 71 GB | 2.68 ms | 373 |
| INT4, scale per 128 | 36 GB | 1.41 ms | 710 |
| NVFP4 | 40 GB | 1.53 ms | 653 |
These bounds need kernels:
- W4A16 kernels dequantize inside the matmul, at a small cost (Marlin and Machete are open examples);
- FP8 and FP4 matmuls need the hardware’s low-precision Tensor Cores;
- a format with no kernel on your hardware buys memory but not speed.
The toy’s KL numbers do not transfer to large models; the orderings and the mechanisms do.
4. Pruning and distillation: Minitron
4.1 Why compress instead of training small models
The guest lecture’s “sculpture is already within the marble” epigraph sets up the argument:
- a product line needs many sizes (the slide lists 1B, 3B, 8B, 13B, 70B, 405B), and deployment targets change while models are trained;
- training each size from scratch repeats most of the work (§1.4).
Compression instead takes the best model and derives the others from it, in 0.1–0.4T tokens instead of 15–25T: the slide’s “40×–160× faster generation of smaller models”, “2.5×–3× faster to produce an entire model family”, “+18% MMLU” compared with training from scratch.
4.2 What to remove: unstructured, semi-structured, structured
- Unstructured pruning zeroes individual weights. The matrices keep their shape and become sparse, which is hard to accelerate without special hardware.
- Semi-structured sparsity follows a strict pattern: 2:4 keeps 2 of every 4 consecutive weights. Ampere-and-later Tensor Cores run it at up to 2× (the “with sparsity” peak numbers Lecture 1 told us never to use for dense work).
- Structured pruning removes whole attention heads, MLP neurons, embedding channels or layers. The matrices become smaller dense matrices that run faster on any hardware, with no special kernels. Minitron prunes this way.
The core question is the slide’s: how do we estimate the importance of a parameter?
4.3 Importance from activations
Minitron’s answer is cheap and forward-only. Run the model on about a thousand calibration samples and record:
- MLP neurons: the mean magnitude of each neuron’s activation;
- attention heads: the size of each head’s output;
- embedding channels: the magnitude of each residual channel after the norms, summed over layers;
- depth: how much each block changes its input (block importance, BI = 1 − cos(input, output), from ShortGPT), or how much the loss rises when the block is removed.
Minitron found these forward-only scores rank structures about as well as gradient-based ones, at a fraction of the cost. Importance is concentrated. The slide shows that sorted per-head activations put most of the energy in a minority of heads (in Llama-2-7B, the top 40% of heads carry the most). On the parent (Demo 05 Part A), the top half of MLP neurons carries 69–81% of each layer’s activation mass. Removing block 0 raises the loss by 5.37 nats; removing block 3 raises it by 0.017.
4.4 Width or depth, one shot
Demo 05 Part B prunes the parent to about half its parameters, with no retraining yet:
| pruned model | params | bpb | KL to parent | top-1 agreement |
|---|---|---|---|---|
| width by importance (d 128→96, MLP 384→192) | 50% | 0.879 | 0.32 | 80.7% |
| width, random channels and neurons | 50% | 1.362 | 1.46 | 47.5% |
| depth, drop the 3 least important blocks | 55% | 0.891 | 0.36 | 64.0% |
(The parent is at 0.734 and the floor at 0.719.) Ranking by importance is what makes one-shot pruning usable: random channels destroy the model.
4.5 Healing with distillation
After pruning, the model is retrained briefly. Minitron compares two ways:
- conventional training on ground-truth next tokens;
- knowledge distillation: the pruned student mimics the unpruned teacher. The main loss is the KL between their output distributions at every position. The softmax temperature τ softens both distributions, so small probabilities carry signal (“dark knowledge”). Optional terms match intermediate hidden states.
KD gives the student a whole distribution per token instead of one label. Minitron found logit KD with forward KL to be the best single choice. When the original pre-training data is unavailable (Mistral-NeMo-12B, Llama-3.1-8B), the teacher is first fine-tuned briefly on the distillation data (“teacher correction”, ~127B tokens on the slide), so that it is not distilled out of distribution.
Demo 05 Part C: 200 steps × 4,096 tokens, 10% of the parent’s training tokens.
| model (~0.65M parameters) | steps | bpb all | bpb math | KL to parent |
|---|---|---|---|---|
| width-pruned + distillation | 200 | 0.7359 | 1.0551 | 0.0069 |
| width-pruned + next-token CE | 200 | 0.7353 | 1.0379 | 0.0135 |
| random-width + distillation | 200 | 0.7380 | 1.0708 | 0.0124 |
| depth-pruned (0.72M) + distillation | 200 | 0.7425 | 1.1501 | 0.0240 |
| same architecture from scratch, CE | 200 | 0.8154 | 1.3708 | 0.2079 |
| same architecture from scratch, CE | 800 | 0.7466 | 1.1792 | 0.0448 |
| same architecture from scratch, distilled | 800 | 0.7419 | 1.1357 | 0.0242 |
| (parent, 1.31M) | 2,000 | 0.7339 | 1.0205 | 0 |
What reproduces, and what does not:
- Starting from the pruned parent is worth far more than tokens. After 10% of the parent’s tokens the compressed model is 0.017 bits/byte above the floor. A from-scratch twin with 4× as many tokens is still worse, even when distilled. This is Minitron’s token saving in miniature.
- Width beats depth on accuracy, as the slide reports. The depth-pruned model is worst on math, and the slide’s GSM8K numbers say the same: “depth pruning significantly affects reasoning”. The slide gives GSM8K 16.8 for depth vs 41.2 for width. Depth pruning removes whole sequential steps, though, so it cuts latency more.
- The importance ranking still matters after healing: random-width pruning heals to 0.7380.
- Distillation did not beat plain training after pruning here. The two end at the same bpb. Distillation copies the parent more closely (KL halves), including its mistakes: on math, where the parent itself is 0.127 bits/byte above the floor, the CE student is better. The reason is specific to the toy. Atlas World’s training text is sampled from the true distribution, so ground-truth labels are an excellent teacher too. In Minitron’s setting, real web text with a teacher much better than anything small trained on the same data, distillation won. From scratch, where the student knows nothing, distillation does help (0.7419 vs 0.7466).
4.6 Lessons from NVIDIA’s compressed models (from the slides)
- Compress by about 2× per step; beyond that, prune and distill iteratively.
- Many attention layers can be removed, especially in hybrids. Nemotron-H 56B, a hybrid Mamba-attention model trained on 20T tokens, was compressed to 47B so that a 1M-token context fits in a 32 GB GPU (an RTX 5090 at FP4). The recipe: drop 5 of 10 attention layers, remove 10 Mamba and 5 FFN layers, compress every FFN by 6.25%, and distill on 100B tokens. The result was 20% faster and better on some benchmarks.
- NVIDIA-Nemotron-Nano-v2 (9B) was compressed from a 12B model. The team now trains about 20–30% larger and compresses: “don’t see reasons why not to do it”.
- Reasoning models need some RL or DPO after compression to recover accuracy.
- On-policy distillation: the student generates, and the teacher scores each of its tokens with reverse KL. The student learns from its own mistakes rather than from teacher text it would never produce. This is Lecture 19’s train–inference mismatch argument, applied to distillation.
4.7 Many models in one: elastic networks
Flextron, LlamaFlex and Nemotron-Elastic go one step further. Permute heads, channels and neurons by importance, so every smaller width is a prefix of the larger one, a nested architecture. Then continue training with a router that picks the width per layer for a given budget.
- Cost: about 5% of the original training tokens (60B on top of Llama-3-8B). The result is one checkpoint from which models of 1.75B–7B can be sliced without further training, close in quality to separately pruned models.
- Nemotron-Elastic: applied to the hybrid Nemotron-Nano-v2, keeping the Mamba state and KV cache sizes fixed while compressing MoE width, hidden size and top-k.
The deployment cost becomes a run-time knob.
5. Architecture search after training: LANA and Puzzle
5.1 The idea: train with what trains well, serve with what serves well
Training prefers operations that optimize well: full attention, SwiGLU, wide MLPs. Serving prefers operations that run fast on the target: fewer KV heads, sliding-window attention, narrower MLPs, sparser MoE.
LANA (Latency-Aware Network Acceleration, ECCV 2022) proposed doing both:
- train with training-friendly blocks;
- train candidate replacement blocks to imitate each original block, using about 1% of the data, once;
- pick replacements per deployment target by integer linear programming, in under 10 minutes;
- fine-tune briefly (5–30% of full training).
Puzzle (ICML 2025) is LANA for LLMs.
5.2 Puzzle in four steps
-
The block library. For every layer, alternative blocks:
- remove the whole layer;
- attention with 8, 4, 2 or 1 KV heads (or a linear replacement);
- FFNs at roughly 87%, 75%, 50%, 25%, 20% or 10% of the width.
Each variant is trained by block-level distillation (BLD): it sees exactly the parent’s input to that layer and minimizes a normalized MSE to the parent’s output. No gradient crosses layers, so all variants can be trained in parallel, once, cheaply.
-
Scores. Each variant is scored by replacing just that one block in the parent and measuring the damage (KL, LM loss, or a benchmark such as MMLU). Cost is measured too: each variant’s runtime and memory on the target hardware.
-
Search. The full space is about 10¹³⁸ architectures, beyond any standard NAS. Puzzle relaxes the model’s quality to a sum of per-block scores. The problem becomes a knapsack: one option per layer, best total score, total cost within budget. Mixed-integer programming solves it in seconds and can return several diverse solutions.
-
Healing. The relaxation ignores how adjacent blocks interact, so errors accumulate. Puzzle runs a short distillation on several candidates, picks the best, and distills it longer. The slide’s results:
- Llama-3.1-70B → 49–51B with about 50B tokens (even 4B tokens is enough for the method);
- gpt-oss-puzzle-88B from GPT-OSS-120B, 1.22× throughput on 8 GPUs and 2.82× on 1 GPU, accuracy retention 100%+. It used heterogeneous MoE expert pruning (8 to 128 of the 128 experts per layer), turned 8 of 18 global-attention layers into window attention, used an FP8 KV cache with calibrated scales, and finished with RL.
5.3 Measured (Demo 06)
The parent’s library has, per layer:
- attention: full, one KV head (
kv1), a linear map, or nothing; - MLP: full, 50%, 25%, a linear map, or nothing.
Block-level distillation is strikingly effective for kv1: NMSE 0.58 → 0.012. A linear map cannot replace attention (NMSE 0.66 after training): attention’s job, moving information between tokens, cannot be done per token.
The replace-one-block scores vary enormously by position:
- removing attention costs KL 0.471 at the worst layer and 0.019 at the best;
- removing layer 0’s MLP costs 5.58, but at the best layer 0.014.
A deployment’s cost is the bytes one decode step reads for each variant: its weights plus, for attention, its KV cache. In an interactive deployment (batch 1, 128-token context) weights dominate. In a long-context batch deployment (batch 8, 1,024 tokens) the KV cache does.
| budget | deployment | searched (heterogeneous) | healed KL | best uniform at the same cost | healed KL |
|---|---|---|---|---|---|
| 45% | interactive | kv1 + 25% MLP everywhere, except full attention in layer 2 | 0.0072 | kv1 + 25% MLP everywhere | 0.0081 |
| 35% | interactive | MLPs removed in layers 2–3, attention removed in layer 5 | 0.015 | linear attention everywhere | 0.867 |
| 35% | long-context batch | attention replaced by a linear map (no KV cache) in layers 3 and 5, all MLPs kept | 0.012 | linear attention everywhere | 0.865 |
Three lessons:
- One parent, a different child per deployment. Where weights dominate, the search cuts MLPs. Where the KV cache dominates, it spends the budget on MLPs and replaces attention instead.
- Heterogeneity matters once the budget forces hard choices. At 45% a uniform architecture is nearly as good. At 35% every uniform option must remove or linearize the same block in every layer, including the layers where that is fatal.
- The summed scores under-predict. At 35% they predicted KL 0.068 and 0.047; the assembled models measured 0.217 and 0.094 before healing. Damages compound, which is why Puzzle heals and checks several candidates.
6. Putting it together
A typical order of operations, and why:
- Architecture first: prune or search (§4–§5), because quantizing a model you will then restructure wastes the calibration.
- Heal by distillation, including RL or DPO for reasoning models (§4.6).
- Quantize: choose formats per tensor type by measured sensitivity, calibrate on traffic-like data, keep sensitive layers (the LM head) in high precision (§3).
- Train or re-train the drafter against the final model. Every earlier step changes the target’s distribution, and acceptance depends on it (§2.7).
- Benchmark the combination you will ship (format + drafter + engine + traffic), not each technique alone. Lecture 23’s case study is a production bug class that only appears in combination: guided decoding with speculative decoding and CUDA graphs.
Each technique also changes the others:
- a smaller target makes a fixed drafter relatively more expensive (larger c);
- a quantized KV cache shrinks memory per sequence, so the batch grows, the step drifts toward compute-bound, and speculative decoding gains less;
- depth pruning shortens the critical path that latency-bound decode cares about, which width pruning does not.
7. Summary
- Decode is memory-bound at small batch. Each technique shrinks one term of the step: weight bytes (quantization, pruning), KV bytes (KV quantization, fewer KV heads, depth), or weight reads per token (speculative decoding). Which helps depends on batch and context.
- Speculative decoding is lossless. Accepting with min(1, p/q) and resampling from the residual emits exactly p, and α = 1 − TV(p, q). Tokens per round are (1 − α^(k+1))/(1 − α), and the speedup divides that by c·k + 1. Correlated acceptance, temperature and batch size all move the real result.
- Drafters range from free to trained: prompt lookup, a separate small model, Medusa heads, EAGLE on the target’s features, MTP trained with the model. On the toy, every drafter keeps the output exact. The draft model yields 4.15 tokens per pass at k = 4; EAGLE’s chained drafts drift.
- A quantization scheme is element format × granularity × scale format. 8 bits are nearly free. At 4 bits, the scales decide: NVFP4’s E4M3 scales per 16 values beat MXFP4’s power-of-two scales per 32. GPTQ, SmoothQuant and dynamic scales fix most of the rest. The LM head and early layers are the most sensitive.
- Minitron: activation importance → structured width/depth pruning → distillation. It reuses the parent’s training, giving 40×-fewer-token models on the slide; on the toy, 10% of the parent’s tokens beat a from-scratch twin with 4× more. Width is more accurate, depth is faster.
- Puzzle: a block library trained locally, replace-one-block scores, a knapsack under the deployment’s measured cost, then healing. The best child differs per deployment, and summed scores under-predict the damage.
8. Common pitfalls
- Quoting speculative speedups at batch 1 for a high-batch service. Once the verify step is compute-bound, drafts stop being free and can make decoding slower (Demo 01 Part B).
- Using one average α in the formula. Acceptance is correlated and depends on position and temperature. Measure tokens per target pass on your traffic.
- Forgetting the drafter after changing the target. Quantizing, pruning or fine-tuning the target lowers a drafter’s acceptance; retrain it last.
- Counting 4 bits as 4 bits. Scales cost 0.125–0.5 bits per weight, and a format without a kernel on your GPU saves memory but not time.
- Calibrating on convenient data. Static scales calibrated on one kind of text move the error onto the others (Demo 04 Part C).
- Quantizing the LM head with everything else. Per weight it is by far the most sensitive tensor (Demo 04 Part E).
- Random or magnitude-of-weights pruning of LLMs. Rank by activations on representative data; random structured pruning destroys the model (Demo 05 Part B).
- Judging a compression method before healing. One-shot numbers rank candidates; only healed numbers say what you ship. Judge after healing, but compare candidates at equal healing budgets.
- Trusting a sum of per-block scores. Damages compound (Demo 06 Part D).
- Assuming distillation always beats labels. When ground-truth data is plentiful and the teacher has known weaknesses, check (Demo 05 Part C).
9. Exercises
-
Acceptance from TV. p = (0.6, 0.3, 0.1), q = (0.3, 0.3, 0.4). Compute α, the residual r, and the expected tokens per round for k = 3 under the i.i.d. assumption.
Answer
α = min(.6,.3)+min(.3,.3)+min(.1,.4) = 0.3+0.3+0.1 = 0.7 (TV = 0.3). max(0, p−q) = (0.3, 0, 0), so r = (1, 0, 0): a rejection always emits token 0, which the drafter under-proposes. E[tokens] = (1 − 0.7⁴)/(0.3) = 2.53. -
Best draft length. α = 0.75, c = 0.1. Compute the speedup for k = 2, 3, 4, 5 and find the best k.
Answer
E[tokens] = (1−0.75^(k+1))/0.25: 2.31, 2.73, 3.05, 3.29. Divided by (0.1k + 1): k=2 1.93, k=3 2.10, k=4 2.18, k=5 2.19, k=6 3.47/1.6 = 2.17. Best k = 5 (2.19×), with k = 4 almost as good. The optimum is flat, so choose by memory and token-budget cost. -
When does verification stop being free? For Llama-3-8B on an H100 (989 TFLOP/s BF16, 3.35 TB/s), batch B, context 512, k = 3: estimate the B at which the verify step’s math time equals its memory time. Ignore attention FLOPs.
Answer
Bytes ≈ 16 GB weights + B × 512 × 128 KiB = 16e9 + B × 6.7e7. FLOPs ≈ B × 4 × 2 × 8e9 = 6.4e10 B. Equal times: 6.4e10 B / 989e12 = (16e9 + 6.7e7 B)/3.35e12 → 6.47e-5 B = 4.78e-3 + 2.0e-5 B → B ≈ 107. Above ~100 sequences the verify step is compute-bound (Demo 01 shows compute-bound at batch 64 with k = 6). Longer contexts push this point higher, since KV bytes grow and FLOPs barely do. -
Bits accounting. A 70B model in INT4 with an FP16 scale and an FP16 zero point per 128 weights: bits per weight and total GB? In NVFP4?
Answer
INT4 g128 with scale + zero: 4 + 32/128 = 4.25 bits → 70e9 × 4.25/8 = 37.2 GB. NVFP4: 4 + 8/16 = 4.5 bits (+ one FP32 per tensor, negligible) → 39.4 GB. -
Why NVFP4 has a second-level scale. E4M3 covers about 2⁻⁹ to 448. Why can’t per-16 E4M3 scales alone represent a weight tensor whose absmax is 0.002?
Answer
A block scale is absmax/6. For absmax 0.002 that is ~3.3e-4, below E4M3's smallest normal (2⁻⁶ ≈ 0.0156) and even below its smallest subnormal (2⁻⁹ ≈ 0.002), so it would flush to zero (or, clamped, be far too large). Dividing first by a per-tensor FP32 scale (tensor absmax / (448 × 6)) maps the block scales into E4M3's well-represented range. -
SmoothQuant’s α. One channel has activations up to 60 and weights up to 0.05; the others have activations ~1 and weights ~0.5. With α = 0.5, what is s for the outlier channel, and what are the new maxima?
Answer
s = 60^0.5 / 0.05^0.5 = 7.75/0.224 = 34.6. New activation max 60/34.6 = 1.73; new weight max 0.05 × 34.6 = 1.73. The difficulty is split evenly (that is what α = 0.5 means). The typical channels: s = 1/√0.5 = 1.41, activations 0.71, weights 0.71. -
Width or depth for latency. A 32-layer model at batch 1 is memory-bound, and its layers run one after another. Compare the decode latency of (a) halving every MLP and the hidden size and (b) removing 16 layers, both giving ~50% of the parameters.
Answer
Memory-bound decode time is proportional to bytes read, about equal in (a) and (b), so the HBM-bound latency is similar. But (b) halves the number of sequential steps: half the kernel launches, half the per-layer synchronization (and, with tensor parallelism, half the all-reduces), and half the KV cache. So depth pruning is faster in practice, as the slide says, while width pruning keeps more accuracy. -
The knapsack. Three layers, each with the same options (cost, score): A (4, 0), B (2, 0.1), C (0, 1.0). Lower score is better. Budget 5. Find the best uniform choice and the best mix.
Answer
Uniform: all-A costs 12 and all-B 6, both over budget; all-C costs 0 with score 3.0. Mixes within budget 5: {A, C, C} cost 4, score 2.0; {B, B, C} cost 4, score 1.2; {A, B, C} cost 6, over budget. The optimum is {B, B, C} (1.2), far better than any uniform choice (3.0). Heterogeneity wins exactly when the budget falls between the costs of uniform options; with budget 6, all-B (0.3) would be optimal and uniform. -
Distillation’s signal. A teacher puts 0.5, 0.3 and 0.2 on three tokens; the training text happens to contain the first. How much more information does the student receive per position from KD than from the label, in the sense of the cross-entropy target’s entropy?
Answer
The label is a one-hot target (entropy 0): it says only "token 1". The teacher's target has entropy −Σp log₂p = 1.49 bits and also ranks the alternatives. With labels, the student must estimate the 0.3 and 0.2 from many examples; with KD it is told directly. This is why KD helps most when the student starts from nothing (Demo 05: from scratch, KD 0.7419 vs CE 0.7466). It also transfers the teacher's errors.
10. The related assignment (concepts only)
Assignment 4 (Inference and Serving, both offerings) exercises serving engines (Lectures 22–23), but its performance questions start here:
- Know which term dominates. Before enabling a technique, compute the weight bytes, KV bytes and FLOPs of the step at the batch and context you will run.
- Measure acceptance and quality yourself. A quantized or speculative configuration must be checked against the BF16 baseline on your evaluation (KL or task accuracy), with error bars.
- Benchmark combinations. Quantization + speculation + batching, at realistic concurrency.
No solutions are given here; the demos are written independently of the assignment’s starter code.
11. Research directions
- Drafters that stay aligned: MTP heads trained with the model; drafters retrained cheaply after quantization or compression; acceptance-aware training objectives.
- Speculation at high batch: adaptive k per request; drafting only for the requests most likely to accept; joint scheduling of draft and verify work (Lecture 22’s scheduler with speculation in the budget).
- 4-bit everything: NVFP4 / MXFP4 activations and KV caches without accuracy loss; rotations (QuaRot, SpinQuant) that spread outliers before rounding; what the LM head and attention softmax need.
- Compression of reasoning models: why depth pruning hurts multi-step reasoning, and how RL or on-policy distillation recovers it.
- Search over hybrids: Puzzle-style search over attention, sliding-window, Mamba and MoE variants per layer, with real latency on the target chip, and better-than-additive quality predictors.
- Elastic deployment: one nested checkpoint serving many cost points, chosen per request by a router.
12. Further reading
- Leviathan et al. 2023 and Chen et al. 2023 for the algorithm; Xia et al., Unlocking Efficiency in LLM Inference: A Comprehensive Survey of Speculative Decoding (2024).
- NVIDIA technical blog, An Introduction to Speculative Decoding for Reducing Latency in AI Inference, and the TensorRT Model Optimizer examples (
github.com/NVIDIA/Model-Optimizer), where most of this lecture’s NVIDIA methods are implemented. - Gholami et al., A Survey of Quantization Methods for Efficient Neural Network Inference (2021); the OCP MX specification.
- Muralidharan et al. 2024 and Sreenivas et al. 2024 (Minitron); Bercovich et al. 2025 (Puzzle); Thinking Machines, On-Policy Distillation (blog, 2025).
13. Next lecture
Lecture 22, Fundamentals of High-Performance Inference, puts the prepared model into a server. With many users at once, latency splits into time-to-first-token and time per output token. Batching, KV-cache memory management (PagedAttention), prefix caching, chunked prefill and the scheduler decide how much of this lecture’s per-step speed reaches the users. Speculative decoding returns there as one more consumer of the scheduler’s token budget.
术语表 (Glossary, English → 中文)
| English | 中文 |
|---|---|
| deployment preparation / post-training optimization | 部署准备 / 训练后优化 |
| memory-bound / compute-bound | 访存受限 / 计算受限 |
| speculative decoding / draft model / target model | 投机解码 / 草稿模型 / 目标模型 |
| acceptance rate / rejection sampling / residual distribution | 接受率 / 拒绝采样 / 残差分布 |
| total-variation distance / lossless | 全变差距离 / 无损 |
| bonus token / draft length | 额外词元 / 草稿长度 |
| prompt lookup / n-gram drafting | 提示查找 / n 元草稿 |
| Medusa heads / EAGLE / multi-token prediction (MTP) | Medusa 多头 / EAGLE 特征级草稿 / 多词元预测 |
| tree attention / tree verification | 树形注意力 / 树形验证 |
| quantization / post-training quantization (PTQ) | 量化 / 训练后量化 |
| fake quantization / dequantize | 伪量化 / 反量化 |
| scale / granularity (per-tensor, per-channel, per-group) | 缩放因子 / 粒度(逐张量、逐通道、逐组) |
| microscaling (MX) / E8M0 scale / NVFP4 / second-level scale | 微缩放格式 / 2 的幂次缩放 / NVFP4 / 二级缩放 |
| weight-only quantization / W8A8 / KV-cache quantization | 仅权重量化 / 权重激活 8 位 / 键值缓存量化 |
| outlier / calibration / static vs dynamic scale | 离群值 / 校准 / 静态与动态缩放 |
| SmoothQuant / GPTQ / AWQ | 平滑量化 / GPTQ 二阶误差补偿量化 / 激活感知权重量化 |
| Hessian / error compensation | 海森矩阵 / 误差补偿 |
| selective quantization / sensitivity | 选择性量化 / 敏感度 |
| unstructured / semi-structured (2:4) / structured pruning | 非结构化 / 半结构化(2:4) / 结构化剪枝 |
| importance score / block importance | 重要性得分 / 块重要性 |
| width pruning / depth pruning | 宽度剪枝 / 深度剪枝 |
| knowledge distillation / teacher / student / dark knowledge | 知识蒸馏 / 教师 / 学生 / 暗知识 |
| teacher correction / on-policy distillation / reverse KL | 教师校正 / 在策略蒸馏 / 反向 KL |
| elastic (nested) model / router | 弹性(嵌套)模型 / 路由器 |
| neural architecture search (NAS) / block library | 神经架构搜索 / 块库 |
| block-level distillation / replace-1-block score | 块级蒸馏 / 单块替换得分 |
| knapsack / mixed-integer programming | 背包问题 / 混合整数规划 |
| healing / heterogeneous architecture / deployment scenario | 修复训练 / 异构架构 / 部署场景 |