Activation Checkpointing
Activation checkpointing (also called gradient checkpointing or recomputation) is a classic technique for trading extra compute for memory when training deep networks. It stores only a few intermediate activations during the forward pass and recomputes the discarded activations during backpropagation, thereby reducing activation memory from scaling with the number of layers to depending on the number of checkpoints.
Core Principles
Conventional backpropagation must keep the intermediate activations of every layer because the chain rule needs them. Taking the Transformer as an example, the attention matrices and the intermediate results of the feed-forward network in each layer are large, and once there are many layers, activations become the main memory consumer, usually far exceeding the model weights themselves. The idea of checkpointing is: save activations only at certain layer boundaries as checkpoints, and discard the layers between checkpoints as soon as their forward computation finishes. When backpropagation reaches a segment, it first re-executes a forward pass from this checkpoint to rebuild the activations in that segment, then performs the backward computation for the segment.
The cost is extra forward computation; in the most extreme case the total compute increases by roughly one third over the original, because each segment's forward pass has to be run once more. In practice recomputation is usually applied only to the memory-heavy parts, such as the attention and feed-forward layers, while activations are kept for cheap parts such as layer normalization.
Key Points
First, a selective strategy is key. Full recomputation saves the most memory but is slowest; selective recomputation recomputes only large tensors, striking a good balance between memory and throughput, and mainstream frameworks offer per-module switches. Second, it is complementary to pipeline parallelism. Each device in a pipeline holds only some layers, and recomputation further lowers the single-GPU activation peak, making larger micro-batches possible. Third, when combined with ZeRO or tensor parallelism the memory budget must be recalculated, since each technique shares a different part. Fourth, recomputation converts memory pressure into compute pressure, which pays off most when compute is abundant and memory constrained, for example high-bandwidth GPUs with small memory, long-sequence training and large micro-batch training.
Common Misconceptions
Misconception one: thinking recomputation saves weight memory. It saves activation memory; weights still have to be stored according to the parallel scheme. Misconception two: thinking full recomputation is mandatory; in fact selective schemes often have a better cost-performance ratio. Misconception three: ignoring the inconsistency that randomness brings to recomputation; when dropout is involved, random seeds must be fixed or the implementation adjusted.
Application Scenarios
Long-context training, full-parameter fine-tuning of large models, batch enlargement under memory constraints, training with high-resolution multimodal inputs, and single-GPU memory optimization for very large models.
In quantitative terms, the space complexity of recomputation can be roughly described as follows: if the network is divided into segments, each keeping only its entry activations, then activation memory is proportional to the number of segments and independent of the number of layers, while compute increases by roughly the cost of one extra forward pass. In actual configurations, the segment size is commonly one to four layers, or split along module boundaries. For attention layers, whose intermediate tensors are huge, recomputing them alone yields the highest benefit.
Recent improvements include on-demand and sparse recomputation: recompute only the operators that contribute most to the memory peak and keep activations for small operators; some research also combines recomputation with offloading, moving temporarily unused activations to host memory or even solid-state disks, which works better when bandwidth allows. In addition, with the advent of sequence parallelism and context parallelism, each GPU carries fewer activations and recomputation is less necessary in some scenarios, but long-context training still depends on it.