Zenaique

Gradient checkpointing, what does it trade, and roughly by how much?

Flashcard·Easy·4.0 · 0·~30s·Asked atAi21DatadogStripe·Relevant atDatabricks
Attempt it
TL;DR

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.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

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. Activation 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 dramatic: 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.

Gradient checkpointing is the cleanest example of a memory versus compute tradeoff in deep learning training. The technique is conceptually simple, the implementation is a few lines, and the impact on training feasibility is enormous: it routinely turns OOM crashes into successful runs at the cost of about a third of throughput.

The mechanism rests on a basic observation about backpropagation. The backward pass needs the forward-pass activations to compute gradients, which 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.

This deep dive walks through what activations actually cost in transformer training, the precise recomputation mechanism, the typical magnitudes on both sides of the tradeoff, the segment granularity and reentrant-flag decisions, and the interactions with FlashAttention and ZeRO-3 that determine how well the technique composes with the rest of the modern training stack.

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 run 30 to 50 GB, comparable to or larger than 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, and they are what makes a 7B model OOM on an 80 GB H100 even when full-FT could theoretically fit.

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, which is why it is the right tool for long-context fine-tuning and the wrong tool for parameter-heavy short-context training.

The recomputation mechanism in detail
Typical magnitudes and segment granularity
Composition with FlashAttention, ZeRO-3, and the reentrant flag
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

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.
  • Production Llama 4 Maverick fine-tunes at 8K context routinely enable checkpointing to fit activations alongside the 70B base on 4xH100.
Sign in to see more production examples.

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?
A

Count the passes. Without checkpointing: 1 forward + 1 backward. With checkpointing: 1 forward + 1 backward + 1 extra forward inside backward. Each pass is roughly the same FLOPs, so the ratio is 3/2 of the forward+backward, or 4/3 of the original total.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Believing gradient checkpointing saves optimizer state or weight memory. It only reduces activation memory, the third memory term, by recomputing forward activations during backward.

Sign in to see all red flags and common mistakes.

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.

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
What is RLHF, and why is it used after pretraining?
MCQ·Easy