Skip to main content

Memory and speed

Training bottlenecks are usually memory first, then throughput. Hugging Face documents both levers extensively.

Adapted for this playbook from the 🤗 Transformers documentation by Hugging Face. Official page: https://huggingface.co/docs/transformers/model_memory_anatomy. Images © Hugging Face (documentation-images) unless noted. This is not a substitute for the upstream docs — verify against the current version.

Covers Hugging Face pages: model_memory_anatomy, grad_accumulation, grad_checkpointing, mixed_precision_training, torch_compile, kernels, padding_free

Memory​

TechniqueIdea
Gradient accumulationSimulate larger batches
Gradient checkpointingRecompute activations to save VRAM
Mixed precisionFP16 / BF16
PEFT / quantizationFewer trainable or lower-bit weights
Optimiser choice8-bit Adam, etc.

Speed​

TechniqueIdea
torch.compileKernel fusion
Fused kernelsAttention / MLP kernels
Padding-free trainingPack sequences to cut waste
DataLoader workers / pinningKeep GPU fed

Official: GPU memory usage, Mixed precision, torch.compile.

Discussion

Comments​

Share feedback or questions about this page. No account required.

Loading comments…