Zenaique

Explain bf16's advantage over fp16 and what gradient checkpointing trades

Short answer·Medium·4.0 · 0·~3 min·Asked atCredGnaniNVIDIA·Relevant atDatabricksMetaMicrosoft
Attempt it

Explain (a) why bf16 is preferred over fp16 for LLM fine-tuning, and (b) what gradient checkpointing trades: when it makes sense and when it doesn't.

Free · 2 AI evals / day
TL;DR

bf16 keeps fp32's 8-bit exponent, so gradients never overflow and loss scaling disappears. Gradient checkpointing trades about 30% compute for about 70% activation memory.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine a ruler with a fixed number of marks. You can either cover a huge span of sizes with marks far apart, or a tiny span with marks close together. One kind of number tries to measure finely, so it cannot reach the very smallest sizes, and those just round down to nothing. The other kind spreads its marks wide, so it reaches everything and nothing gets lost. Saving memory is a separate trick. Picture doing a long calculation on scratch paper. Instead of keeping every line you ever wrote, you keep only a few checkpoints and rework the missing lines when you need them. That clears your desk a lot, but you do some sums twice, so it takes a little longer.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

This question bundles two fine-tuning mechanics that share a goal, fitting a big model on the hardware you have, but solve different problems. Mixed precision picks a cheaper number format. Gradient checkpointing changes what you keep in memory during the backward pass. Interviewers ask both together because candidates often blur them, calling checkpointing a precision trick or claiming bf16 is simply more accurate.

The payoff for getting this right is that both choices are everyday decisions in any real fine-tuning run. You set the precision flag and the checkpointing flag in the first few lines of every training config. Knowing exactly what each one buys, and what it costs, is the difference between a recipe you copied and a recipe you understand.

A clean way to keep them apart is to ask what resource each one is buying back. Mixed precision buys back both memory and math throughput by using a smaller number format, and the bf16 versus fp16 choice is about which 16-bit format keeps training stable. Gradient checkpointing buys back memory alone, and it pays for that memory with extra compute. They can be used together, and in practice usually are.

This deep dive walks the bit-level difference between fp16 and bf16, why that difference makes loss scaling necessary for one and pointless for the other, the precision cost bf16 pays, and then the separate mechanics and economics of gradient checkpointing.

How fp16 and bf16 split their bits

A floating point number splits its bits between an exponent, which sets the magnitude or range, and a mantissa, which sets the precision within that range. Both fp16 and bf16 are 16-bit formats, so each has a fixed budget to divide.

fp16 spends 5 bits on the exponent and 10 on the mantissa, plus 1 sign bit. That buys fine precision but a narrow range of roughly 10^-5 to 10^4. bf16 instead spends 8 bits on the exponent and 7 on the mantissa. Those 8 exponent bits are exactly what fp32 uses, so bf16 inherits the fp32 range of roughly 10^-38 to 10^38 while giving up precision.

The headline contrast is simple. fp16 is more precise but cramped in range. bf16 is coarser but matches the fp32 range. For gradients, range is the property that decides whether training is stable, which is why the bit split matters so much.

It helps to see why this design exists. fp16 is an IEEE format designed for graphics and inference, where values cluster in a predictable band and precision is at a premium. bf16 was designed at Google specifically for deep learning, where the priority is representing a huge spread of magnitudes rather than resolving them finely. The two formats are answers to two different questions, and LLM training asks the question bf16 was built for. A useful mental shortcut: bf16 is just fp32 with the bottom 16 mantissa bits chopped off, so converting between fp32 and bf16 is almost free and never changes the exponent.

Why range forces fp16 into loss scaling
The precision cost bf16 pays, and why it still works
Gradient checkpointing: the recompute trade
Memory-bound versus compute-bound: when to enable each
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
Propertyfp16bf16
Exponent / mantissa bits5 / 108 / 7
Dynamic rangeNarrow (~10^-5 to 10^4)fp32-equivalent (~10^-38 to 10^38)
PrecisionHigher (10 mantissa bits)Lower (7 mantissa bits)
Loss scalingRequired (dynamic)Not needed
Training stability on LLMsNaN-prone without careStable by default

Real products, models, and research that use this idea.

  • Llama 3.1 and DeepSeek V4 pretraining and fine-tuning pipelines default to bf16 on H100 and TPU hardware, avoiding fp16 loss scaling entirely.
  • Hugging Face TRL and Axolotl set bf16=True and gradient_checkpointing=True as the standard recipe for LoRA fine-tuning open-weight models.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QWhy does bf16 training match fp32 despite having only 7 mantissa bits?
A

Think about where precision is actually needed. Optimizer master weights and accumulations stay in fp32, so rounding noise on the bf16 forward and backward averages out across many steps rather than compounding.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Saying bf16 is just more accurate than fp16. It is actually less precise (7 mantissa bits) but has far wider range, and that range is what removes loss scaling.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • How fp16 and bf16 split their 16 bits differently

  • Why exponent range, not precision, matters for gradients

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
What is RLHF, and why is it used after pretraining?
MCQ·Easy