Stanford CS336 · Inference
20 min from the inference resource-accounting discussion. Derive a lower bound on the time to read weights once. Say which assumption changes when batch size increases.
Weights are shared by concurrent requests. Each live sequence needs space for its own cached keys and values unless blocks can be shared.
Yesterday’s trace. Label the prefill and decode steps before doing arithmetic.
Inference Engineering · §2.4.1–2.4.2 pp. 62–66; §3.1 pp. 74–77; §5.3.1 pp. 136–138
Use the printed page numbers. In the supplied PDF, add two to reach the viewer page. Write a prediction for the question below before opening its answer.
Baseten · Inference Engineering · PagedAttention · SOSP ’23
20 min from the inference resource-accounting discussion. Derive a lower bound on the time to read weights once. Say which assumption changes when batch size increases.
Compute BF16 weights for 7B parameters. For 32 layers, 8 KV heads and head width 128, calculate cache for eight 4,096-token sequences.
Write 7,000,000,000 × 2 bytes. Divide by 2³⁰ to convert to GiB.
Multiply 2 (key and value) × 32 layers × 8 KV heads × 128 values × 2 bytes. You should get 131,072 bytes per token.
Multiply by 4,096 tokens and eight sequences. Add weights and list three other allocations before choosing a GPU.
If your cache estimate is 2 GiB, check that you counted both key and value.
Save memory.md with bytes, GiB, context length, batch size and headroom assumptions. Use the same model shape again on Day 10.
Suppose output length doubles but the prompt stays fixed. Does your cache budget double?
Cache grows with total live tokens. Doubling only the generated tokens increases the sum of prompt and generated tokens by less than 2× for a nonempty prompt.
Check your units: weights ≈ 13.0 GiB, cache = 4 GiB before overhead. Explain how a paged cache changes allocation.