AI Hints
Home›Fine-Tuning LLMs Tutorial›Precision, Length and Hardware
Fine-Tuning LLMs · Lesson 64 of 120

Mixed Precision

Fast maths, safe updates.

⏱ 2 min read▶ Video at 1:40:01🎓 Free
Watch this lesson in the Fine-Tuning LLMs courseWatch on YouTube ↗Full Fine-Tuning LLMs course

GPUs are much faster at sixteen bit maths than thirty two bit. But some parts of training need more precision. Mixed precision uses each format where it works best.

  • 16-bit maths is faster
  • Some parts need precision
  • Use each where it fits

How mixed precision works

In mixed precision training, the heavy maths, the big matrix multiplications, runs in b float sixteen. That's fast, and saves memory. But sensitive steps, like adding up the loss, and updating weights, use float thirty two. You get most of the speed, with almost none of the risk.

keyvalue
Heavy mathsbfloat16, fast
Loss and updatesfloat32, safe
Speedup to 2× or more
Riskvery low

Which flag to use

In SFT config, b f sixteen equals true turns on mixed precision with b float sixteen. It's the default on modern GPUs, like the A one hundred, the H one hundred, and RTX thirty and forty series cards. Older GPUs, like the T four on free Colab, don't support it. There, use f p sixteen equals true instead. On a CPU, like our laptop, neither is used.

HardwareSetting
A100, H100, RTX 30/40bf16=True (default)
T4, V100 (older)fp16=True
CPU (our laptop)neither, float32

Summary

Let's recap. Mixed precision runs heavy maths in sixteen bits, and sensitive steps in thirty two. Use b f sixteen on modern GPUs, and f p sixteen on older ones. Next, how long our examples are, and why it matters.

Key takeaways
  • Heavy maths in 16-bit
  • Updates in 32-bit
  • bf16 or fp16
Next up: Sequence Length and Packing — tokens per example