Inferensys

Glossary

Activation Recomputation (Checkpointing)

Activation recomputation, also known as gradient checkpointing, is a memory optimization technique that trades off computation for memory by selectively discarding and later recalculating intermediate activations during the backward pass of training.
ML engineer managing model training cluster on laptop, GPU utilization visible, technical deep learning setup.
GRAPH COMPILATION STRATEGIES

What is Activation Recomputation (Checkpointing)?

Activation recomputation, also known as gradient checkpointing, is a fundamental memory optimization technique in neural network training.

Activation recomputation (checkpointing) is a memory-for-computation trade-off technique where selected intermediate activations from the forward pass of neural network training are deliberately discarded and later recalculated during the backward pass to compute gradients. This strategy dramatically reduces the peak memory required to store the computational graph's state, enabling the training of deeper models or larger batch sizes on memory-constrained hardware like NPUs and GPUs. The compiler strategically selects which activations to checkpoint to minimize the recomputation overhead.

The technique is implemented during graph compilation by inserting special checkpointing operators. During execution, the forward pass stores only these checkpointed tensors. In the backward pass, the system recomputes the non-checkpointed activations in segments, starting from the nearest stored checkpoint. This approach is critical for large language model (LLM) training and is a key component of hardware-aware model optimization, allowing frameworks to adapt to specific accelerator memory hierarchies.

GRAPH COMPILATION STRATEGIES

Key Characteristics of Activation Recomputation

Activation recomputation (checkpointing) is a memory-for-compute trade-off technique used during neural network training. It strategically discards intermediate activation tensors in the forward pass and recalculates them during the backward pass to compute gradients.

01

Memory-for-Compute Trade-off

The core principle of activation recomputation is a direct trade: it reduces peak memory consumption at the cost of increased computational FLOPs. Instead of storing all intermediate activations for the entire forward pass, only a subset (checkpoints) is saved. The discarded activations are recomputed on-demand during backpropagation from the nearest checkpoint. This is critical for training very large models that would otherwise exceed GPU or NPU memory limits.

02

Selective Checkpoint Placement

Not all layers are checkpointed. Optimal placement is determined by a cost model that analyzes:

  • Tensor Size: Larger activations are prime candidates for discarding.
  • Recomputation Cost: The FLOPs required to recompute the subgraph.
  • Memory Budget: The target peak memory reduction.

Common strategies include checkpointing every N layers or placing checkpoints at the boundaries of memory-intensive operations (e.g., after large matrix multiplications).

03

Subgraph Recomputation

When the backward pass reaches a point where a needed activation has been discarded, the compiler re-executes a segment of the forward pass. This is not a full model rerun but a targeted recomputation of a subgraph defined between two checkpoints. The compiler must manage this execution context, ensuring inputs are available and the recomputed tensors are identical to the original forward pass values for correct gradient calculation.

04

Compiler-Driven Automation

Modern ML compilers (e.g., PyTorch's torch.utils.checkpoint, XLA) automate activation recomputation. The compiler:

  1. Analyzes the computational graph to identify candidate regions.
  2. Inserts checkpoint and recompute nodes into the IR.
  3. Schedules the forward/backward/recompute operations to ensure correctness and minimize overhead.

This allows developers to apply the technique with minimal code changes, often via a simple decorator or context manager.

05

Impact on Training Throughput

The primary trade-off is increased wall-clock time per training iteration. The recomputation of forward segments can add 20-30% overhead. However, this is often preferable to the alternative: model parallelism or offloading to CPU RAM, which can introduce even greater latency due to communication. The technique enables batch size scaling within fixed memory, which can sometimes offset the recomputation cost by improving gradient signal.

06

Relation to Graph Fusion & Memory Planning

Activation recomputation interacts closely with other graph compilation strategies:

  • Graph Fusion: Recomputation boundaries can affect fusion opportunities. Fused kernels that span a checkpoint may need to be split.
  • Memory Planning: The compiler's memory allocator must manage the lifetime of checkpointed tensors and the temporary buffers for recomputation. Advanced planning can reuse memory between discarded activations and recomputation buffers.
  • Operator Reordering: Independent ops may be reordered to create more favorable subgraphs for recomputation.
MEMORY OPTIMIZATION COMPARISON

Activation Recomputation vs. Alternative Memory Optimization Techniques

This table compares activation recomputation (checkpointing) with other major techniques for reducing memory footprint during neural network training, highlighting trade-offs in compute, memory, and implementation complexity.

Feature / MetricActivation Recomputation (Checkpointing)Gradient AccumulationModel ParallelismMixed-Precision Training (FP16)

Primary Optimization Target

Peak activation memory

Batch size memory

Model parameter memory

Activation & parameter memory

Mechanism

Discards & recomputes selected activations during backward pass

Accumulates gradients over multiple micro-batches before updating weights

Distributes model layers across multiple devices

Uses lower numerical precision (e.g., FP16) for weights and activations

Memory Reduction (Typical)

30-70%

Linear with micro-batch count

Near-linear with device count

~50%

Compute Overhead

30-50% extra FLOPs

< 1%

5-20% (communication)

0-5% (with tensor cores)

Implementation Complexity

High (requires compiler/runtime integration)

Low (framework-level)

Very High (model architecture changes)

Medium (framework support required)

Communication Overhead

None

None

High (inter-device communication)

None

Optimal Use Case

Memory-bound training of very large models

Simulating large effective batch sizes

Models too large for a single device

Throughput-optimized training on supported hardware (e.g., NVIDIA Tensor Cores)

Compiler/Runtime Support Required

Transparent to Model Code

GRAPH COMPILATION STRATEGIES

Activation Recomputation (Checkpointing)

Activation recomputation, also known as gradient checkpointing, is a memory optimization technique that trades off computation for memory by selectively discarding and later recalculating intermediate activations during the backward pass of training.

01

Core Mechanism

Activation recomputation works by strategically discarding the outputs (activations) of certain layers during the forward pass of neural network training. During the backward pass, when gradients are needed for those discarded activations, the system re-executes a segment of the forward pass to regenerate them. This creates a fundamental trade-off: reduced memory footprint for storing activations versus increased computational cost due to the extra forward passes.

  • Checkpoint Selection: The compiler decides which layers to checkpoint. Common strategies include checkpointing every n-th layer or using a dynamic cost model.
  • Recomputation Granularity: Can be performed at the level of individual operators, subgraphs, or entire network segments.
02

Memory vs. Compute Trade-off

The primary value proposition is trading abundant compute for scarce memory. For a network with L layers, the naive approach stores all L activations, leading to O(L) memory complexity. With optimal checkpointing, peak memory can be reduced to O(√L) while increasing total FLOPs by approximately 30-40%.

  • Peak Memory Reduction: Critical for training very large models (e.g., LLMs, diffusion models) that would otherwise exceed GPU VRAM.
  • Overhead Calculation: The recomputation overhead is not uniform; it depends on the placement of checkpoints and the computational cost of the recomputed subgraph.
03

Implementation in Frameworks

Major deep learning frameworks provide APIs and compiler passes to implement activation recomputation automatically or via user annotations.

  • PyTorch: torch.utils.checkpoint.checkpoint function wraps a network segment. The torch.compile API with fullgraph=True can enable more aggressive, compiler-managed checkpointing.
  • TensorFlow/JAX: Similar functionality via tf.recompute_grad decorator or jax.checkpoint (formerly jax.remat).
  • Compiler Integration: In graph compilers like XLA (for JAX/TensorFlow) and TorchInductor (for PyTorch), checkpointing decisions are often made during the graph lowering and fusion passes, considering the target hardware's memory hierarchy.
04

NPU-Specific Optimizations

On Neural Processing Units, activation recomputation must be co-designed with other graph compilation strategies to account for unique hardware constraints.

  • Fusion-Aware Checkpointing: The compiler must decide whether to checkpoint before or after a fused kernel. Recomputation a fused kernel is efficient but may regenerate more data than needed.
  • Memory Hierarchy Alignment: Checkpoints can be placed to minimize expensive transfers between NPU global memory and on-chip SRAM/cache. The goal is to keep actively recomputed tensors in faster memory.
  • Pipeline Interleaving: In training pipelines, recomputation can be scheduled to overlap with other operations (e.g., communication, weight updates) to hide its latency.
05

Checkpointing Strategies

Different algorithmic strategies determine which activations to save and which to recompute.

  • Uniform Checkpointing: Saves activations at regular intervals (e.g., every 5 layers). Simple but often suboptimal.
  • Optimal Checkpointing (Chen et al.): A dynamic programming algorithm that minimizes recomputation FLOPs for a given memory budget. It has O(L²) complexity for a graph of L layers.
  • Greedy Heuristics: Runtime or compile-time heuristics that estimate the memory cost of saving an activation versus the compute cost of recomputing it.
  • Subgraph Checkpointing: Treats a connected subgraph of operators as a single unit for checkpointing, which can be more efficient than per-operator decisions.
06

Related Compiler Techniques

Activation recomputation interacts closely with other graph compilation passes.

  • Operator Reordering: Independent operations may be reordered to create larger, more efficient subgraphs for checkpointing.
  • Memory Planning: The compiler's memory allocator must account for the transient buffers needed during recomputation phases.
  • Common Subexpression Elimination (CSE): If the same subgraph is recomputed multiple times during backward pass, CSE can cache the result.
  • Static vs. Dynamic: Decisions can be made statically at compile time (AOT) or dynamically at runtime (JIT), with static planning allowing for more aggressive global optimization.
ACTIVATION RECOMPUTATION

Frequently Asked Questions

Activation recomputation, also known as gradient checkpointing, is a critical memory optimization technique in neural network training. It strategically trades increased computation for reduced memory consumption, enabling the training of larger models or the use of larger batch sizes on hardware with limited memory.

Activation recomputation, also known as gradient checkpointing, is a memory optimization technique for training deep neural networks. During the forward pass, it selectively discards (does not store) certain intermediate layer activations in GPU or NPU memory. During the subsequent backward pass, when these discarded activations are required to compute gradients, they are recomputed on-the-fly via a partial re-execution of the forward pass. This creates a fundamental trade-off: it reduces peak memory usage at the cost of increased computational overhead.

For example, in a 100-layer network, a naive implementation stores all 100 layers' activations. With checkpointing, you might store only every 10th layer's activation. To get the activation for layer 95 during the backward pass, the system re-runs the forward pass from the last stored checkpoint (layer 90) up to layer 95.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.