3.3.9 · D3Deep Learning Frameworks

Worked examples — Mixed precision training

3,144 words14 min readBack to topic

This page is the "put a number in every box" companion to Mixed precision training. The parent note taught you the three moving parts — FP32 master weights, loss scaling, and FP16 arithmetic. Here we do not add new theory. We take every kind of situation those parts can land in and grind through an actual worked number, so that when you meet one on an exam or in a real training log, you have already seen its twin.

Before any symbol appears, we agree on plain words:

The whole game is the picture below — read it now, we will point back to it in the examples. Its horizontal axis is number magnitude on a log scale (each tick a power of ten). The violet band is FP16's full-precision normal zone; the magenta strip to its left is the subnormal zone (numbers survive but lose bits); left of that is pure underflow; the orange strip on the right is overflow. The violet arrow shows loss scaling sliding a doomed tiny gradient rightward onto the safe ruler. Everything on this page is one of those two failures (fall off the left = underflow, fall off the right = overflow), or the fix.

Figure — Mixed precision training

The scenario matrix

Every situation this topic throws at you falls in exactly one of these cells. The last column names the worked example that fills it. (Recall is the relative tick size defined above; near a value the absolute tick is .)

# Case class The tricky quantity What can go wrong Example
A Tiny weight update vs FP16 tick update rounds to 0 → training stalls Ex 1
B Gradient underflow (small ) grad → 0, dead neuron Ex 2
C Loss-scale overflow (too big ) grad → inf, step skipped Ex 3
D Dynamic scaler: skip → halve → recover → double over time picking automatically Ex 4
E Degenerate input: exact power of two no-op, must stay exact Ex 5
F BF16 vs FP16 trade (range vs precision) same big/small range fine, precision coarse Ex 6
G Real-world word problem: memory budget bytes per tensor does the model fit? Ex 7
H Exam twist: gradient accumulation + scaling scale vs accumulation order double-count or lose scale Ex 8

Worked examples


Recall Quick self-check

A weight update near in FP16 rounds to what, and why? ::: To — the update is far below FP16's local absolute tick , so it vanishes; the FP32 master saves it. Loss scale , largest gradient — what breaks? ::: , so FP16 overflows to inf and the step is skipped. Dynamic scaler on overflow does what two things? ::: Halves and skips (does not apply) the corrupt update. Why does BF16 usually need no loss scaling? ::: BF16 shares FP32's 8 exponent bits, so its range reaches (subnormals to ) and tiny gradients don't underflow — it trades mantissa (precision) for that range. In gradient accumulation, you unscale by how many times? ::: Once, after summing all micro-batch gradients — unscaling is linear so once suffices and rounds less. What is the difference between FP16 normal and subnormal numbers? ::: Normal ( to ) has full 10-bit precision; subnormal ( to ) still stores values but with fewer significant bits; below everything underflows to .