Gradient checkpointing is a memory-for-compute trade-off technique used during neural network training. It reduces peak memory consumption by strategically saving only a subset of intermediate layer activations from the forward pass. The unsaved activations are recomputed on-demand during the backward pass when needed for gradient calculation. This selective checkpointing allows for the training of models that would otherwise exceed available GPU or accelerator memory, albeit at the cost of increased computational overhead.
Glossary
Gradient Checkpointing

What is Gradient Checkpointing?
Gradient checkpointing is a memory optimization technique 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, enabling the training of larger models.
The technique is governed by a checkpointing schedule that determines which activations to store. Common strategies include storing every n-th layer or using dynamic programming to find an optimal schedule. It is a form of recomputation and is fundamentally different from pruning or quantization, which alter the model itself. Gradient checkpointing is essential for training massive models, such as large language models (LLMs), and is often combined with other memory-saving techniques like mixed-precision training and model parallelism.
Key Characteristics of Gradient Checkpointing
Gradient checkpointing is a memory-for-compute trade-off technique that enables the training of neural networks that would otherwise exceed available GPU memory. It strategically manages which intermediate activations are stored during the forward pass.
The Core Trade-Off: Compute for Memory
Gradient checkpointing's fundamental principle is a time-memory trade-off. During the standard backpropagation algorithm, all intermediate activations from the forward pass must be stored to compute gradients, leading to memory usage that scales linearly with model depth. Checkpointing reduces peak memory consumption by selectively saving only a subset of these activations (the checkpoints). The unsaved activations are recomputed on-demand during the backward pass from the nearest checkpoint. This reduces memory usage from O(n) to O(√n) in a naive implementation, at the cost of approximately one additional forward pass per checkpoint segment.
Strategic Checkpoint Placement
The efficiency of gradient checkpointing is highly dependent on where checkpoints are placed. Common strategies include:
- Uniform Placement: Dividing the network into equal segments (e.g., place a checkpoint every 5 layers). Simple but often suboptimal.
- Memory-Budget-Aware Placement: Using a cost model to place checkpoints where recomputation cost is lowest relative to memory saved. Tools like PyTorch's
torch.utils.checkpointallow manual or automated placement. - Layer-Specific Strategies: Treating expensive, memory-intensive layers (e.g., attention blocks in Transformers) as natural checkpoints. The goal is to minimize the total wall-clock time penalty of recomputation while staying within a fixed memory budget.
Implementation in Modern Frameworks
Gradient checkpointing is natively supported in major deep learning frameworks with simple APIs:
- PyTorch:
torch.utils.checkpoint.checkpoint(function, *args)wraps a segment of the model. It accepts a recomputation function and its inputs. - TensorFlow:
tf.recompute_graddecorator or thetf.contrib.layers.recompute_gradfunction (in older versions). - JAX: The
jax.checkpoint(formerlyjax.remat) transformation, which is composable with other JAX transformations. A critical implementation detail is handling non-deterministic operations (e.g., dropout). Frameworks typically use a RNG state checkpointing mechanism to ensure identical recomputation.
Critical Use Case: Large Model Training
This technique is indispensable for training models whose memory footprint exceeds GPU VRAM. Key applications include:
- Training Very Deep Networks: Enabling research on architectures with hundreds or thousands of layers.
- Large Batch Sizes: Allowing for larger effective batch sizes on memory-constrained hardware, which can improve training stability.
- Transformer Models: The self-attention mechanism in models like GPT or BERT has a memory cost that scales quadratically with sequence length. Checkpointing the attention computation is often essential for long-sequence training.
- Scientific Computing: Training Physics-Informed Neural Networks (PINNs) or other models where the computational graph is exceptionally deep due to iterative solvers.
Performance and Overhead Analysis
The overhead of gradient checkpointing is not uniform and must be carefully evaluated:
- Theoretical Overhead: In an optimal setup with √n checkpoints for an n-layer network, the recomputation adds the equivalent of one extra forward pass, increasing total compute by ~33% (1 forward + 1 backward normally, becomes 2 forward + 1 backward).
- Practical Slowdown: Real-world slowdown is typically between 20% and 40%, depending on checkpoint placement, hardware, and the ratio of computation to memory bandwidth.
- Memory Reduction: Peak memory can be reduced by 50-80%, which is the enabling factor. The trade-off is always justified when the alternative is an out-of-memory (OOM) error or severe batch size limitation.
Relationship to Other Compression Techniques
Gradient checkpointing is complementary to other model compression and optimization techniques:
- Vs. Quantization/Pruning: Checkpointing optimizes training-time memory, while quantization and pruning optimize inference-time memory and speed of the final model. They are often used in sequence: checkpoint to train a large model, then prune/quantize for deployment.
- Synergy with Parallelism: It is frequently combined with model parallelism (splitting layers across GPUs) and pipeline parallelism (where checkpoints naturally align with pipeline stage boundaries).
- Foundation for Advanced Methods: Concepts from checkpointing inform more advanced memory-saving techniques like offloading (moving activations to CPU RAM) and recomputation-aware scheduling in compilers.
Gradient Checkpointing vs. Other Memory Techniques
A comparison of techniques used to reduce memory consumption during the training of deep neural networks, highlighting trade-offs between memory, compute, and implementation complexity.
| Feature / Metric | Gradient Checkpointing | Micro-Batching | Offloading to CPU RAM | Model Parallelism |
|---|---|---|---|---|
Primary Mechanism | Selectively saves activations; recomputes others during backward pass | Splits a batch into smaller sequential chunks | Moves inactive tensors (e.g., optimizer states) from GPU to CPU memory | Distributes model layers across multiple GPUs/devices |
Memory Reduction Target | Activation memory (peak during backward pass) | Activation memory (per micro-batch) | Optimizer state and gradient memory | Model parameter and activation memory |
Compute Overhead | High (significant recomputation of forward passes) | Low (minimal extra computation, some pipeline bubbles) | Medium (PCIe transfer latency for swapped tensors) | High (communication overhead between devices) |
Implementation Complexity | Medium (requires identifying checkpoint layers; framework support varies) | Low (standard data loader modification) | Medium (requires manual tensor management or library like DeepSpeed) | High (requires significant model refactoring and communication logic) |
Optimal Use Case | Training very deep models where activation memory is the bottleneck | Training with large batch sizes on memory-constrained hardware | Training extremely large models where optimizer states dominate memory | Training models too large to fit on a single device's memory, even for a single sample |
Hardware Requirement | Single GPU (or data parallelism); maximizes usable model size per GPU | Single GPU; enables larger effective batch sizes | Single GPU with substantial CPU RAM available | Multiple GPUs with high-bandwidth interconnects (e.g., NVLink) |
Framework Support | Native in PyTorch ( | Manual implementation or pipeline parallelism libraries | Libraries: DeepSpeed (ZeRO-Offload), PyTorch (manual | Native: PyTorch ( |
Compatibility with Other Techniques | High (often combined with quantization, pruning, and data parallelism) | High (can be combined with gradient accumulation) | High (core component of full Zero Redundancy Optimizer (ZeRO) stages) | Medium (can be combined with pipeline parallelism; complex with checkpointing) |
Frequently Asked Questions
Gradient checkpointing is a critical memory optimization technique for training large neural networks. It strategically trades increased computation for reduced memory consumption, enabling the training of models that would otherwise exceed GPU memory limits.
Gradient checkpointing is a memory optimization technique that trades compute for memory by selectively saving only a subset of layer activations during the forward pass and recomputing the non-checkpointed activations during the backward pass. During the standard forward pass, the algorithm saves the activations from only certain designated 'checkpoint' layers (e.g., every k-th layer). The activations from intermediate, non-checkpointed layers are discarded after use. During the backward pass, when gradients for a segment between two checkpoints are needed, the forward pass for that segment is re-executed from the last saved checkpoint. This recomputation regenerates the necessary intermediate activations on-demand for gradient calculation, after which they are discarded again. The primary trade-off is a 20-30% increase in total computation time for a typical 50% or greater reduction in peak memory usage.
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 one of several memory-centric optimization techniques. These related methods focus on reducing the computational footprint of neural networks for efficient training and deployment.
Activation Recomputation
Activation recomputation is the core mechanism behind gradient checkpointing. During the forward pass, only a strategically chosen subset of layer outputs (checkpoints) are stored in memory. The non-checkpointed activations are discarded and then recomputed on-demand during the backward pass when needed for gradient calculation. This creates a fundamental trade-off between memory and compute, as recomputation adds significant floating-point operations (FLOPs) but can reduce peak memory consumption by 50-80%.
- Key Benefit: Enables training of models that are 2-5x larger than GPU memory would normally allow.
- Implementation: Frameworks like PyTorch provide
torch.utils.checkpointandtorch.cuda.checkpointAPIs to automate this process.
Model Parallelism
Model parallelism is a distributed training strategy that partitions a single model's layers across multiple devices (e.g., GPUs). When combined with gradient checkpointing, it enables the training of extremely large models (e.g., with hundreds of billions of parameters).
- How it works: Different layers of the network are placed on different GPUs. Activations and gradients are passed between devices during the forward and backward passes.
- Synergy with Checkpointing: Checkpointing is often applied within each model-parallel segment to further reduce the memory footprint on each individual device. This combination is foundational to training modern large language models (LLMs).
- Contrast with Data Parallelism: Data parallelism replicates the entire model on each device and splits the batch of data, whereas model parallelism splits the model itself.
Mixed Precision Training
Mixed precision training is a memory optimization technique that uses lower-precision numerical formats (like 16-bit floating-point, or FP16/BF16) for most operations while keeping a master copy of weights in 32-bit precision for stability. It is highly complementary to gradient checkpointing.
- Memory Reduction: Using FP16/BF16 halves the memory required for storing activations and weights compared to standard FP32.
- Combined Strategy: In practice, gradient checkpointing and mixed precision are used together. Checkpointing reduces the number of activations stored, and mixed precision reduces the size of each stored activation. This compound effect is critical for training state-of-the-art models.
- Hardware Acceleration: Modern GPUs (NVIDIA Tensor Cores, AMD Matrix Cores) perform lower-precision operations much faster, providing a simultaneous speedup.
Rematerialization
Rematerialization is a compiler-level term synonymous with activation recomputation. It refers to the process of recalculating a value that was previously computed but not stored. In deep learning frameworks, the checkpointing scheduler performs optimal rematerialization.
- Scheduling Problem: The core challenge is deciding which activations to store and which to recompute to minimize the total computational cost under a fixed memory budget. This is an NP-hard problem.
- Algorithms: Heuristics and cost models are used, such as Chen's algorithm, which treats the computational graph as a series of segments. More advanced methods use dynamic programming to find near-optimal checkpointing plans for arbitrary graphs.
- Beyond Training: The concept is also used in just-in-time (JIT) compilers for automatic differentiation, like those in JAX and TensorFlow.
CPU Offloading
CPU Offloading is an alternative memory optimization technique where tensors (like optimizer states, gradients, or even activations) are moved from GPU memory to host (CPU) RAM when not immediately needed, and fetched back for computation.
- Comparison with Checkpointing: Both techniques increase training time to save GPU memory. Checkpointing trades memory for extra compute (recomputation). CPU offloading trades memory for extra communication (PCIe data transfer).
- Hybrid Approaches: Systems like DeepSpeed ZeRO-Offload combine CPU offloading of optimizer states with gradient checkpointing of activations for extreme memory savings, enabling multi-billion parameter model training on a single GPU.
- Use Case: Often more effective than pure checkpointing when the model has massive parameter states but a relatively shallow computational graph.
Selective Activation Recomputation
Selective activation recomputation is an advanced form of gradient checkpointing that makes fine-grained decisions about which specific operations within a layer to recompute, rather than treating entire layers as atomic checkpoints.
- Mechanism: It exploits the fact that some intermediate tensors within a layer (e.g., the output of a non-linear activation like GELU) are cheaper to recompute than others (e.g., the output of a large matrix multiplication).
- Memory/Compute Pareto Frontier: This granularity allows for a better trade-off, achieving greater memory savings for a given amount of extra compute, or less compute overhead for a given memory budget.
- Framework Support: Implementing selective recomputation often requires manual annotation of the computational graph or support from advanced frameworks that can perform fine-grained automatic differentiation.

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