How does gradient checkpointing reduce memory usage during training, and what trade-offs does it ...
.
.
.
.
.
Gradient checkpointing is a memory optimisation technique used during training of large neural networks, including models from Hugging Face Transformers. Normally, during backpropagation, all intermediate activations from the forward pass are stored in memory so that gradients can be calculated later. In large models, especially on limited GPU resources, this can quickly exhaust memory. Gradient checkpointing tackles this by only storing a subset of activations during the forward pass. When it’s time to compute gradients, the missing activations are recomputed on the fly by re-running portions of the forward pass.
The key trade-off with gradient checkpointing is the increased computational overhead. Since some activations are not saved and must be recomputed, training takes longer due to the extra forward passes. However, this trade-off is often worthwhile, especially when training large models on hardware with constrained memory, such as a single GPU or lower-tier cloud instance. In practice, this allows developers to fine-tune or train larger models than would otherwise be possible, making it a powerful tool in memory-constrained environments.