VKVlad KulikovPublic / lectures
Modern LLMs11 / 20

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 KB

The archive preserves the source folder structure, both languages, and supporting files.

Exercise 1. Exact mass balance

For p=(0.40,0.30,0.15,0.10,0.05)p=(0.40,0.30,0.15,0.10,0.05) and q=(0.25,0.35,0.20,0.10,0.10)q=(0.25,0.35,0.20,0.10,0.10), compute α\alpha, the residual distribution, and the final emitted distribution.

Show answer and solution

Solution. Accepted mass is the overlap

min⁡(p,q)=(0.25,0.30,0.15,0.10,0.05),α=0.85.\min(p,q)=(0.25,0.30,0.15,0.10,0.05),\qquad \alpha=0.85.

Missing target mass is (p−q)+=(0.15,0,0,0,0)(p-q)_+=(0.15,0,0,0,0). Normalize it by rejection probability 1−α=0.151-\alpha=0.15 to get r=(1,0,0,0,0)r=(1,0,0,0,0). The emitted law is

min⁡(p,q)+(1−α)r=(0.40,0.30,0.15,0.10,0.05)=p.\min(p,q)+(1-\alpha)r=(0.40,0.30,0.15,0.10,0.05)=p.

Normalizing this residual—rather than simply resampling from pp—is what corrects the distribution after rejection.

Exercise 2. Proposal-length scan

Use S=E/(1+γc)S=E/(1+\gamma c) with α=0.8\alpha=0.8, c=0.1c=0.1, and γ≤9\gamma\le9. Then evaluate the illustrative point γ=1\gamma=1, α=0.875\alpha=0.875, c=0.05c=0.05.

Show answer and solution

Solution. Expected emitted length, counting accepted proposals plus one correction or bonus token, is

Eγ=1+α+⋯+αγ=1−αγ+11−α.E_\gamma=1+\alpha+\cdots+\alpha^\gamma=\frac{1-\alpha^{\gamma+1}}{1-\alpha}.

For α=0.8\alpha=0.8, S=Eγ/(1+0.1γ)S=E_\gamma/(1+0.1\gamma) over γ=1,…,9\gamma=1,\ldots,9 is 1.6364, 2.0333, 2.2708, 2.4011, 2.4595, 2.4696, 2.4477, 2.4050, and 2.3490. Thus the peak is γ=6\gamma=6, with E=3.951424E=3.951424: beyond it, acceptance gain no longer pays for the extra draft work.

For the MTP point, E=1+0.875=1.875E=1+0.875=1.875 and the denominator is 1.05, so S=1.78571S=1.78571. 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 S=2.83790769S=2.83790769 to bf16 and S=1.78571S=1.78571 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 Q=3.35⋅1012/WQ=3.35\cdot10^{12}/W:

FormatPayload, GBQQ, tok/s
bf1616.00209.38
FP88.00418.75
NVFP4-like4.50744.44
MXFP4-like4.25788.24
ideal W44.00837.50

Applying the scenario factors gives 209.375⋅2.83790769≈594.19209.375\cdot2.83790769\approx594.19 tok/s and 3.35⋅10124.5⋅109⋅(1.875/1.05)≈1329.37\frac{3.35\cdot10^{12}}{4.5\cdot10^9}\cdot(1.875/1.05)\approx1329.37 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.