DocsAI Training Coach Advanced Techniques

Mixed Precision Training

Train faster with fp16 and bf16 – half the memory

Mixed precision training uses 16-bit instead of 32-bit floating point numbers for most computations. This halves memory requirements and speeds up training on modern GPUs by 2–3×.

fp32 vs. fp16 vs. bf16 – the detailed comparison

FormatBitsExp. BitsMantissaNumeric RangePrecisionRecommendation
float3232823±3.4e38Very highSafe, but slow
float1616510±65,504MediumOverflow risk
bfloat161687±3.4e38Low-mediumBest choice

Why bf16 is better than fp16

BFloat16 has the same exponent range as fp32 (8 exponent bits), but fewer mantissa bits. fp16 has only 5 exponent bits → much smaller numeric range → overflow with large activations. bf16 solves this problem.

fp16 overflow problem:
  If activations > 65,504:
  → Overflow → NaN → training crashes!
  Workaround: loss scaling (automatic, but complex)

bf16 no overflow:
  Same numeric range as fp32
  → No loss scaling needed
  → Simpler, more stable

GPU support for bf16:
  NVIDIA Ampere (RTX 30xx, A100): bf16 hardware support ✓
  NVIDIA Turing (RTX 20xx, T4):   fp16 hardware only ✗
  NVIDIA Volta (V100):             fp16 hardware only ✗
  Apple Silicon (M1/M2/M3):       bf16 hardware support ✓
  AMD RDNA3+:                      bf16 hardware support ✓

Automatic Mixed Precision (AMP)

During mixed precision training, not all computations run in 16-bit. Some critical operations stay in fp32:

Mixed precision training – what runs at which precision:

  fp16/bf16 (fast, low memory):
    ✓ Forward pass (activations)
    ✓ Backward pass (gradients)
    ✓ Model weights (inference copy)

  fp32 (safe, precise):
    ✓ Master copy of weights (optimizer states)
    ✓ Weight updates
    ✓ Loss computation
    ✓ Batch normalization (statistics)

  Result: ~2× less VRAM, 2–3× faster
          with minimal quality loss

Memory savings from mixed precision

7B model28 GB (fp32)14 GB (fp16)14 GB (bf16)
13B model52 GB (fp32)26 GB (fp16)26 GB (bf16)
1B model4 GB (fp32)2 GB (fp16)2 GB (bf16)
125M (BERT)0.5 GB (fp32)0.25 GB (fp16)0.25 GB (bf16)

In FrameTrain

FrameTrain automatically picks the best precision format based on your GPU. RTX 30xx/40xx and newer: automatically bf16. Older GPUs: fp16 or fp32. You can override this manually in the "Advanced Settings" panel.

Feedback

What did you notice? Bugs, ideas, praise – it goes straight to the developer.

What's it about?