Gradient (Activation) Checkpointing in NeMo AutoModel
Gradient (Activation) Checkpointing in NeMo AutoModel
Gradient checkpointing, also called activation checkpointing, trades a little extra compute for a large reduction in GPU memory by recomputing intermediate activations during the backwards pass instead of storing them.
It is especially powerful when combined with memory-efficient loss functions (e.g., Linear-Cut Cross-Entropy) and parameter sharding using FSDP.
Enable Gradient Checkpointing
Configure in YAML
Add the activation_checkpointing: true flag under your distributed strategy.
Example (snippet):
Configure Programmatically
Combine with Linear-Cut Cross-Entropy (LC-CE)
Linear-Cut Cross-Entropy (LC-CE) reduces the hidden-state memory required to compute the loss by calculating the softmax on the fly, thus avoiding the need to allocate memory for the logits.
It is already available using nemo_automodel.components.loss.linear_ce.FusedLinearCrossEntropy and can be enabled in recipes by using the following:
LC-CE and gradient checkpointing target different memory hot-spots (output layer vs. transformer blocks) so their benefits stack almost linearly.
Example Memory Savings (H100-80GB, Llama-3.2-1B)
- Measurements taken with local batch size = 8, sequence len = 2048, AdamW, PyTorch 2.8.
- Peak memory reported by
torch.cuda.max_memory_allocated()averaged across DP ranks. - Expect ±5 % variance depending on exact model, sequence length and GPU architecture.
Performance Considerations
- Extra compute: Each checkpointed segment is recomputed once during the backward pass. In practice, the wall-clock overhead is ≈5-10% for transformer models.
- Throughput vs. Batch Size: The goal is usually to increase batch size or sequence length while keeping throughput constant.
Verify It Works
Run your training script and inspect the peak memory:
If we run with the above settings (activation ckpt = on, lc-ce = on, fsdp = on), look for a log line similar to: