Module 11. Speculative Decoding and Quantization
Try each exercise first. Expand worked answers or project guidance when needed; their open state is shared between RU/EN.
Download course files (.zip) 2588.1 KBThe archive preserves the source folder structure, both languages, and supporting files.
Exercise 1. Exact mass balance
For and , compute , the residual distribution, and the final emitted distribution.
Show answer and solution
Solution. Accepted mass is the overlap
Missing target mass is . Normalize it by rejection probability to get . The emitted law is
Normalizing this residual—rather than simply resampling from —is what corrects the distribution after rejection.
Exercise 2. Proposal-length scan
Use with , , and . Then evaluate the illustrative point , , .
Show answer and solution
Solution. Expected emitted length, counting accepted proposals plus one correction or bonus token, is
For , over is 1.6364, 2.0333, 2.2708, 2.4011, 2.4595, 2.4696, 2.4477, 2.4050, and 2.3490. Thus the peak is , with : beyond it, acceptance gain no longer pays for the extra draft work.
For the MTP point, and the denominator is 1.05, so . These are results of the stated cost model, not universal runtime measurements.
Exercise 3. Payload ladder
Reproduce the bf16, FP8, NVFP4-like, MXFP4-like, and idealized W4 payloads for 8B weights at 3.35 TB/s. Apply to bf16 and to the 4.5 GB row.
Show answer and solution
Solution. Eight billion weights occupy 16 GB in bf16, 8 GB in FP8, 4.5 GB in the NVFP4-like scenario with overhead, 4.25 GB in the MXFP4-like row, and 4 GB at ideal four-bit packing. With :
| Format | Payload, GB | , tok/s |
|---|---|---|
| bf16 | 16.00 | 209.38 |
| FP8 | 8.00 | 418.75 |
| NVFP4-like | 4.50 | 744.44 |
| MXFP4-like | 4.25 | 788.24 |
| ideal W4 | 4.00 | 837.50 |
Applying the scenario factors gives tok/s and tok/s. These combine a weight-stream ceiling with a fixed-relative-cost scenario; real kernels, KV traffic, and acceptance can prevent the gains from composing multiplicatively.
Exercise 4 [project]
Begin with Demo 1 on CPU: next-token probabilities depend on the preceding token, and one stored batch provides all target distributions for a cycle. Compare the empirical joint law of the first two tokens with its exact value, then vary the draft table and proposal length. Report target calls and emitted tokens per call, including ordinary sampling as the baseline. Explain why call count is not elapsed time. With a suitable local model, optionally measure ITL, goodput, and accepted length at three concurrency levels.
Project demos and guidance
Demo for this project exercise: English project-demo notebook for Module 11, section “Demo 1”. It supplies the starting experiment; the exercise asks you to vary its assumptions and explain what changes.
Exercise 5 [project]
In Demo 2, compare symmetric INT4 with an E2M1-like grid on one weight matrix. Report weight MSE, relative layer-output error, and ideal code-plus-scale storage. Keep the weights fixed and change one input channel’s activity. Why does weight MSE stay constant while output error changes? An optional model experiment compares two low-bit checkpoints on a fixed held-out task set and common execution path, measuring quality, memory, and throughput.
Project demos and guidance
Demo for this project exercise: English project-demo notebook for Module 11, section “Demo 2”. It supplies the starting experiment; the exercise asks you to vary its assumptions and explain what changes.