What does gradient checkpointing trade, and roughly by how much?
Gradient checkpointing trades extra compute for activation memory. Typical cost is roughly 30 percent more wall-clock per step in exchange for roughly 60 to 70 percent less activation memory.
Imagine taking a long road trip and writing down detailed notes about every turn so you can retrace your route home. Eventually your notebook fills up. Gradient checkpointing is like deciding to write down only the major waypoints (every fifth turn) instead of every single turn. When you need to find your way back, you can drive the small loops between waypoints again to reconstruct the detailed turns you did not write down. You burn extra fuel doing the small re-drives, but your notebook stays small enough to carry. For long sequences during model training, the savings are large. They are the difference between running out of GPU memory and finishing the job.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Gradient checkpointing is a memory versus compute trade-off in deep learning training. The technique is conceptually simple and the implementation is a few lines. The impact on training feasibility is enormous: it routinely turns OOM crashes into successful runs at the cost of about a quarter of throughput.
The mechanism rests on a basic observation about backpropagation. The backward pass needs the activations from the forward pass to compute gradients. That is why frameworks normally keep all intermediates in memory throughout the forward. Gradient checkpointing observes that you do not have to keep them: you can drop them and recompute them on demand when backward arrives.
Activation memory: the term that gradient checkpointing targets
Training memory decomposes into four roughly orthogonal terms: weights, gradients, optimizer state, and activations. Each scales differently with model size and training configuration.
Weights, gradients, and optimizer state scale with parameter count and are fixed once the model is loaded. For a 7B model in bf16 with Adam: 14 GB weights, 14 GB gradients, 56 GB Adam moments, totaling 84 GB of fixed training state.
Activations are different. They scale with batch size, sequence length, and depth: roughly O(B times S times H times L) bytes for a transformer. For the same 7B model at batch 4 and sequence 8K, activations alone can exceed 100 GB without checkpointing, far larger than the weights.
For short sequences and small batches, weight memory dominates and activations are a minor term. For long sequences (8K and up) and reasonable batch sizes (4 and up), activations become the largest single term. Even a 7B LoRA run has fixed state of little more than the 14 GB of bf16 weights. Activations are what makes it OOM on an 80 GB H100.
Gradient checkpointing is the technique specifically designed to collapse this activation term. It does not touch weights, gradients, or optimizer state. Its entire job is to reduce the activation footprint. That is why it is the right tool for long-context fine-tuning and the wrong tool for parameter-heavy short-context training.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- Hugging Face Trainer exposes gradient_checkpointing=True as a single config flag that enables per-layer checkpointing on standard transformer architectures.
- Long-context fine-tunes at 8K tokens routinely enable checkpointing, because activations at that length far outgrow the weights of a 7B base.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy is the compute cost of gradient checkpointing approximately 1.33x rather than 2x?
Count the passes. Without checkpointing: 1 forward + 1 backward. With checkpointing: 1 forward + 1 backward + 1 extra forward inside backward. A backward costs about twice a forward, so the baseline is about 3 forward-equivalents; one extra forward makes it 4, a ratio of 4/3.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Believing gradient checkpointing saves optimizer state or weight memory. It only reduces activation memory, the third memory term, by recomputing forward activations during backward.
60 second bullets to scan on the way to the call.
What memory term gradient checkpointing reduces (activations) and what it does not (weights, gradients, optimizer state)
How the recomputation mechanism works during forward and backward passes.
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.