Gradient checkpointing is a memory-for-compute trade-off technique in deep learning that reduces GPU memory consumption during training by selectively discarding intermediate activations from the forward pass and recomputing them on-demand during the backward pass. This enables the training of significantly larger models or the use of longer sequences within a fixed memory budget, such as on edge hardware, at the cost of increased computational overhead.
Glossary
Gradient Checkpointing

What is Gradient Checkpointing?
A memory optimization technique for training deep neural networks.
The technique works by strategically saving only a subset of activations, known as checkpoints, during the forward pass. During backpropagation, the discarded activations are recomputed from the nearest checkpoint. This reduces peak memory usage from O(n) to O(√n) with respect to the number of layers, a critical optimization for small language model engineering and other memory-constrained environments, though it typically increases training time by 20-30%.
Key Characteristics of Gradient Checkpointing
Gradient checkpointing is a memory optimization technique that trades compute for memory by selectively discarding and recomputing intermediate activations during the backward pass of neural network training.
Core Trade-Off: Compute for Memory
The fundamental principle of gradient checkpointing is a time-memory trade-off. Instead of storing all intermediate activations from the forward pass—which consumes O(n) memory for n layers—the technique strategically discards most of them. 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), enabling the training of models that are 2-4x larger on the same hardware, at the cost of approximately 30-40% more compute time for the extra forward passes.
Selective Checkpoint Placement
Not all activations are checkpointed. The placement of checkpoints is a critical optimization problem. Common strategies include:
- Uniform Placement: Checkpointing every k-th layer (e.g., every 5 layers). Simple but suboptimal.
- Optimal Dynamic Programming: Algorithms that determine the checkpoint schedule to minimize total recomputation cost for a fixed memory budget, considering the varying computational cost of different layers.
- Manual Heuristics: Targeting memory-intensive layers (e.g., early transformer blocks with large sequence lengths). The goal is to store just enough activations to keep the recomputation cost manageable while staying within the memory limit.
Implementation in Autodiff Frameworks
Gradient checkpointing is implemented by intercepting the automatic differentiation (autodiff) engine. In PyTorch, this is done via torch.utils.checkpoint.checkpoint. The function wraps a segment of the model:
- Forward Pass: The wrapped segment runs, but its outputs are stored, not its internal activations. A custom autograd
Functionis recorded. - Backward Pass: When gradients are requested, this custom function re-executes the wrapped segment in a no-grad context to recompute the internal activations, then performs the backward pass through the segment with gradients enabled.
Frameworks like TensorFlow and JAX have similar APIs (
tf.recompute_grad,jax.checkpoint).
Activation Recomputation Process
The backward pass becomes a series of recomputation sweeps. Starting from the output and moving backward:
- The system loads the nearest stored checkpoint activation.
- It re-executes the forward pass for the subsequent non-checkpointed layers.
- With the full set of activations now temporarily available for that segment, it computes the gradients for those layers.
- The recomputed activations are discarded, and the process repeats for the next segment. This creates a wavefront of computation where memory is repeatedly allocated and freed for small segments, keeping the peak usage low. The process is automatic but adds significant computational overhead.
Interaction with Mixed Precision Training
Gradient checkpointing is often used in conjunction with mixed precision training (using FP16/BF16). This combination is powerful but requires care:
- Checkpoint Precision: Typically, checkpoints are stored in FP32 (full precision) even when forward/backward passes use FP16. This prevents a buildup of quantization error during the chain of recomputations, which can degrade training stability.
- Recomputation Precision: The recomputation forward pass is usually performed in the same lower precision (FP16) as the original forward pass for speed.
- Memory Savings: Storing checkpoints in FP32 doubles their memory footprint compared to FP16, but this is offset by not storing all other activations. The net effect is still a substantial memory reduction.
Use Cases and Limitations
Primary Use Cases:
- Training very large models (e.g., LLMs, diffusion models) on memory-constrained hardware.
- Processing extremely long sequences in transformers, where activation memory is the primary bottleneck.
- Enabling larger batch sizes for better hardware utilization and training stability.
Key Limitations:
- Compute Overhead: Adds 30-40% more FLOPs, increasing wall-clock training time.
- Implementation Complexity: Requires careful segmentation of the model; not all model architectures (e.g., those with complex control flow) are easily checkpointable.
- I/O Bottlenecks: On systems with slow CPU-GPU data transfer, the overhead can be higher. It is less beneficial for models where parameter memory, not activation memory, is the limiting factor.
Gradient Checkpointing vs. Related Techniques
A comparison of techniques for managing memory and computational load during the training of large neural networks, focusing on the trade-offs inherent in each approach.
| Feature / Metric | Gradient Checkpointing | Full Activation Storage | Micro-Batching | CPU Offloading |
|---|---|---|---|---|
Primary Objective | Reduce peak GPU memory usage | Maximize training speed | Fit large batches into memory | Train models larger than GPU memory |
Memory Reduction Mechanism | Discard & recompute intermediate activations | Store all activations | Split batch into smaller sequential chunks | Move optimizer states/gradients/params to CPU RAM |
Computational Overhead | ~30-40% extra forward pass compute | None | Minimal (slight pipeline bubble) | High (significant CPU-GPU transfer latency) |
Implementation Complexity | Medium (selective layer checkpointing) | Low (default PyTorch/TF behavior) | Low (data loader logic) | High (manual tensor management) |
Maximum Model Size (Relative) | 2-4x larger | Baseline (1x) | Limited by micro-batch size | 10x+ larger (bound by system RAM) |
Best Suited For | Memory-bound single GPU training | Compute-bound scenarios with ample VRAM | Pipeline parallelism in multi-GPU setups | Extreme model sizes on limited GPU hardware |
Impact on Training Speed | Slower (due to recomputation) | Fastest | Slightly slower (pipeline overhead) | Slowest (bandwidth-limited) |
Framework Support | Native in PyTorch ( | Default in all frameworks | Manual implementation or pipeline parallel libs | Libraries like DeepSpeed (ZeRO-Offload) |
Frequently Asked Questions
Gradient checkpointing is a critical memory optimization technique for training large neural networks. It strategically trades compute for memory, enabling the training of models that would otherwise exceed available GPU memory. This FAQ addresses its core mechanisms, trade-offs, and practical implementation.
Gradient checkpointing is a memory optimization technique for neural network training that trades compute for memory by selectively discarding intermediate activations during the forward pass and recomputing them during the backward pass. In standard backpropagation, all intermediate layer outputs (activations) are stored in memory to compute gradients. Gradient checkpointing designates certain layers as checkpoints. During the forward pass, only the activations at these checkpoints are retained; the non-checkpoint activations are discarded. During the backward pass, when gradients for a non-checkpointed segment are needed, the network re-executes the forward pass for that segment, starting from the nearest stored checkpoint, to regenerate the required activations. This process reduces peak memory usage from O(n) to O(√n) with respect to the number of layers, at the cost of approximately one additional forward pass per checkpointed segment.
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 the broader discipline of designing models for resource-constrained environments. These related concepts represent other critical strategies for achieving computational and memory efficiency.
Mixture of Experts (MoE)
A neural network architecture that routes different inputs to specialized sub-networks (experts). Instead of activating the entire model for every input, a gating network selects a small subset of experts. This enables a massive increase in model parameters (e.g., 1 trillion+) while keeping the computational cost per token similar to a much smaller dense model, as only a fraction of the total parameters are used.
FlashAttention
An I/O-aware exact attention algorithm that dramatically speeds up transformer training and inference and reduces memory usage. Its key innovation is avoiding the materialization of the large, quadratic-sized attention matrix in slow High Bandwidth Memory (HBM). Instead, it recomputes attention scores on-the-fly within fast SRAM, performing tiling and recomputation to minimize memory reads/writes. This is a form of kernel fusion optimized for modern GPU memory hierarchy.
Quantization-Aware Training (QAT)
A process where a model is fine-tuned with simulated quantization noise applied during the forward pass. This allows the model weights to adapt to the lower precision (e.g., INT8) that will be used during deployment. Unlike post-training quantization, QAT accounts for the quantization error during training, typically recovering nearly all the accuracy lost by moving to lower bit-widths. It's a critical technique for on-device inference optimization.
Structured Pruning
A model compression technique that removes entire structural components from a neural network, such as neurons, channels, filters, or attention heads. Unlike unstructured pruning (which creates sparse weight matrices), structured pruning results in a smaller, denser architecture that can leverage standard, highly optimized dense linear algebra libraries. It directly reduces the model's parameter count and FLOPs, making it hardware-friendly.
Dynamic Inference
A family of techniques where a model adapts its computational cost per input sample. The goal is to avoid wasting computation on easy examples. Key strategies include:
- Early Exiting: Attaching classifiers to intermediate layers, allowing simple inputs to exit early.
- Conditional Computation: Dynamically activating only a subset of the model's components (e.g., layers, experts) based on the input. This paradigm shifts from a fixed-cost to an input-adaptive cost model.
Model Scaling Laws
Empirically derived power-law relationships that predict how a model's pre-training loss scales with its size (parameters), dataset size, and computational budget. The Chinchilla scaling laws demonstrated that for a fixed compute budget, optimal performance is achieved by scaling model size and training data in roughly equal proportion, challenging prior assumptions. These laws are essential for compute-optimal planning of large-scale training runs.

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