Gradient checkpointing is a memory optimization technique that reduces the peak memory footprint of training deep neural networks by selectively discarding intermediate activations during the forward pass and recomputing them on demand during the backward pass. This explicit trade-off of additional computation for reduced memory enables the training of larger models or the use of larger batch sizes on hardware with limited GPU high-bandwidth memory (HBM).
Glossary
Gradient Checkpointing

What is Gradient Checkpointing?
A memory optimization technique that trades compute for memory by discarding intermediate activations during the forward pass and recomputing them on demand during the backward pass.
During standard backpropagation, all intermediate activations from the forward pass are stored in memory because they are required to compute gradients. With gradient checkpointing, the user defines checkpoints—specific layers where activations are preserved—while activations for non-checkpointed layers are discarded. During the backward pass, when a discarded activation is needed, a mini-forward pass is re-executed from the nearest preceding checkpoint to recompute it. This can reduce memory consumption from O(n) to O(sqrt(n)) for a network with n layers, at the cost of approximately 33% additional forward computation.
Key Characteristics of Gradient Checkpointing
A compute-for-memory trade-off technique that enables training of large vision transformer models on limited hardware by strategically discarding and recomputing intermediate activations.
Core Mechanism: The Forward-Backward Trade
During a standard forward pass, all intermediate activations are stored in memory for the backward pass. Gradient checkpointing breaks this convention by discarding activations of designated layers. During backpropagation, when a discarded activation is needed for the gradient calculation, it is recomputed on-demand by re-running a segment of the forward pass. This transforms the memory footprint from O(n) to O(sqrt(n)) or O(log n) for the checkpointed segments, at the cost of approximately 33% additional forward computation.
Implementation in Vision Transformers
In Vision Transformer (ViT) architectures, checkpointing is typically applied to the MLP and self-attention blocks within each encoder layer. Frameworks like PyTorch implement this via torch.utils.checkpoint.checkpoint, which wraps a module segment as a no-gradient function. During the backward pass, the autograd engine triggers a re-computation of the wrapped segment with gradients enabled. This is particularly critical for Swin Transformers and Masked Autoencoders (MAE) processing large 3D medical volumes where activation memory can exceed 40GB per sample.
Memory Complexity Reduction
A standard n-layer network stores M activations. With optimal checkpointing at every sqrt(n) layers, the memory requirement drops to approximately O(sqrt(n) * M). For a ViT-Large model with 24 transformer blocks processing a 3D CT scan:
- Without checkpointing: ~36GB activation memory
- With selective checkpointing: ~8GB activation memory
- Recomputation overhead: ~20-25% increase in training step time This enables training on a single NVIDIA A100 (80GB) that would otherwise require model parallelism across multiple GPUs.
Selective Checkpointing Strategies
Not all operations benefit equally from checkpointing. Optimal strategies target high-activation, low-compute operations:
- Attention maps: Store QK^T matrices; they are memory-intensive but cheap to recompute
- Linear projections: Checkpoint aggressively; matrix multiplications are fast to recompute
- LayerNorm/GELU activations: Store these; they are computationally trivial but memory-light
- Convolutional stem layers: Avoid checkpointing; early feature maps are small and recomputation is expensive Frameworks like DeepSpeed and FairScale offer automatic activation partitioning to apply this selectively.
Interaction with Mixed Precision Training
When combined with Automatic Mixed Precision (AMP) training, gradient checkpointing requires careful handling of precision casting. The recomputed forward pass must replicate the original precision state:
- FP16 forward: Recomputation occurs in FP16 to match the original activation values
- Master weights: Remain in FP32 and are not affected by checkpoint boundaries
- Loss scaling: The gradient scaling factor is applied identically to recomputed gradients This combination is standard in medical imaging pipelines using nnUNet or MONAI with ViT backbones, enabling batch sizes of 4-8 on 3D volumes that would otherwise be limited to batch size 1.
Recomputation vs. Offloading Trade-off
Gradient checkpointing is one of three primary memory-saving strategies, each with distinct trade-offs:
- Gradient Checkpointing: +25% compute, no CPU-GPU transfer overhead, deterministic
- Activation Offloading: Moves activations to CPU RAM; +10% compute but high PCIe bandwidth dependency
- Gradient Accumulation: Splits batch across micro-batches; no compute overhead but changes batch norm statistics For medical imaging with DICOM volumes, checkpointing is preferred over offloading when GPU compute is abundant but VRAM is constrained, as PCIe transfers become a bottleneck with high-resolution 3D data.
Frequently Asked Questions
Clear, technical answers to the most common questions about this critical memory optimization technique for training large vision transformer models on medical imaging data.
Gradient checkpointing is a memory optimization technique that trades increased computation for reduced memory consumption during neural network training. During the standard forward pass, a deep learning framework normally stores all intermediate activations required for the backward pass. Gradient checkpointing instead discards the activations of designated layers and recomputes them on demand during backpropagation. The technique segments the computational graph into checkpoints—typically at the boundaries of Transformer blocks or residual stages—and only stores the inputs to these segments. When the backward pass reaches a segment, it re-runs the forward computation for that segment to regenerate the necessary intermediate tensors. This reduces peak memory usage from O(n) to O(√n) or O(log n), where n is the number of layers, enabling the training of significantly larger models on memory-constrained hardware.
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.
Gradient Checkpointing vs. Other Memory Optimization Techniques
A technical comparison of gradient checkpointing against alternative methods for reducing GPU memory footprint during deep learning training.
| Feature | Gradient Checkpointing | Mixed Precision Training | Model Parallelism |
|---|---|---|---|
Primary Mechanism | Discards intermediate activations; recomputes during backward pass | Uses FP16 for forward/backward; FP32 master weights | Partitions model layers across multiple accelerators |
Memory Reduction Target | Activation memory | Activations, weights, gradients | All memory types (distributed) |
Compute Overhead | ~20-30% additional forward pass compute | Negligible; often faster due to tensor cores | Communication overhead between devices |
Requires Multiple GPUs | |||
Training Throughput Impact | Reduced throughput proportional to recomputation | Increased throughput on supported hardware | Scales near-linearly with device count |
Implementation Complexity | Single API call or flag toggle | Few lines of code; framework-native | Significant architectural refactoring required |
Numerical Stability Risk | None; exact recomputation | Loss scaling required; potential underflow | None inherent to partitioning |
Compatibility with Other Techniques | Orthogonal; combines with mixed precision and parallelism | Orthogonal; combines with checkpointing and parallelism | Orthogonal; combines with checkpointing and mixed precision |
Related Terms
Gradient checkpointing is one of several critical techniques for managing GPU memory during training. These related concepts form the complete memory optimization toolkit for large-scale vision transformer training.
Activation Recomputation
The formal name for the mechanism underlying gradient checkpointing. During the forward pass, only a subset of layer activations are retained in memory. During the backward pass, discarded activations are recomputed on-the-fly from the nearest saved checkpoint. This trades a ~20-30% increase in forward computation for a sublinear reduction in peak memory, enabling models like ViT-Large to train on consumer GPUs.
Mixed Precision Training
A complementary technique that stores activations and performs most arithmetic in 16-bit floating point (FP16 or BF16) rather than 32-bit. When combined with gradient checkpointing, the memory savings multiply: checkpointing reduces the number of stored tensors, while mixed precision halves the size of each remaining tensor. Modern frameworks like PyTorch's torch.cuda.amp implement this via automatic loss scaling to preserve numerical stability.
FlashAttention
An I/O-aware exact attention algorithm that avoids materializing the full N×N attention matrix in GPU high-bandwidth memory (HBM). By tiling the computation and recomputing attention scores in fast on-chip SRAM during the backward pass, FlashAttention achieves the same memory-compute tradeoff as gradient checkpointing but specifically optimized for the self-attention bottleneck. Critical for training long-sequence vision transformers.
Micro-Batching & Gradient Accumulation
A strategy that splits a large logical batch into smaller micro-batches processed sequentially. Gradients are accumulated across micro-batches before a single optimizer step. This reduces peak activation memory linearly with the number of micro-batches. Combined with gradient checkpointing, it allows effective batch sizes that would otherwise exceed GPU memory by orders of magnitude, though at the cost of increased wall-clock training time.
Model Parallelism Strategies
When gradient checkpointing alone cannot fit a model, tensor parallelism shards individual layers across multiple GPUs, while pipeline parallelism partitions sequential layers across devices. Checkpointing integrates naturally with pipeline parallelism: only activations crossing pipeline stage boundaries must be communicated, and each stage can independently apply recomputation. Frameworks like Megatron-LM and DeepSpeed orchestrate this combination for trillion-parameter vision models.
CPU Offloading
An orthogonal technique that moves tensors from GPU memory to much larger CPU RAM during the forward pass and fetches them back during the backward pass. DeepSpeed ZeRO-Offload and PyTorch's torch.utils.checkpoint with use_reentrant=False support hybrid strategies where some activations are checkpointed and others are offloaded. The tradeoff is PCIe bandwidth: offloading adds latency, while recomputation adds compute. Optimal strategies balance both based on the GPU-CPU bandwidth ratio.

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