From 6fe7401fac6e708dd9bbffd61c0fdae00c14a7df Mon Sep 17 00:00:00 2001 From: Pei Li Date: Thu, 15 Oct 2026 03:35:54 -0700 Subject: [PATCH] [Perf] Read VLLM_COMPUTE_NANS_IN_LOGITS once per IterationStats (#61710) Signed-off-by: Pei Li Co-authored-by: Kevin H. Luu --- vllm/v1/metrics/stats.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vllm/v1/metrics/stats.py b/vllm/v1/metrics/stats.py index 87277f6545..d30e857fa2 100644 --- a/vllm/v1/metrics/stats.py +++ b/vllm/v1/metrics/stats.py @@ -476,6 +476,10 @@ class IterationStats: def __init__(self): self.iteration_timestamp = time.time() + # Read once per iteration: update_from_output runs per request per + # step, and each envs attribute access re-reads the environment + # in processes that never enable the envs cache (the API server). + self.compute_nans_in_logits = envs.VLLM_COMPUTE_NANS_IN_LOGITS self.num_generation_tokens = 0 self.prompt_token_stats = PromptTokenStats() self.num_preempted_reqs = 0 @@ -527,7 +531,7 @@ class IterationStats: # Track if this request is corrupted (only check once per request) # Early exit if already marked as corrupted to avoid redundant checks if ( - envs.VLLM_COMPUTE_NANS_IN_LOGITS + self.compute_nans_in_logits and not req_stats.is_corrupted and output.num_nans_in_logits > 0 ):