Mixed Precision Training with PyTorch AMP: fp16, bf16, and GradScaler
A practical guide to PyTorch Automatic Mixed Precision for ML engineers: the numerical difference between fp16 and bf16 and when to use each, complete AMP training loop with autocast and GradScaler, how GradScaler adaptive scaling works and how to tune it, which ops autocast converts vs keeps in float32, AMP with HuggingFace Trainer, mixed precision inference with permanently converted model weights, and a hook-based debugger for finding which operation first produces NaN under fp16.