Inference prep
Study plan
Day 2 of 13 · Nov 29, 2026

Fit a model in memory

Weights are shared by concurrent requests. Each live sequence needs space for its own cached keys and values unless blocks can be shared.

Before you start

Yesterday’s trace. Label the prefill and decode steps before doing arithmetic.

Read and predict 1 hour including video

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

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.

Play lecture
Open original lecture

Build and test 3 hours

Compute BF16 weights for 7B parameters. For 32 layers, 8 KV heads and head width 128, calculate cache for eight 4,096-token sequences.

  1. Calculate weight bytes

    Write 7,000,000,000 × 2 bytes. Divide by 2³⁰ to convert to GiB.

  2. Calculate KV bytes per token

    Multiply 2 (key and value) × 32 layers × 8 KV heads × 128 values × 2 bytes. You should get 131,072 bytes per token.

  3. Size the batch

    Multiply by 4,096 tokens and eight sequences. Add weights and list three other allocations before choosing a GPU.

Open gateway
Troubleshooting

If your cache estimate is 2 GiB, check that you counted both key and value.

Save your result 1 hour

Save memory.md with bytes, GiB, context length, batch size and headroom assumptions. Use the same model shape again on Day 10.

Explain from memory 1 hour

Suppose output length doubles but the prompt stays fixed. Does your cache budget double?

Check your reasoning

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.