TensoriumInterview preparation
← Home

Core concepts · 62 topics

A guided path through the ideas behind modern LLMs.

Read the stages in order: how text becomes a prediction, what happens inside the Transformer block, how a model learns, then serving, scale, and post-training. Every topic names what to know first, then gives the intuition, the math with concrete numbers, the common misconception, and a self-check. Already comfortable with the basics? Switch to By area and jump straight to a topic.

New to machine learning? Start here instead.

These topics work best as a refresher; they assume ideas like probability and loss. Begin with three short beginner lessons (tokens, embeddings, next-token prediction), then the visual walkthrough for attention and the Transformer.

Finish line: You can explain how text becomes a prediction and what training does to improve that prediction.

Topic 35 of 62 · Training at scale

Activation checkpointing

Medium

How does activation checkpointing (gradient checkpointing) reduce memory, and what is the trade-off?

Why this mattersSelective activation recomputation is the first lever to pull when long sequences overflow GPU memory, trading a small compute overhead for a large drop in saved activations.

1 · Start with the intuition

To compute ∂L/∂θ during the backward pass, each layer needs the intermediate activations it produced during the forward pass. Holding every intermediate tensor for all L layers alive at the same time creates a huge activation memory wave—especially at long sequence lengths. Activation checkpointing trades compute for memory: during the forward pass, it saves only the boundary inputs between selected blocks (e.g., each Transformer layer’s input) and discards the internal activations; when backward reaches that layer, it re-runs that layer’s forward pass on the fly to reconstruct the needed intermediates.

2 · How the mechanism works

Mechanism step 1 of 3 · no question to answer

Save block boundaries only

During forward, keep the input tensor at each checkpoint boundary and free the internal layer intermediates.

Next, we will look at: Recompute just in time. Move on when this operation makes sense.

Visualizing the behavior

Recomputation costs about one extra forward pass

Illustrative
Store everything
F1
F2
F3
F4
B4
B3
B2
B1
Checkpoint each layer
F1
F2
F3
F4
R4
B4
R3
B3
R2
B2
R1
B1
0481216time (one layer forward = 1)
  • Forward
  • Recompute
  • Backward (≈ 2× forward)
Only each layer’s input is kept. Before backpropagating through a layer, its forward pass is rerun to rebuild the internal activations: 12 → 16 time units here, about +33%.

Peak stored activations for n = 16 equal layers

Derived
Store every layer
16 units
√n segments (4 checkpoints + 1 live segment of 4)
≈ 8 units
Chen et al.’s √n strategy stores segment boundaries plus one segment’s internals, giving O(√n) memory for about one extra forward pass.