TensoriumInterview preparation
← Home

Core concepts · 62 topics

A guided path through the ideas behind modern LLMs.

Read the stages in order: how text becomes a prediction, what happens inside the Transformer block, how a model learns, then serving, scale, and post-training. Every topic names what to know first, then gives the intuition, the math with concrete numbers, the common misconception, and a self-check. Already comfortable with the basics? Switch to By area and jump straight to a topic.

New to machine learning? Start here instead.

These topics work best as a refresher; they assume ideas like probability and loss. Begin with three short beginner lessons (tokens, embeddings, next-token prediction), then the visual walkthrough for attention and the Transformer.

Finish line: You can explain how text becomes a prediction and what training does to improve that prediction.

Topic 34 of 62 · Training at scale

FP16, BF16, and mixed precision

Medium

How do FP16 and BF16 divide their 16 bits differently, and why does FP16 require dynamic loss scaling?

Why this mattersKnowing the exponent-vs-mantissa trade-off between FP16 and BF16—and why master weights stay in FP32—is essential for both memory sizing and numerical debugging.

1 · Start with the intuition

Every 16-bit floating-point format has to split 15 non-sign bits between exponent (dynamic range: how large or small a number can be) and mantissa/fraction (precision: how finely spaced two nearby numbers are). FP16 uses 5 exponent bits and 10 fraction bits, giving good precision near 1.0 but a tiny dynamic range that overflows above 65,504 and loses small gradients: below 2⁻¹⁴ ≈ 6.1 × 10⁻⁵ values become subnormal with fewer significant bits, and below about 3 × 10⁻⁸ they round to zero. BF16 keeps the exact 8-bit exponent of FP32 and leaves 7 fraction bits—matching FP32’s huge dynamic range so gradients almost never underflow, removing the need for FP16-style loss scaling.

2 · How the mechanism works

Mechanism step 1 of 3 · no question to answer

Run matmuls in 16-bit

Execute tensor-core matrix multiplications in BF16 or FP16 while accumulating dot products in FP32.

Next, we will look at: Keep sensitive state in FP32. Move on when this operation makes sense.

Visualizing the behavior

Bit layouts: sign · exponent · mantissa

Spec
FP3232 bits
8
23
BF1616 bits
8
7
FP1616 bits
5
10
  • Sign
  • Exponent → range
  • Mantissa → precision
BF16 keeps FP32’s 8 exponent bits (same range) but has fewer mantissa bits than FP16. FP16 is more precise but overflows above 65,504 and underflows small gradients, which is why it needs loss scaling.

Range vs precision

Spec

Largest finite value

FP16
65,504
BF16
≈ 3.4e38
FP32
≈ 3.4e38

Gap between 1.0 and the next value (smaller = finer)

FP16
9.8e-4
BF16
7.8e-3
FP32
1.2e-7
Log scale, each group scaled separately. BF16 rarely overflows, but adding an update smaller than about 0.4% to a weight near 1.0 can be rounded away. That is why master weights and optimizer updates stay in FP32.