Devices, mixed precision, batching and gradient accumulation
What it is
GPU training moves both model parameters and each batch's tensors to the same accelerator device. Mixed precision uses lower-precision arithmetic where it is safe and maintains critical values or scaling in higher precision, often reducing memory use and increasing throughput on modern hardware. Gradient accumulation sums appropriately scaled gradients across several micro-batches before one optimiser step, emulating a larger effective batch when activations would not fit together in memory. Data loading, host-to-device transfer, sequence padding, and activation checkpointing can dominate performance as much as the model's arithmetic.
Why it matters
Performance is often limited by input loading, memory bandwidth, or activation storage rather than raw FLOPs. Measuring those bottlenecks is more useful than guessing: profile step time, accelerator utilisation, memory peaks, and data-loader wait time before changing model design. Efficiency work must preserve numerical and training semantics; a faster run with a changed effective batch or unstable reduced precision is not a fair comparison.
In the real world: Techniques that cut training time and cloud GPU bills.
Visual example
Deep learningSeveral small micro-batches can contribute to one larger effective update.
import torch
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = model.to(device)
torch.cuda.reset_peak_memory_stats()
train_one_epoch(model, loader, optimizer, device)
peak_gb = torch.cuda.max_memory_allocated() / 1e9
print(f'peak allocated: {peak_gb:.2f} GB')Calling optimizer.step() for each accumulation micro-batch. That changes the effective batch and update count; divide the loss, call backward per micro-batch, then step only at the accumulation boundary.