Skip to content

[CI] Add option to raise an exception when NaNs are detected in logits - #50323

Merged
tlrmchlsmth merged 12 commits into
vllm-project:mainfrom
tlrmchlsmth:ci/fail-on-nan-logits
Aug 4, 2026
Merged

[CI] Add option to raise an exception when NaNs are detected in logits#50323
tlrmchlsmth merged 12 commits into
vllm-project:mainfrom
tlrmchlsmth:ci/fail-on-nan-logits

Conversation

@tlrmchlsmth

Copy link
Copy Markdown
Member

This PR sets VLLM_COMPUTE_NANS_IN_LOGITS=1 in several evals so we can test against NaNs.

NaNs appearing in logits often co-appear with KV cache NaNs, which is a catastrophic failure mode for a inference service since attention kernels mask with multiplication by zero. (see Dao-AILab/flash-attention#1974)

Assisted-by: OpenAI Codex

Assisted-by: OpenAI Codex
Signed-off-by: Tyler Michael Smith <tlrmchlsmth@gmail.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@tlrmchlsmth

Copy link
Copy Markdown
Member Author

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM — CI-only change wiring existing NaN-logits detection infra into the eval test suite, no production code touched.

Extended reasoning...

Overview

This PR touches only test/CI infrastructure: buildkite scheduled-integration scripts and tests/evals/* correctness tests. It adds a new tests/evals/metrics.py helper (assert_no_nan_logits) that scrapes the /metrics endpoint for the vllm:corrupted_requests_total counter and asserts it stays at zero, then wires VLLM_COMPUTE_NANS_IN_LOGITS=1 into the various eval harnesses (GSM8K, GPQA, MRCR, lm-eval) so that NaN-logit corruption fails the eval instead of silently producing garbage accuracy numbers.

Security risks

None. No production code paths (attention kernels, sampler, scheduler, etc.) are modified — VLLM_COMPUTE_NANS_IN_LOGITS and the vllm:corrupted_requests counter already exist in vllm/v1/metrics/loggers.py, vllm/v1/worker/gpu_model_runner.py, and vllm/envs.py; this PR only turns the flag on in test harnesses and asserts on the pre-existing metric.

Level of scrutiny

Low-to-moderate. This is CI/test-only tooling with no impact on the served product; the new helper has direct unit test coverage (test_assert_no_nan_logits parametrized over missing-metric, zero, and multi-engine-nonzero cases) that exercises the parsing/aggregation logic exactly as it will be used against a real /metrics payload.

Other factors

I confirmed the metric name matches: the underlying Counter is a prometheus_client.Counter, which Prometheus auto-suffixes with _total on scrape, matching what assert_no_nan_logits queries for. I also confirmed --host/--port construction in gsm8k_eval.py's new --check-nan-logits path is consistent with how the buildkite scripts invoke it (--host http://127.0.0.1). The change is mechanical and consistently applied across all five eval call sites.

Assisted-by: OpenAI Codex
Signed-off-by: Tyler Michael Smith <tlrmchlsmth@gmail.com>
trap cleanup EXIT

for BACK in "${BACKENDS[@]}"; do
VLLM_COMPUTE_NANS_IN_LOGITS=1 \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we let each hw backend determine the value of that? tbh if this goes through i would ask if you could set it in run-am-tests.sh so that it is enabled by default on amd for everything. or you think that it should be kept in test level?

@njhill

njhill commented Jul 29, 2026

Copy link
Copy Markdown
Member

Thanks @tlrmchlsmth this looks great!

I wonder though, rather than relying on scraping the metrics, we could maybe have a VLLM_COMPUTE_NANS_IN_LOGITS mode where an exception is raised if a NaN is encountered. Then we can just set that globally for the whole CI (doesn't even need to be added per test). Basically it would just blow up the test if encountered.

@mgoin

mgoin commented Jul 30, 2026

Copy link
Copy Markdown
Member

^ +1 to Nick's suggestion! I'd like this to be global on CI and raise so the pytest/script fails

@tlrmchlsmth

Copy link
Copy Markdown
Member Author

Going to add VLLM_RAISE_ON_LOGIT_NANS or something and then set it in all of buildkite

Replace per-eval metrics scraping with a runtime flag that raises as soon as NaN logits reach output bookkeeping. The flag implies existing NaN computation and covers both GPU model runners.

Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Tyler Michael Smith <tlrmchlsmth@gmail.com>
@tlrmchlsmth
tlrmchlsmth requested a review from WoosukKwon as a code owner July 30, 2026 19:30
tlrmchlsmth and others added 5 commits July 30, 2026 15:38
Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Tyler Michael Smith <tlrmchlsmth@gmail.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Tyler Michael Smith <tlrmchlsmth@gmail.com>
Inject NaN logits through the GPU model runner and assert that the runtime flag raises for the affected request.

Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Tyler Michael Smith <tlrmchlsmth@gmail.com>
Replace the direct detector test with inference tests that force model runner v1 and v2, inject a NaN from model logits computation, and assert generation fails.

Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Tyler Michael Smith <tlrmchlsmth@gmail.com>
Only build the corrupted-request mapping after detecting a nonzero NaN count.

Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Tyler Michael Smith <tlrmchlsmth@gmail.com>
@tlrmchlsmth

Copy link
Copy Markdown
Member Author

partner PR is up here vllm-project/ci-infra#444

@mergify mergify Bot added the mrv2 Model Runner V2 specific label Jul 30, 2026
@tlrmchlsmth tlrmchlsmth added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 3, 2026

@njhill njhill left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @tlrmchlsmth LGTM

@github-project-automation github-project-automation Bot moved this from To Triage to Ready in gpt-oss Issues & Enhancements Aug 3, 2026
Signed-off-by: Tyler Michael Smith <tlrmchlsmth@gmail.com>
@tlrmchlsmth

Copy link
Copy Markdown
Member Author

Switching the envs to 1 to see if anything breaks -- so nobody merge it yet ;)

Comment thread vllm/envs.py Outdated
Avoid retaining the v2 model through a bound method in the injected-NaN test, and restore opt-in defaults for logit NaN detection.

Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Tyler Michael Smith <tlrmchlsmth@gmail.com>
@tlrmchlsmth
tlrmchlsmth enabled auto-merge (squash) August 4, 2026 13:32
@tlrmchlsmth tlrmchlsmth changed the title [CI] Detect and fail evals on when NaNs appear in logits [CI] Add option to raise an exception when NaNs are detected in logits Aug 4, 2026
@tlrmchlsmth
tlrmchlsmth merged commit 12292d9 into vllm-project:main Aug 4, 2026
114 checks passed
vrdn-23 added a commit to vrdn-23/vllm that referenced this pull request Aug 7, 2026
…nflicts

Dropped the legacy TYPE_CHECKING block and environment_variables dict
wholesale, then ported main's delta across 10 main-side commits:

Additions: VLLM_ROCM_USE_AITER_MOE_SITUV2_A8W4 (vllm-project#50582), VLLM_USE_RUST_BENCH
(vllm-project#50081), VLLM_KIMI_K3_SHARD_SP_SHARED_EXPERT (vllm-project#50656),
VLLM_RAISE_ON_LOGIT_NANS (vllm-project#50323), VLLM_ENABLE_COHERE_API (vllm-project#47189).
Modifications: VLLM_COMPUTE_NANS_IN_LOGITS is now implied by
VLLM_RAISE_ON_LOGIT_NANS (cross-field, so a model_validator);
_resolve_rust_frontend_path -> _resolve_rust_cli_path, resolving on either
VLLM_USE_RUST_FRONTEND or VLLM_USE_RUST_BENCH.
Deletions: VLLM_CPU_SGL_KERNEL (vllm-project#50801), Q_/K_/V_SCALE_CONSTANT (vllm-project#49389 --
main deleted the dict entries but left the TYPE_CHECKING annotations;
followed the PR's intent).
tests: ported VLLMValidationError assertions; adapted
test_rust_bench_auto_path_missing_fails_fast to construct ServerSettings
directly. Dropped the Q_SCALE_CONSTANT case from test_envs_pydantic.py.

AI assistance (Claude) was used for this merge resolution.

Co-authored-by: Claude
Signed-off-by: Vinay Damodaran <vrdn@hey.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/build gpt-oss Related to GPT-OSS models kv-connector mrv2 Model Runner V2 specific ready ONLY add when PR is ready to merge/full CI is needed v1

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants