Skip to content

Warn when building gpt-oss with float16 I/O precision - #2444

Open
Gopalakrishnan Nallasamy (GopalakrishnanN) wants to merge 1 commit into
microsoft:mainfrom
GopalakrishnanN:fix/gptoss-fp16-nan-warning
Open

Warn when building gpt-oss with float16 I/O precision#2444
Gopalakrishnan Nallasamy (GopalakrishnanN) wants to merge 1 commit into
microsoft:mainfrom
GopalakrishnanN:fix/gptoss-fp16-nan-warning

Conversation

@GopalakrishnanN

Copy link
Copy Markdown
Contributor

gpt-oss activations grow through the decoder and exceed the float16 range in the final layers. Instrumenting the graph shows the max absolute activation climbing from ~35 at layer 0 to ~45,344 at layer 34; layer 35 passes the 65,504 ceiling and every logit comes back NaN. argmax over all-NaN returns index 0, so the model emits one repeated token ("!") instead of text.

This is silent: the build succeeds and the model loads and runs at full speed. Warn when io_dtype is float16, matching the existing Gemma2/Gemma3 warnings, and point at --precision bf16 or --extra_options use_cuda_bf16=true.

Should the builder instead default use_cuda_bf16=true for gpt-oss? A warning still lets users produce a model that only emits NaN, but defaulting would silently change the output dtype for anyone currently passing --precision int4 -e cuda.

gpt-oss activations grow through the decoder and exceed the float16 range in the
final layers. Instrumenting the graph shows the max absolute activation climbing
from ~35 at layer 0 to ~45,344 at layer 34; layer 35 passes the 65,504 ceiling
and every logit comes back NaN. argmax over all-NaN returns index 0, so the model
emits one repeated token ("!") instead of text.

This is silent: the build succeeds and the model loads and runs at full speed.
Warn when io_dtype is float16, matching the existing Gemma2/Gemma3 warnings, and
point at --precision bf16 or --extra_options use_cuda_bf16=true.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a runtime build-time warning in the Python model builder to help users avoid generating GPT-OSS ONNX models whose float16 I/O precision can overflow in late layers and produce NaN logits (leading to degenerate output).

Changes:

  • Emit a targeted warning when building GptOssForCausalLM with float16 I/O precision.
  • Direct users toward using BF16 precision (and CUDA BF16 I/O for int4) to avoid NaN logits.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +504 to +505
if io_dtype == ir.DataType.FLOAT16:
print("WARNING: This model overflows the float16 range in its last layers, which produces NaN logits. Set `--precision bf16` or `--precision int4 --extra_options use_cuda_bf16=true`.")
@tianleiwu

Tianlei Wu (tianleiwu) commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

I think gpt-oss-20b has no overflow. We have a foundry local gpt-oss-20b model with fp16 I/O.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants