Zain Dana Harpernight school / K24

Mixed precision.

Graphics chips multiply 16-bit numbers fastest. Tallow measures where fp16 and bf16 can put a value, adds 1 to a running total until it stops moving, and scores the whole model with 16-bit inputs and with 16-bit sums.

The film

About 4:23, hosted by Tallow. It asks you one question and waits for your answer before it shows you. The guide's voice is not recorded yet, so for now the film plays with captions; the full words are also below.

Nothing loads until you press play.

The lab: the measuring jugs

Type a number and see the values each format can store around it; run a long sum; or score the model on held-out rows in each mode. In the film, adding 1 stalled at 2,048 in fp16 and 256 in bf16; near 110, fp16's marks are 0.0625 apart. The model's loss was 0.6676 in 32 bits and 0.6679 in bf16 throughout.

Everything is computed on your computer, in this page. Nothing is sent anywhere.

Everything the film says

fp16, bf16 and tensor cores

fp16, bf16 and tensor cores.

Graphics chips multiply much faster in 16-bit numbers than in 32-bit ones. Tonight Tallow measures what a 16-bit number can hold, where it goes wrong, and why the sums are often kept in 32 bits.

Measuring jugs

Think of a number format as a measuring jug. The marks are its precision; the height is its range.

fp16 has 11 bits of significand and tops out at 65,504. bf16 keeps the range of 32-bit numbers but has only 8 bits of significand. 32-bit numbers have 24.

Near one hundred and ten

Look at the marks near 110. In fp16 they are 0.0625 apart. In bf16, 0.5. Any number in between is rounded to the nearest mark.

fp16 near 110. How far apart are the marks? (the film pauses here)

So in fp16 a number near 110 can be off by up to one thirty-second, about 0.03. That is about three parts in ten thousand. A job that needs one part in ten thousand needs a significand of 13 bits; fp16 has 11. We will need that in the next lesson.

A sum that stops

Now add 1 to a running total, five thousand times, keeping the total in fp16.

It stops at 2,048. There the marks are 2 apart, and adding 1 rounds back to where it was. In bf16 it stops at 256.

Small inputs, big sums

This is why tensor cores, the units that multiply small tables of numbers in one step, can take 16-bit inputs and keep the running sums in 32 bits. With fp16 inputs they can also sum in fp16. With bf16 inputs, the sums are always 32-bit.

Paulius Micikevicius and colleagues trained large networks this way in 2018 and kept a 32-bit master copy of the weights.

On the second floor's feed-forward table of our model, the error with fp16 inputs and 32-bit sums is about 0.0003 of the answer's size. Keep the sums in fp16 too, and it grows to about 0.001.

The whole model

Run the whole model with every stored number rounded to 16 bits and score it on 1,024 held-out rows.

The loss barely moves. It stays at 0.6676 with fp16 inputs and 32-bit sums, and rises to 0.6679 with bf16 throughout. Its numbers stay far below fp16's limit, so nothing overflows. Its sums are short, at most 64 terms, so the rounding hardly shows.

We only ran this model in 16 bits; we did not train it that way. When large models are trained in 16 bits, the rounding can show. Micikevicius and colleagues needed three fixes to stop it.

Goodnight

Small inputs, big sums: the marks you can afford for the parts, and the marks you need for the total.

Next, at the prism: one glint of light that 16 bits could not hold precisely enough. Goodnight.

Sources

Every claim in the film, with where it comes from and what that source does not prove. The numbers about the model are computed from its weights, which you can load and check: facts.json.

What this lesson leaves out

The 16-bit formats are emulated by rounding in the main processor; no graphics chip and no tensor core ran these numbers.

One small model; its scores are small enough that fp16 never overflows here, which large models cannot count on.

Scores on 1,024 held-out rows; differences from 32 bits are paired on the same rows.

Before this: Fused attention (K23). Earlier: Quantisation (S18).