esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
Let’s talk

I’ll build the agent for it.

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.

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

  1. 1The big value goes into the conversion step.
  2. 2Values well above 65,504 turn into infinity.
  3. 3Infinity meets the next maths. It can give NaN, which spreads.
A few huge values pass through the conversion to FP16, where values well above 65,504 become infinity. Infinity can then turn into NaN in the next steps, and the output breaks.

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. 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. 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. 3

    Or use BF16 if the chip supports it

    The whole run keeps FP32's range, with a little less precision.

  4. 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

  1. 1Keep the sensitive steps in full precision.
  2. 2Or switch the whole run to BF16.
  3. 3Check the fixed run on real prompts.
  4. 4Check the BF16 run the same way.
A short order to try when a converted model breaks: find the first bad layer, then either keep risky steps in full precision or switch to BF16. Both paths end in the same retest on real prompts.

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. 1

    Find the layer

    The logs show the first infinity in one attention layer, only on the long inputs.

  2. 2

    Read the cause

    Those inputs push that layer's values past 65,504, so the conversion turns them into infinity.

  3. 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.

Python
# 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

1 / 6

What will they ask next?

  1. Q311What is quantization?10 min
  2. Q312INT8 vs INT4 vs FP8?14 min
  3. Q313GPTQ, AWQ and GGUF in one line each?8 min
  4. Q074What uses memory at inference time?11 min

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.