3.3.9 · D1Deep Learning Frameworks

Foundations — Mixed precision training

1,829 words8 min readBack to topic

Before you can read the parent note on Mixed precision training, you must be able to picture what a "precision format" actually is, why a tiny number can vanish, and what every symbol like , , , and means. We build each one from nothing, in an order where every piece leans only on the pieces before it.


1. A number lives in a box of bits

A bit is a single switch: it is either or . That's the whole alphabet a computer has.

To store a "real" number like or , the computer glues a fixed number of bits together and agrees on a rule for reading them. The rule used everywhere in deep learning is called floating point. Think of it like scientific notation you already know:

Three separate jobs are hidden in that expression, and floating point stores exactly these three jobs as three groups of bits:

  • the sign (): is the number positive or negative? → 1 bit.
  • the exponent (): how big is the number, i.e. where does the decimal point sit? → some bits.
  • the mantissa (the part, also called the fraction or significand): the actual digits, how precise the number is → the remaining bits.
Figure — Mixed precision training

The parent note's whole table (FP32, FP16, BF16) is just different splits of the same total bits between these three jobs. Keep this picture: exponent = how wide a net; mantissa = how fine the mesh.


2. Range vs. precision — two different limits

These two words get confused, so pin them down with a picture.

  • Range = the smallest and largest magnitudes the format can reach at all. Set by the exponent bits. If a number is bigger than the max, you get overflow (the value becomes , written inf). If it is smaller than the min, you get underflow (the value collapses to ).
  • Precision = the gap between neighbouring representable numbers. Set by the mantissa bits. Numbers that land between two representable neighbours get snapped to the nearest one — this snapping is called rounding.
Figure — Mixed precision training

The parent note quotes:

  • FP32: 8 exponent + 23 mantissa → range to , precision .
  • FP16: 5 exponent + 10 mantissa → range to , precision .
  • BF16: 8 exponent + 7 mantissa → FP32's range, but coarser precision .

Notice BF16 spends its bits on exponent (wide net) rather than mantissa (fine mesh) — that is why it "can't underflow like FP16 but is blurrier." See 1.3.07-Numerical-stability for the general study of when arithmetic quietly breaks like this.


3. Rounding and casting — moving a number between boxes

So when the parent writes , it means "copy the master weight into the coarse format for fast computation," accepting a little rounding. When it writes , no information is lost — we are only widening the box.


4. The symbols from training itself

Mixed precision sits inside ordinary gradient-descent training, so you must know these symbols cold. Each is a plain object with a picture.

Put together, one step of gradient descent is:

Figure — Mixed precision training

Why does (the partial derivative) appear at all, and not some simpler measure? Because we want the direction that changes the loss fastest, and the derivative is precisely the tool that answers "rate of change of one quantity as another wiggles." Nothing else gives you the slope of in the direction.


5. The chain rule — why gradients get tiny

The parent note writes:

Here is an activation — the output of some neuron between the input and the loss. The chain rule says: to know how affects the final loss , multiply how affects the nearby activation by how affects .

Why does this cause tiny numbers? In a deep network, depends on through many layers, so the gradient is a product of many such factors. Multiply a dozen numbers each around and you get something like — a number that FP16 cannot even represent. That is the exact failure the parent note's loss scaling fixes.


6. Where the speed actually comes from

The memory savings interact with sibling techniques: 3.3.08-Gradient-accumulation, 3.3.10-Gradient-checkpointing, and 5.1.02-Model-parallelism all fight the same "does it fit on the GPU?" battle from different angles.


Prerequisite map

bits and floating point

sign exponent mantissa

range vs precision

rounding and casting

underflow and overflow

gradient descent w eta g

chain rule tiny gradients

FP32 master weights

loss scaling factor S

GEMM and Tensor Cores

FP16 for speed

Mixed Precision Training


Equipment checklist

Cover the answer and test yourself. If any line is shaky, reread that section before the parent note.

What are the three groups of bits in a floating-point number?
Sign (1 bit), exponent (scale/range), mantissa (digits/precision).
Which bits control range, and which control precision?
Exponent bits control range; mantissa bits control precision.
What is underflow?
A nonzero number smaller than the format's minimum magnitude collapses to .
What is overflow?
A number larger than the format's maximum becomes inf.
Why can't casting FP16 → FP32 recover lost precision?
The value was already snapped to an FP16 tick; widening the box keeps the snapped value.
In , what is and what is ?
is the learning rate (step size); is the gradient (slope of loss w.r.t. ).
Why does the product matter for FP16?
If it is smaller than the FP16 mesh (~), the weight update rounds away to nothing.
Why does the chain rule make gradients tiny in deep nets?
The gradient is a product of many per-layer factors, and many sub-1 factors multiply down to ~.
What does the loss-scale factor do?
Multiplies the loss (hence every gradient) by a big constant to lift tiny gradients into FP16 range; divided out before the update.
What is a GEMM and why is FP16 fast for it?
A big matrix multiply; Tensor Cores run FP16 GEMMs several times faster than FP32.