Gradient Checkpointing is a memory optimization technique for training deep neural networks that trades compute for memory by selectively saving only a subset of layer activations during the forward pass and recomputing the others during the backward pass. This strategic recomputation dramatically reduces the peak memory required to store intermediate results, enabling the training of models that are significantly larger than the available GPU or NPU memory. The technique is a form of time-memory trade-off, where increased computational cost is accepted to alleviate a critical memory bottleneck.
Glossary
Gradient Checkpointing

What is Gradient Checkpointing?
Gradient Checkpointing is a fundamental technique for training deep neural networks on memory-constrained hardware.
The process works by designating specific layers as checkpoints. During the forward pass, only the outputs of these checkpoint layers are stored in memory. During the backward pass, when gradients for a non-checkpoint layer are needed, the forward computation is re-executed from the nearest upstream checkpoint. This is managed by the autograd engine in frameworks like PyTorch. It is particularly crucial for training large Transformer models with long sequence lengths, where activation memory scales quadratically with context size, and is a key enabler for hardware-aware model optimization on specialized accelerators like NPUs.
Key Characteristics of Gradient Checkpointing
Gradient Checkpointing is a memory-for-compute trade-off technique that enables the training of deeper neural networks by strategically managing which intermediate activations are stored during the forward pass.
Core Trade-Off: Memory vs. Compute
Gradient Checkpointing fundamentally trades increased computation for reduced memory consumption. During the standard backpropagation algorithm, all intermediate layer activations from the forward pass must be stored to compute gradients, leading to O(n) memory complexity with network depth (n). Checkpointing reduces this to O(√n) by storing only a subset of activations (checkpoints) and recomputing the non-checkpointed activations on-demand during the backward pass. This recomputation is the source of the ~30% typical compute overhead.
Selective Activation Storage
Not all layer outputs are treated equally. The technique involves a strategic policy for selecting which activations to save as checkpoints. Common policies include:
- Uniform: Save every k-th layer's output.
- Dynamic (Optimal): Use a dynamic programming algorithm to minimize total recomputation cost for a given memory budget.
- Heuristic-based: Prioritize layers with large output tensors or high computational cost to recompute. The saved checkpoints act as 'anchor points' from which the forward pass can be re-executed in segments during backpropagation.
Recomputation on Demand
This is the computational engine of the technique. During the backward pass, when gradients for a non-checkpointed layer are needed, the system:
- Identifies the nearest upstream checkpoint.
- Re-executes the forward pass from that checkpoint to the required layer.
- Computes the local gradients using these freshly recomputed activations.
- Discards the recomputed activations after use. This process eliminates the need to store the entire activation history, but requires the forward pass to be run multiple times for different segments of the network.
Implementation in Frameworks
Modern deep learning frameworks provide built-in support, abstracting the complexity.
- PyTorch:
torch.utils.checkpoint.checkpointandtorch.utils.checkpoint.checkpoint_sequentialwrap model segments. It uses a custom autograd Function that reruns the forward pass in the backward hook. - TensorFlow:
tf.recompute_graddecorator or thetf.contrib.layers.recompute_gradfunction (in older TF 1.x). - JAX:
jax.checkpoint(formerlyjax.remat) is a core transformation that performs gradient checkpointing. These APIs allow developers to annotate which parts of their model should use checkpointing, often at the level of individual transformer blocks or residual groups.
Primary Use Case: Large Models & Long Sequences
Checkpointing is indispensable in specific high-memory scenarios:
- Training Very Deep Networks: Enables models with hundreds or thousands of layers that would otherwise exceed GPU memory.
- Long Sequence Processing: Critical for Transformer models with long context windows, where the self-attention mechanism's memory footprint grows quadratically with sequence length. Checkpointing the attention computation is often combined with memory-efficient attention algorithms like Flash Attention.
- Large Batch Sizes: Allows for increased batch sizes within a fixed memory budget, which can improve training stability and utilization. It is a standard technique in large language model (LLM) and large vision model training pipelines.
Interaction with Parallelism Strategies
Gradient Checkpointing interacts closely with distributed training methods:
- Pipeline Parallelism: Essential for making pipeline bubbles manageable. Checkpointing is applied within each pipeline stage to reduce the memory footprint of activations stored for the backward pass across micro-batches.
- Model & Tensor Parallelism: While these split the model parameters, the per-device activation memory can still be prohibitive. Checkpointing is used in conjunction to train even larger models.
- ZeRO Optimizer Stages: Used with ZeRO Stage 2 (partitioned gradients) and Stage 3 (partitioned parameters) to further push the boundaries of model size by reducing activation memory, which ZeRO does not address.
Gradient Checkpointing vs. Other Memory Optimization Techniques
A technical comparison of memory reduction strategies for training large neural networks, highlighting trade-offs between memory, compute, and implementation complexity.
| Technique / Feature | Gradient Checkpointing | Activation Recomputation | Model Parallelism | Zero Redundancy Optimizer (ZeRO) |
|---|---|---|---|---|
Primary Goal | Reduce peak activation memory | Reduce peak activation memory | Distribute model parameters across devices | Eliminate memory redundancy in data-parallel training |
Memory Savings Source | Activations | Activations | Model Parameters & Activations | Optimizer States, Gradients, Parameters |
Compute Overhead | High (33-50% extra FLOPs) | Very High (2x forward passes) | Moderate (Communication latency) | Low to Moderate (Communication volume) |
Communication Overhead | None (single device) | None (single device) | High (inter-device per layer) | Moderate (inter-device per optimizer step) |
Implementation Complexity | Moderate (framework support) | Low (manual checkpoint placement) | High (model partitioning logic) | High (integration with training framework) |
Transparency to Model Code | High (often automatic) | Low (requires manual code changes) | Low (requires model restructuring) | High (often automatic via optimizer wrapper) |
Best Suited For | Single-device training of very deep networks | Extreme memory constraints on a single device | Models too large for any single device's memory | Large-scale data-parallel training across many devices |
Typical Memory Reduction | √(n) vs. n layers (e.g., 10x for 100 layers) | Up to ~n vs. n layers | Linear with number of devices | Up to 8x for Adam optimizer states |
Frameworks and Libraries Supporting Gradient Checkpointing
Gradient checkpointing is implemented as a core memory optimization feature within major deep learning frameworks and specialized libraries, enabling the training of models that exceed single-device memory capacity.
Frequently Asked Questions
Gradient Checkpointing is a memory-for-compute trade-off technique essential for training large neural networks on hardware with limited memory, such as Neural Processing Units (NPUs). This FAQ addresses its core mechanisms, trade-offs, and implementation.
Gradient Checkpointing is a memory optimization technique for training deep neural networks that trades increased computational cost for reduced memory consumption by selectively saving only a subset of layer activations during the forward pass and recomputing the non-saved activations during the backward pass.
During standard backpropagation, all intermediate activations from the forward pass must be stored to compute gradients, leading to memory usage that scales linearly with model depth and batch size. Gradient Checkpointing strategically designates certain layers as checkpoints. Only the activations at these checkpoints are stored; the activations for the layers between checkpoints are discarded after the forward pass and must be recomputed during the backward pass when they are needed for gradient calculation. This reduces peak memory usage from O(n) to O(√n) in a naive implementation, where n is the number of layers, enabling the training of models that would otherwise exceed accelerator memory limits.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Gradient Checkpointing is a key technique within the broader discipline of hardware-aware optimization. These related concepts focus on managing the critical trade-offs between memory, compute, and communication during model training and inference.
Activation Recomputation
The core computational mechanism behind Gradient Checkpointing. During the backward pass, the intermediate layer activations that were not saved are recomputed from the nearest stored checkpoint. This process trades extra forward-pass compute for significantly reduced memory consumption.
- Checkpoint Selection: Strategic placement of checkpoints (e.g., every sqrt(n) layers) balances recomputation cost and memory savings.
- Implementation: Frameworks like PyTorch provide
torch.utils.checkpointfor manual or automatic application.
Memory-Bound vs. Compute-Bound
A fundamental hardware performance dichotomy critical to understanding when to apply Gradient Checkpointing. A workload is memory-bound when its speed is limited by data movement bandwidth, or compute-bound when limited by arithmetic throughput.
- Gradient Checkpointing Trade-off: It converts a memory-bound problem (storing all activations) into a compute-bound one (recomputing them).
- Analysis Tool: The Roofline Model is used to diagnose this bound and guide optimization strategy.
Zero Redundancy Optimizer (ZeRO)
A complementary memory optimization technique for distributed data-parallel training. While Gradient Checkpointing reduces activation memory, ZeRO partitions the optimizer states, gradients, and model parameters across devices.
- ZeRO Stages:
- Stage 1: Partition optimizer states.
- Stage 2: Partition gradients.
- Stage 3: Partition model parameters.
- Combined Use: ZeRO and Gradient Checkpointing are often used together to train models with trillions of parameters.
Operator Rematerialization
The compiler-level equivalent of activation recomputation, applied during graph compilation for inference. The compiler analyzes the computational graph and decides which intermediate tensor values to discard and later recompute to minimize peak memory usage.
- Scope: Operates at the granularity of individual operators or subgraphs within a static graph.
- Goal: Enables the execution of larger models or batches on memory-constrained accelerators (NPUs, GPUs).
Pipeline Parallelism
A distributed training strategy that partitions model layers across multiple devices. Gradient Checkpointing is essential for efficient pipeline parallelism, as it reduces the memory footprint of each pipeline stage, allowing for more layers per device or larger micro-batches.
- Bubble Overhead: Idle time in the pipeline. Checkpointing can influence bubble size by changing stage memory/compute profiles.
- Interplay: Techniques like the PipeDream scheduler integrate checkpointing to manage memory across sequential stages.
Flash Attention
An I/O-aware algorithm that optimizes the memory footprint of the attention mechanism in Transformers. While Gradient Checkpointing is a general technique, Flash Attention is a domain-specific kernel optimization that also uses recomputation.
- Key Similarity: Both trade extra FLOPs for reduced HBM (High-Bandwidth Memory) accesses.
- Key Difference: Flash Attention is an exact, mathematically reformulated algorithm for a specific operation, while Gradient Checkpointing is a generic, coarse-grained strategy for an entire network graph.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us