Activations are the intermediate outputs of each forward-pass layer; backprop reads them to compute gradients, so training must store or recompute them. Unlike the static param budget 16Ψ, which depends only on parameter count, activation memory scales with batch size b × sequence length s × hidden dim hl. Storing each layer's input activation (FP16, 2 bytes/element) needs 2⋅s⋅b⋅hl bytes, so total activation memory ≈ ∑l=1L2⋅s⋅b⋅hl≈2Lsbh bytes; rule of thumb: ~16 bytes per token per layer (a coarse ~8 FP16 elements per token per layer, hidden-size dependent), total ≈ 16Lsb bytes, with the exact value from ∑l2sbhl. Worked example: Llama-2 70B (L=80, h=8192), s=4096, b=2 → per layer 2×4096×2×8192≈134 MB, 80 layers ≈ 10.7 GB — about 1% of the static param budget (1120 GB), but it grows linearly with s×b and takes over under long context and large batches. Gradient checkpointing (activation recomputation): store a checkpoint every k layers instead of every layer, and rerun the forward pass during backward to regenerate intermediates; activation memory drops from O(L) to O(L) (with k≈L) at ~1/3 extra FLOPs — trading memory for compute; selective recomputation reruns only the biggest tensors (the s×s attention score matrix, MLP intermediates) to minimize the overhead.
💡Use Cases
a complete memory budget for 70B training must add the activation term; interview favorites are deriving the activation formula, the cost of gradient checkpointing, and activation memory vs KV cache.
⚡Key Problems Solved
counting only 16Ψ badly underestimates long-sequence/large-batch training (activations can exceed param memory); checkpointing cuts activation memory from O(L) to O(L) for ~33% extra compute, complementing ZeRO's param sharding — the total budget is 16Ψ/Nd (params) + activations (after recomputation), and together they decide whether a model fits.
🎯5 High-Frequency Exam Points
1
Derive the activation memory formula ∑l2⋅s⋅b⋅hl: explain each factor (2 bytes/element FP16 × layer input hl elements × s positions × b samples), why it is independent of parameter count, and why it grows linearly with batch×seq.
2
Worked example: Llama-2 70B (L=80, h=8192), s=4096, b=2 → ≈134 MB/layer, ≈10.7 GB total; put it beside the static 16Ψ=1120 GB and state what each budget scales with (params vs batch×seq) — the complementary relationship.
3
Gradient checkpointing: keep a checkpoint every k layers and recompute the forward pass in backward — activation memory drops from O(L) to O(L) at ~1/3 extra FLOPs; explain the memory-for-compute trade.
4
Which tensors dominate activation memory (the s×s attention score matrix, 4h MLP intermediates, dropout masks), and how selective recomputation reruns only the big ones to minimize overhead.
5
Distinguish activation memory (training) from KV cache (inference): activations are forward intermediates read back by backprop, growing with L×s×b; the KV cache stores generated K/V read sequentially once, formula 2⋅2⋅L⋅H⋅d⋅s⋅b; why the two budgets must not be conflated.