Gradient checkpointing is a memory optimization technique that enables the training of larger models or longer sequences by trading increased computation for reduced memory usage. During the forward pass, instead of saving all intermediate layer activations for the backward pass, the system strategically saves only a subset, known as checkpoints. The non-saved activations are recomputed on-demand during backpropagation from the nearest checkpoint. This technique is critical for overcoming GPU memory bottlenecks in large-scale model training.
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, particularly large language models, to reduce memory consumption by selectively storing intermediate activations.
The primary trade-off is between memory and compute. By storing fewer activations, peak memory consumption can be reduced by a factor proportional to the square root of the number of layers, enabling the training of models that would otherwise be impossible. However, this comes at the cost of approximately a 30% increase in computational time due to the extra forward passes required for recomputation. It is a foundational technique in frameworks like PyTorch (torch.utils.checkpoint) and is often combined with other methods like mixed precision training and ZeRO optimization.
Key Characteristics of Gradient Checkpointing
Gradient checkpointing is a memory-for-compute trade-off technique that enables the training of larger neural networks by strategically managing the storage of intermediate activations during backpropagation.
Core Trade-Off: Compute for Memory
Gradient checkpointing fundamentally trades increased computation for reduced memory consumption. During the forward pass, only a subset of layer activations (the 'checkpoints') are stored in memory. During backpropagation, the non-checkpointed activations are recomputed on-the-fly from the nearest checkpoint. This reduces peak GPU memory usage from O(n) to O(√n) for a model with n layers, at the cost of approximately one additional forward pass per checkpoint segment.
Selective Activation Storage
Instead of storing every intermediate activation, the algorithm saves only key activations at predetermined intervals. Common strategies include:
- Uniform checkpointing: Saving activations every
klayers. - Dynamic checkpointing: Using heuristics to save at memory-intensive layers (e.g., after large matrix multiplications).
- Recomputation granularity: Choosing whether to recompute at the tensor, layer, or block level. The choice directly impacts the memory-compute Pareto frontier for a given model architecture.
Enables Larger Models & Longer Sequences
By drastically reducing activation memory, checkpointing is essential for training state-of-the-art models that would otherwise exceed GPU memory limits. It is critical for:
- Large Language Models (LLMs): Training models with tens or hundreds of billions of parameters.
- Long-context tasks: Processing long sequences in transformers, where activation memory scales with sequence length.
- High-resolution vision models: Training on large images where activations from early convolutional layers are voluminous.
Performance Overhead Profile
The computational overhead is not uniform. Key performance characteristics include:
- Theoretical overhead: Up to 33% more FLOPs in an optimal schedule.
- Practical latency: Overhead is often lower due to memory bandwidth bottlenecks; recomputation can be faster than reading large tensors from slow GPU memory (HBM).
- Communication overhead: In distributed training, reduced memory can enable larger batch sizes per GPU, potentially improving throughput and reducing synchronization costs.
Relationship to Other Optimizations
Checkpointing is often combined with other memory-saving techniques:
- Mixed Precision Training: Checkpointing stores activations in FP16/BF16, while recomputation may use higher precision for numerical stability.
- Parameter-Efficient Fine-Tuning (PEFT): Methods like LoRA reduce gradient memory for weights, while checkpointing reduces activation memory.
- Model Parallelism: Checkpointing is used within each device's sub-model to further push memory limits.
- Offloading: Can be used with CPU RAM offloading (e.g., via DeepSpeed) for extreme memory reduction.
Gradient Checkpointing vs. Other Memory Optimization Techniques
A comparison of memory reduction strategies for training large neural networks, focusing on the trade-offs between compute overhead, memory savings, and implementation complexity.
| Feature / Metric | Gradient Checkpointing | Mixed Precision Training (FP16/BF16) | ZeRO Optimization (DeepSpeed) | Parameter-Efficient Fine-Tuning (PEFT) |
|---|---|---|---|---|
Primary Mechanism | Selectively re-computes activations during backward pass | Uses lower-precision (16-bit) floats for weights/activations | Partitions optimizer states, gradients, and parameters across GPUs | Freezes base model, updates only small adapter modules |
Memory Reduction Target | Activations (forward pass) | Model Weights & Activations | Optimizer States, Gradients, Parameters | Trainable Parameters |
Typical Memory Savings | 50-75% of activation memory | ~50% of model parameter memory | Up to 8x increase in trainable model size (vs. naive) |
|
Compute Overhead | 30-40% increase in training time | < 5% increase (often a net speedup) | Moderate communication overhead | Minimal (often faster than full fine-tuning) |
Implementation Complexity | Medium (requires code modification) | Low (framework-supported flags) | High (requires distributed training setup) | Low (library-based, e.g., Hugging Face PEFT) |
Best Suited For | Training very large models from scratch | Accelerating standard training/inference | Extreme-scale model training (e.g., > 100B params) | Adapting pre-trained models to new tasks |
Compatible with Model Parallelism | ||||
Preserves Full Model Performance |
Implementation in Frameworks and Platforms
Gradient checkpointing is implemented as a memory optimization layer within deep learning frameworks, enabling the training of larger models by trading compute for memory. The following cards detail its integration across major platforms.
Hugging Face Transformers Integration
The Hugging Face transformers library integrates gradient checkpointing as a model configuration flag for many of its architectures, abstracting the framework-specific details.
- Activation: Enabling it is as simple as setting
model.gradient_checkpointing = Trueor passinggradient_checkpointing=Trueduring model initialization (e.g.,AutoModelForCausalLM.from_pretrained(...)). - Underlying Framework: The library calls the appropriate underlying framework's checkpointing API (PyTorch's
checkpointor TensorFlow'srecompute_grad). - Impact: This is a critical feature for training or fine-tuning large language models (LLMs) like GPT-2, T5, or BLOOM on limited hardware, as it can reduce activation memory by 60-70%.
- Caveat: It introduces a 20-30% increase in training time due to recomputation.
Practical Trade-offs and Configuration
Implementing gradient checkpointing requires careful configuration to maximize the memory-compute trade-off.
- Granularity: The unit of checkpointing is critical. Checkpointing too finely (e.g., every operation) leads to excessive recomputation overhead. Checkpointing too coarsely (e.g., the entire model) saves little memory. The optimal level is often at the layer or block level.
- Memory Savings: Typically reduces activation memory from O(n) to O(sqrt(n)), where
nis the number of layers. This can be the difference between fitting a model in GPU memory or not. - Compute Cost: Adds one extra forward pass per checkpointed segment during backward propagation. The overall training time increase is often a worthwhile trade for enabling larger models.
- Best Practices:
- Profile memory usage to identify the most memory-intensive modules.
- Start by checkpointing large, homogeneous blocks (e.g., transformer blocks).
- Use framework-specific profiling tools (like PyTorch's memory profiler) to validate savings.
Frequently Asked Questions
Gradient checkpointing is a critical memory optimization technique for training large neural networks. These questions address its core mechanism, trade-offs, and practical implementation.
Gradient checkpointing is a memory optimization technique that trades compute for memory by selectively saving only a subset of intermediate activations during the forward pass of neural network training. During the standard backpropagation algorithm, gradients are calculated using the chain rule, which requires the intermediate values (activations) from the forward pass. Storing all these activations for a large model or long sequence can exceed GPU memory limits. Checkpointing works by dividing the computational graph into segments. Only the activations at the boundaries of these segments (the checkpoints) are saved. During the backward pass, when gradients for a non-checkpointed layer are needed, the forward pass for that segment is re-computed from the nearest checkpoint, regenerating the required activations on the fly. This process significantly reduces peak memory consumption at the cost of additional forward-pass computations.
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 a broader ecosystem of methods designed to manage the trade-offs between memory, compute, and model scale during training.
Activation Recomputation
This is the fundamental mechanism underlying gradient checkpointing. Instead of storing all intermediate activations from the forward pass, the system selectively saves only a subset (the checkpoints). During the backward pass, the unsaved activations are recomputed on-demand from the nearest checkpoint. This creates a direct trade-off: reduced GPU memory at the cost of increased computation time, typically adding 20-33% more forward-pass compute.
Micro-Batching
A technique to split a training batch into smaller micro-batches that are processed sequentially. This is essential for fitting large models into memory. Gradient checkpointing is often applied within the processing of a single micro-batch to handle long sequences or deep layers. The gradients from each micro-batch are accumulated before performing a weight update, simulating the effect of the full batch size.
Model Parallelism
A distributed training strategy where different layers or components of a single model are placed on different accelerators (e.g., GPUs). This is used when a model is too large to fit on one device. Pipeline Parallelism and Tensor Parallelism are common forms. Gradient checkpointing is used within each parallel segment to further reduce the memory footprint of the activations stored on each individual device, enabling even larger models.

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