Why Does a Model Output Garbage After FP16 Conversion?
Why FP16's low top value breaks some models after conversion, how to find the bad layer, and the fix, explained simply for your AI interview.
In short
FP16 can only hold numbers up to 65,504, so some internal values of a model turn into infinity when converted. Infinity can turn into NaN in the next steps, and then the output breaks. Find the first bad layer, keep risky steps in full precision, or use BF16.
9 min readAdvancedOccasional · estimateFacts checked 27 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
FP16 is a 16-bit number format, and its biggest value is 65,504. A model's inside numbers can be bigger than that. When I convert, those numbers turn into infinity, and infinity can make not-a-number values (NaN) that spread through the model. So the output turns to garbage. The fix: find the first bad layer, keep the risky steps in full precision, or use BF16, which has a wider range.
Floating point numbers are how a model stores its values. FP16 uses 16 bits, so it takes half the memory of FP32 and moves data faster. The cost is range. The biggest value FP16 can hold is 65,504, and values much bigger than that become infinity when converted.
Why does that break a model? Large language models have a few internal values far bigger than the rest. The massive activations paper says a few activations are far bigger than the rest, and gives one example about 100,000 times larger than typical ones. If a typical value is about 1, that one is above FP16's limit. Once it is infinity, the next arithmetic can produce NaN, and NaN spreads through the later layers. The answer comes out as garbage.
BF16 is the usual cure. It keeps the same range as FP32, so the big values survive, but it has less precision. Most models trained in BF16 cannot run in FP16's range, PyTorch's docs warn. So I would first find the first layer that shows infinity or NaN, keep softmax, layer norm and sums in FP32, and use BF16 if the chip supports it.
Last, I would test on long, messy real prompts and compare the answers with the full precision version. A short test would miss this bug.
What is FP16, in plain words?
A model keeps its numbers in a floating point format, a bit like scientific notation. FP16 stores each number in 16 bits, and FP32, the full format, uses 32. Fewer bits means less memory and faster moves, which is why people convert.
The trade is range. FP16 can only hold numbers up to 65,504. Anything bigger turns into infinity, and everything built on it goes wrong.
Think of a bank's old teller system. Its amount field holds up to 65,504, so a 91,000 payment does not fit. The screen shows infinity, and every running total after it is wrong. Inside a model, the same thing happens to a few big internal numbers.
Key words
- FP16
- A 16-bit number format: small and fast, with a narrow range.
- BF16
- Another 16-bit format. It keeps FP32's wide range and gives up some precision.
- Infinity
- What a number too big for FP16 becomes.
- NaN
- Not a Number. The result of impossible maths, like infinity minus infinity.
- Activation
- A number one layer of the model makes while it reads your text.
Why does one big number break the whole answer?
FP16 has one sign bit, five exponent bits and ten fraction bits. The exponent bits set the size, so the largest value FP16 can hold is 65,504. Official sources give the limit, and note that BF16 keeps FP32's range:
“Maximum normalized 65,504”
NVIDIA
“The dynamic range of bfloat16 and float32 are equivalent.”
Google Cloud
“most bf16-pretrained models cannot operate in the fp16 numerical range of max 65504”
PyTorch
Large language models do have very big internal values. The massive activations paper found that very few activations are far bigger than the rest, and it gives 100,000 times larger as one example. Its authors called them massive activations.
Do the sum. If a typical value is about 1, a value 100,000 times bigger is 100,000. That is above 65,504, so the conversion turns it into infinity. A paper on 8-bit inference, LLM.int8(), found highly systematic emergent features that dominate attention and transformer predictive performance, a related kind of large feature.
Then the damage spreads. The next step that touches infinity can produce NaN, and NaN passes into later layers. NVIDIA's guide warns that a loss scale that is too large can overflow during backpropagation, leaving gradients with infinities or NaNs that irreversibly damage the weights during the update. In a converted model, the output can show up as repeated symbols, random words, or one token again and again.
How a few huge values break the output
A few huge values
past FP16's 65,504 limit
Convert to FP16
well above 65,504 becomes infinity
Infinity
next steps can give NaN
Garbage output
NaN spreads to later layers
- 1The big value goes into the conversion step.
- 2Values well above 65,504 turn into infinity.
- 3Infinity meets the next maths. It can give NaN, which spreads.
How do you fix it?
BF16 usually avoids this, because it has FP32's range, so the big internal values fit. It pays for that with less precision, so the numbers are a little rougher. The fix is to find the break first, then change one thing at a time.
- 1
Find the first bad layer
Log the first layer that outputs an infinity or NaN. Only that layer shows where the range breaks.
- 2
Keep risky steps in FP32
Softmax, layer norm and sums can stay in full precision while the big matrix maths runs in FP16. PyTorch's autocast runs softmax, layer norm and sums in float32 on CUDA.
- 3
Or use BF16 if the chip supports it
The whole run keeps FP32's range, with a little less precision.
- 4
Test on real prompts
Run long, messy inputs through the fixed model and compare with the full precision answers. A short test misses this bug.
What to try when a converted model breaks
Find the first bad layer
log the first infinity or NaN
Keep risky steps in FP32
softmax, layer norm, sums
Use BF16 if the chip can
same range as FP32
Test on real long prompts
compare with full precision
- 1Keep the sensitive steps in full precision.
- 2Or switch the whole run to BF16.
- 3Check the fixed run on real prompts.
- 4Check the BF16 run the same way.
Tip
Don't cast the whole model and hope. A clean short test can pass while long inputs still break.
What does a real failure look like, in code?
A mid-size bank moves its support assistant to FP16 servers to cut memory costs. Short chats look fine. Long chats, where a customer pastes in several months of statements, come back as strings of symbols about one time in twenty.
- 1
Find the layer
The logs show the first infinity in one attention layer, only on the long inputs.
- 2
Read the cause
Those inputs push that layer's values past 65,504, so the conversion turns them into infinity.
- 3
Fix and retest
The team keeps that layer's sums in FP32, then reruns 500 saved long chats and matches the full precision answers.
The code below shows the same break in a few lines. A made-up layer produces one big value, and the conversion does the rest.
# A made-up layer of a model after conversion to FP16 (a 16-bit float).
# FP16 cannot hold anything above 65,504, so a bigger value becomes infinity.
import math
import struct
def to_fp16(x):
try:
return struct.unpack("<e", struct.pack("<e", x))[0]
except OverflowError:
return float("inf") # too big for FP16
# Most activations are small, but one value is far bigger.
activations = [0.8, -1.2, 0.3, 91000.0]
fp16 = [to_fp16(a) for a in activations]
print("FP16 copy:", fp16)
# A simplified step: subtract the average from every value.
mean = sum(fp16) / len(fp16)
print("Mean:", mean)
centred = [a - mean for a in fp16]
print("Centred:", centred)
print("Any NaN?", any(math.isnan(v) for v in centred))Output
FP16 copy: [0.7998046875, -1.2001953125, 0.300048828125, inf] Mean: inf Centred: [-inf, -inf, -inf, nan] Any NaN? True
What does the interviewer want to hear?
A strong answer covers
- FP16 tops out at 65,504, so bigger values become infinity.
- Models with big internal values break under FP16, which BF16 avoids.
- Infinity can turn into NaN, and NaN spreads, so the output is garbage.
- Fixes: find the first bad layer, keep risky steps in FP32, or use BF16.
- Always test on long, real prompts after any format change.
Common traps
Trap"Just retrain it in FP16, the bug will go away."
BetterRetraining is slow, and the number range still breaks the model. Find the first bad layer first.
Trap"FP16 is just less accurate, so there is a bit of noise."
BetterThe problem is range, not small rounding. Big values turn into infinity, and NaN spreads.
Trap"Just use FP16 everywhere, it is faster."
BetterSpeed only counts if the answers still match. Test on long real prompts first.
Can you spot the problem?
Spot the fix
A converted model gives correct answers on short chats but garbage on long ones. Which first step makes the most sense?
Quick check
Which format keeps the same range as FP32, at the cost of some precision?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
Last updated on 27 November 2026
Moving a model to a cheaper format and seeing strange output?
I design and build AI products and agents, the screens and the system behind them. Book a short call and tell me what you need.