Step-by-step answer
Stretch 60 min7 stepsImplement a KV cache and measure the speed-up
A 1.4M-parameter GPT with random weights whose forward pass accepts a per-layer KV cache, a check script showing that cached greedy decoding produces exactly the same 200 tokens as recomputing everything, a CPU benchmark at 128, 512 and 2,048 tokens with a plot, and a cache size that matches 2 × layers × KV heads × head size × bytes to the byte.
Back to the exercise