Gradient checkpointing is a memory optimization technique for training deep neural networks that trades increased computation for reduced memory consumption by selectively storing only a subset of layer activations during the forward pass. The non-checkpointed activations are recomputed on-demand during the backward pass when their gradients are needed. This strategic recomputation dramatically lowers the peak memory required to store the computational graph, enabling the training of models that would otherwise exceed hardware memory limits.
Glossary
Gradient Checkpointing

What is Gradient Checkpointing?
Gradient checkpointing is a memory-for-compute trade-off technique used during the training of deep neural networks.
The technique is governed by a checkpointing schedule that determines which intermediate tensors to save. Optimal schedules, often placed at evenly spaced intervals, minimize the total recomputation cost. It is a fundamental tool in hardware-aware model design, allowing engineers to co-design algorithms for specific silicon constraints. By controlling the memory-compute trade-off, it is essential for training large models like transformers on limited hardware, including in small language model engineering pipelines targeting edge deployment.
Key Characteristics of Gradient Checkpointing
Gradient checkpointing is a memory-for-compute trade-off technique essential for training large models on memory-constrained hardware. Its core characteristics define its applicability and performance profile.
Memory-For-Compute Trade-Off
Gradient checkpointing fundamentally trades increased computation for reduced memory consumption. During the forward pass, only a strategically selected subset of layer activations are stored in memory (the 'checkpoints'). All other intermediate activations are discarded. During the backward pass, these discarded activations are recomputed on-demand from the nearest stored checkpoint. This reduces peak memory usage from O(n) to O(√n) for a chain of n layers, at the cost of approximately one additional forward pass worth of computation.
Selective Activation Storage
Not all activations are checkpointed. The algorithm determines an optimal subset to store, minimizing both memory and recomputation overhead.
- Common Strategies: Checkpointing every k-th layer, or using dynamic programming to find the optimal pattern for a given computational graph.
- Impact: The choice directly controls the trade-off curve. More frequent checkpoints reduce recomputation but increase memory; fewer checkpoints maximize memory savings but increase FLOPs.
- Example: In a 100-layer network, storing only 10 checkpoints can reduce activation memory by ~90%, but requires recomputing 90% of the forward pass during backpropagation.
Recomputation Overhead
The primary cost of gradient checkpointing is the recomputation of non-checkpointed activations during backpropagation. This is not free:
- Computational Cost: Typically adds 30-40% more forward-pass FLOPs to the total training step, effectively increasing epoch time.
- Implementation: The backward pass traverses the graph, and when it reaches a layer whose input activation was not saved, it re-executes the forward pass segment from the prior checkpoint.
- Trade-off Analysis: The technique is beneficial when memory is the limiting bottleneck, and extra compute is available. It becomes inefficient if the recomputation cost overwhelms any memory-bound speedups.
Enables Larger Models & Batch Sizes
By drastically reducing the memory footprint of activations, gradient checkpointing allows for two critical scaling maneuvers:
- Training Larger Models: Networks with more parameters or layers can be trained on a fixed GPU memory budget (e.g., fitting a 20B parameter model on a 40GB A100).
- Increasing Batch Size: For a given model size, freed memory can be allocated to larger batch sizes, improving statistical efficiency and training stability.
- Practical Limit: The technique does not reduce memory for model parameters or optimizer states; these remain the ultimate limit for model size on a device.
Integration with Model Parallelism
Gradient checkpointing is often combined with model parallelism strategies to train extremely large models.
- Pipeline Parallelism: Checkpointing is crucial for reducing the memory of activations stored between pipeline stages, lowering the 'pipeline bubble' and improving hardware utilization.
- Tensor Parallelism: While less directly coupled, checkpointing still reduces activation memory within each parallelized device.
- Synergy: Used together, these techniques allow for the training of models far exceeding the memory of any single accelerator, forming the backbone of modern large language model training frameworks like Megatron-LM and DeepSpeed.
Compiler & Framework Support
Modern deep learning frameworks provide automated or semi-automated gradient checkpointing, abstracting the complexity from the user.
- PyTorch:
torch.utils.checkpoint.checkpointandtorch.utils.checkpoint.checkpoint_sequentialwrap model segments to apply checkpointing. - TensorFlow: Similar functionality via
tf.recompute_grad. - Compiler Integration: Advanced compilers like Torch Dynamo (PyTorch 2.0+) and XLA can automatically apply checkpointing during graph compilation as part of a broader memory optimization pass, determining optimal checkpoint placement.
Gradient Checkpointing vs. Other Memory Techniques
A comparison of techniques for reducing memory consumption during the training of deep neural networks, highlighting trade-offs between memory, compute, and implementation complexity.
| Feature / Metric | Gradient Checkpointing | Model Parallelism | Activation Recomputation | Mixed Precision Training |
|---|---|---|---|---|
Primary Mechanism | Selectively saves activations, recomputes others during backward pass | Partitions model layers across multiple devices | Recomputes all non-checkpointed activations in backward pass | Uses lower-precision (FP16/BF16) data types for weights/activations |
Memory Reduction | Up to √n reduction (n = # layers) | Scales memory with # of devices | Similar to checkpointing, often configurable | ~50% reduction for FP16 vs. FP32 |
Compute Overhead | High (33-50% extra FLOPs) | Low (communication overhead) | High (similar to checkpointing) | Low (hardware-accelerated) |
Communication Overhead | None (single device) | High (inter-device gradients/activations) | None (single device) | None (single device) |
Implementation Complexity | Moderate (framework support required) | High (model partitioning logic) | Low (often a framework flag) | Low (automated in modern frameworks) |
Hardware Requirements | Single accelerator with sufficient memory for one segment | Multiple accelerators with high-bandwidth interconnect | Single accelerator | Hardware supporting low-precision math (e.g., Tensor Cores) |
Best Suited For | Training very deep networks on a single device | Training models too large for any single device | Default option when checkpointing is enabled | General training speedup and memory saving |
Typical Use Case | Transformer models with 50+ layers on one GPU | LLMs with hundreds of billions of parameters | Training with | Accelerated training of CNNs and Transformers on modern GPUs |
Common Applications and Use Cases
Gradient checkpointing is a critical memory-for-compute trade-off technique. Its primary applications are in enabling the training of models that would otherwise exceed available GPU or accelerator memory.
Training Very Deep Neural Networks
Gradient checkpointing is essential for training extremely deep architectures like large vision transformers (ViTs) or deep convolutional networks where the sequential chain of layers creates a massive memory footprint for activations.
- Example: A 100-layer transformer might require storing activations for all 100 layers. Checkpointing can reduce this to storing only ~10 key layers, recomputing the rest.
- Impact: This allows researchers to explore deeper model variants without requiring prohibitively expensive, high-memory hardware.
Large Batch Size Training
To achieve stable convergence and leverage data parallelism, training often requires large batch sizes. Each sample's activations consume memory; larger batches multiply this cost linearly.
- Mechanism: By checkpointing select layers, memory per sample is reduced, allowing for a larger number of samples to fit into a single batch within the same memory budget.
- Benefit: Enables more efficient use of GPU compute resources and can lead to faster training convergence by allowing higher gradient precision per update.
Long Sequence Modeling (NLP & Genomics)
Processing long sequences in models like transformers has quadratic memory complexity due to the attention mechanism. Gradient checkpointing is applied not just across layers but within the sequence processing of a single layer.
- Use Case: Training language models on very long context windows (e.g., 128k tokens) or analyzing lengthy genomic sequences.
- Strategy: Checkpointing the key computational blocks within the attention and feed-forward layers allows these massive sequences to be processed by trading increased recomputation for feasible memory usage.
Memory-Constrained Research & Development
In academic and industrial R&D environments, access to top-tier hardware with terabytes of VRAM is limited. Gradient checkpointing acts as a force multiplier for existing infrastructure.
- Practical Impact: A team with consumer-grade GPUs (e.g., 24GB VRAM) can train models that would nominally require 80+ GB of memory.
- Development Speed: Facilitates rapid experimentation with novel, memory-intensive architectures without the lead time and cost of procuring specialized hardware.
Enabling Model Parallelism Strategies
Gradient checkpointing complements advanced distributed training strategies like pipeline model parallelism. In pipeline parallelism, the model is split across devices, creating dependencies that require storing activations for the backward pass across device boundaries.
- Integration: By checkpointing the activations at the boundaries between pipeline stages, the memory burden on each device is significantly reduced, allowing for more efficient partitioning of very large models (e.g., models with hundreds of billions of parameters).
- Synergy: Often used in conjunction with frameworks like Megatron-LM or DeepSpeed.
Optimizing for Specific Hardware Accelerators
Different accelerators (GPUs, NPUs, TPUs) have unique memory hierarchies and bandwidth characteristics. Gradient checkpointing must be hardware-aware.
- NPU/TPU Optimization: These accelerators often have high compute throughput but relatively less high-bandwidth memory (HBM). Checkpointing strategies are tuned to maximize the compute utilization by accepting recomputation to stay within memory limits.
- Compiler Integration: Frameworks like TensorRT or TVM can apply automated checkpointing during graph compilation, determining the optimal set of nodes to checkpoint based on a cost model of the target hardware's memory and compute profile.
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 consumer GPUs. These questions address its core mechanics, trade-offs, and practical implementation.
Gradient checkpointing is a memory optimization technique for training deep neural networks that trades off compute for memory by selectively saving only a subset of layer activations during the forward pass and recomputing the others during the backward pass.
How it works:
- Forward Pass (Selective Save): Instead of storing every intermediate activation tensor (which consumes O(N) memory for N layers), the algorithm saves only a strategically chosen subset of these tensors, known as checkpoints. Common strategies include saving every sqrt(N)-th layer.
- Backward Pass (Recomputation): During backpropagation, when the gradients for a non-checkpointed layer are needed, the algorithm re-executes the forward pass for the segment of the network between the two nearest checkpoints. This regenerates the required activations on-the-fly.
- Trade-off: This process reduces peak memory consumption from O(N) to O(sqrt(N)), but increases the total computational cost by approximately 30-40%, as parts of the forward pass are computed twice.
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 core technique within hardware-aware model design, trading compute for memory. Understanding these related concepts is essential for engineers optimizing deep learning workloads for constrained hardware.
Memory Hierarchy Optimization
The process of structuring computations and data layouts to maximize data reuse in fast, on-chip memory (caches, registers) and minimize costly accesses to slower, off-chip memory (DRAM). This is the foundational hardware principle that gradient checkpointing exploits.
- Goal: Minimize the memory wall bottleneck.
- Techniques: Include loop tiling, data prefetching, and operator fusion.
- Relation to Checkpointing: Checkpointing strategically manages the flow of activation tensors between DRAM and GPU memory, treating saved checkpoints as a manual cache.
Model Parallelism
A distributed training strategy where different layers or components of a single neural network model are partitioned and executed across multiple devices (e.g., GPUs) to handle models too large to fit on one device.
- Contrast with Checkpointing: Model parallelism addresses memory limits by using more devices, while checkpointing addresses limits on a single device by using more compute.
- Combined Use: For extremely large models, pipeline parallelism (a form of model parallelism) is often combined with gradient checkpointing within each pipeline stage to manage memory per device.
Activation Recomputation
The core computational trade-off inherent to gradient checkpointing. It refers to the process of recalculating intermediate layer activations during the backward pass that were not saved during the forward pass.
- Mechanism: The forward pass is re-executed for selected segments of the network between saved checkpoints.
- Cost: Typically adds 30-40% overhead to the total training time in exchange for a 4x to 8x reduction in peak activation memory.
- Implementation: Modern frameworks like PyTorch offer APIs (
torch.utils.checkpoint) to automate this process.
Roofline Model
An analytical performance model that visualizes the attainable performance of a computational kernel as a function of its operational intensity (operations per byte of DRAM access), bounded by the hardware's peak compute throughput and memory bandwidth.
- Use in Analysis: Gradient checkpointing moves a workload's profile on the roofline model. It increases operational intensity (more compute per byte fetched) by recomputing activations, potentially moving the kernel from a memory-bound regime closer to a compute-bound one.
- Design Tool: Helps engineers decide if the compute overhead of checkpointing is acceptable given the hardware's memory constraints.
Operator Fusion
A compiler optimization that combines multiple consecutive neural network operations (e.g., convolution, batch normalization, ReLU activation) into a single, fused kernel.
- Primary Benefit: Reduces intermediate memory writes and reads, lowering latency and memory bandwidth pressure.
- Synergy with Checkpointing: Fusing operators reduces the number of individual activation tensors that need to be managed (saved or recomputed), making checkpointing strategies more efficient. A fused Conv-BN-ReLU block is treated as a single unit.
Hardware-in-the-Loop Evaluation
A validation methodology where a model or algorithm is profiled directly on the target physical hardware (or a cycle-accurate simulator) to obtain realistic performance metrics like latency, memory usage, and power.
- Critical for Checkpointing: The optimal checkpointing strategy (e.g., how many layers between checkpoints) is highly hardware-dependent, influenced by memory bandwidth, cache sizes, and compute throughput.
- Process: Engineers use tools like NVIDIA Nsight Systems to profile memory usage with and without checkpointing on the target GPU, empirically determining the best trade-off.

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