Mixed Precision Training
Training efficiency technique
Mixed precision training is a technique for training neural networks that uses lower-precision numerical formats (such as 16-bit floating point) for most computations while selectively retaining higher-precision 32-bit values where needed,…
Definition
Mixed precision training is a technique for training neural networks that uses lower-precision numerical formats (such as 16-bit floating point) for most computations while selectively retaining higher-precision 32-bit values where needed, to speed up training and reduce memory usage without sacrificing model accuracy.
Overview
Mixed precision training combines FP16 (or BF16, bfloat16) and FP32 (32-bit floating point) arithmetic within a single training run: forward and backward passes are computed primarily in the lower-precision format, which uses half the memory of FP32 and runs substantially faster on hardware with dedicated low-precision compute units, such as NVIDIA GPU tensor cores, while a master copy of the model's weights is kept in FP32 to preserve numerical stability during the small, cumulative weight updates that occur during optimization. A key technical challenge with pure FP16 training is that its limited numerical range can cause small gradient values to underflow to zero, stalling learning. Mixed precision training addresses this with loss scaling: the loss value is multiplied by a scaling factor before backpropagation, which proportionally scales up the gradients into FP16's representable range, and then the gradients are scaled back down before the weight update is applied. Modern deep learning frameworks (PyTorch's `torch.cuda.amp`, TensorFlow's mixed precision API) automate this process, dynamically adjusting the loss scale during training and automatically selecting which operations run in reduced precision versus which remain in FP32 for stability (such as certain reduction and normalization operations). BF16, an alternative 16-bit format with the same exponent range as FP32 but fewer mantissa bits, avoids much of the underflow risk that motivates loss scaling in FP16, at the cost of somewhat lower precision per value, and has become popular for training very large models. Mixed precision training is now standard practice for training large-scale deep learning models, including large language models and vision transformers, because it can roughly halve memory usage and provide 1.5x to 3x training speedups on modern accelerator hardware with negligible accuracy degradation compared to full FP32 training. This efficiency gain directly enables training larger models, using larger batch sizes, or reducing training costs and carbon footprint, and it pairs naturally with other efficiency techniques like gradient checkpointing and distributed data-parallel training in large-scale training pipelines.
Key Concepts
- Combines FP16/BF16 compute with an FP32 master copy of model weights
- Roughly halves memory usage compared to full FP32 training
- Delivers 1.5x-3x training speedups on tensor-core-equipped hardware
- Uses loss scaling to prevent small gradients from underflowing in FP16
- BF16 avoids much of FP16's underflow risk due to its wider exponent range
- Automated in modern frameworks via APIs like PyTorch's torch.cuda.amp
- Preserves accuracy close to full-precision training in most cases
- Standard practice for training large language models and vision transformers
Use Cases
Frequently Asked Questions
From the Blog
RAG Explained: How AI Answers From Your Data
RAG lets AI answer from your private documents instead of just its training data — here's how it works.
Read More AI & TechnologyRAG Explained: Retrieval-Augmented Generation
RAG is how you give an LLM access to your own private data without training a new model. This guide explains the full pipeline — chunking, embeddings, vector search, and augmented generation — with a working Python example using open-source tools.
Read More AI & TechnologyFine-Tuning LLMs: A Practical Guide
Fine-tuning lets you adapt a pre-trained language model to your specific domain, style, or task — without training from scratch. This guide explains when fine-tuning is the right choice, how LoRA makes it affordable, and how to run a fine-tuning job with Hugging Face PEFT.
Read More AI & TechnologyHow Large Language Models Actually Work
LLMs seem magical until you understand what they are: next-token predictors trained on massive text corpora. This guide explains tokenisation, embeddings, the transformer architecture, attention mechanism, and how training works — without requiring a maths degree.
Read More