Repository navigation
fix: sanitize non-finite logprobs in vllm async worker - #2962
yuchenwang3 wants to merge 1 commit into
Conversation
9b450c8 to
eb836d6
Compare
eb836d6 to
922710d
Compare
|
This has been waiting on the copy-pr-bot gate since Jun 26 — could a maintainer |
922710d to
7065be6
Compare
|
@yuki-97 sorry for the direct ping — you're the most recent committer on |
There was a problem hiding this comment.
thanks @yuchenwang3 , fix LGTM.
but @yfw @ananthsub could you help confirm whether this will affect something?
it looks like:
- before: traj with nan logprobs will return http 500 to gym.
- after: will return traj, and replace logprobs nan with 0.
|
Thanks @yuki-97! Unit test added in 3e688cb — covers the float / nested-dict / nested-list branches plus ±inf and non-float passthrough, per your sketch. On the behavior question for @yfw @ananthsub: the intent is that a single non-finite logprob no longer 500s the whole request (which aborts GRPO rollout collection through the Gym proxy). Replacing with 0.0 makes the affected token look more likely under the rollout policy, so any importance-style correction downweights rather than amplifies it — conservative in that direction — and the train-time recomputed logprobs (which dominate the loss) are unaffected. Happy to switch the sentinel or drop only the affected trajectory instead if you'd prefer different semantics. |
|
@yfw @ananthsub bump — unit tests went in three weeks ago per @yuki-97's sketch, CI is green, and the one open item is the behavior question in my Jul 15 comment that's addressed to you two. Could you weigh in so this can move to a decision? |
|
hi @terrykong , could you help take a look? #2962 (review) |
|
@yuchenwang3 sorry for the delay in looking into this. In the past when we've seen nan logprobs, this was usually indicative of a bug in vllm. My concern is this may mask an issue with the inference engine that needs further investigation. Do you have some cases where the nan logprob is expected from vllm? |
e56338d to
219af62
Compare
|
@yfw @ananthsub @terrykong @yuki-97 — I refreshed this onto current main and resolved the only conflict (the new refit-watchdog import and this helper shared the same insertion point; both are preserved). The sanitize + one-warning/count behavior is unchanged. Current head: |
219af62 to
0a53d46
Compare
|
/ok to test 0a53d46 |
|
@yfw, following up on your concern about masking inference-engine bugs. The PR now makes replacements observable with a per-response warning and count, but the policy choice still needs your judgment: is sanitize-with-warning acceptable, or should these responses fail/be dropped? Could you confirm the preferred direction before we take this further? Thanks. |
|
Synced with current main and resolved the async-worker conflicts. The upstream engine-loop adapter and token-capture path are preserved; response sanitization now happens after capture, immediately before JSON serialization. This leaves the original capture input untouched. Changed-file Ruff/format checks pass. Isolated CPU checks cover NaN/Inf serialization, preservation of finite values and capture coordinates, and AST comparison confirming the rest of the upstream async worker is unchanged. These are not full vLLM/Ray integration tests. The sanitize-versus-reject design question remains open; this update does not change that policy. |
a10ef2b to
3e21158
Compare
|
@jepio Rebased at |
|
@yfw To answer your earlier question directly: I do not have a case showing that NaN logprobs are expected. The reproduced NaN is an inference failure. Making the response JSON-serializable does not establish that the sample is valid for training, so the current |
vLLM can return NaN or Inf logprobs, which Starlette JSONResponse rejects because it serializes with allow_nan=False. Sanitize the dumped response before serialization so the rollout request remains valid JSON. Emit one warning with a per-response replacement count so numerical instability remains visible, and cover nested values plus warning behavior with a unit test. Signed-off-by: Yuchen Wang <[email protected]> (cherry picked from commit e56338d) Signed-off-by: Yuchen Wang <[email protected]>
3e21158 to
8a5e9da
Compare
|
There is now a concrete upstream policy dependency here: main at bf50129 explicitly tests that an uncaptured Gym call with non-finite logprobs fails and is retried, matching the native HTTP endpoint (test). Captured rollout transport separately preserves non-finite values through strict JSON. Moving this PR's zero substitution into the newly extracted |
|
Closing: main now handles NaN logprobs by failing the request and retrying (#4979), and the clamp itself is proposed in vLLM in vllm-project/vllm#68261. |
vLLM can emit non-finite logprobs. We hit a NaN consistently around 49K context, and vLLM also uses
-infintentionally when sampling filters remove tokens. Starlette'sJSONResponseserializes withallow_nan=False, so any remaining NaN or infinity raisesValueErrorand turns the chat-completion request into a 500.This PR sanitizes the dumped response immediately before JSON serialization:
+inf, and-inffloats with0.0;model_dump_chat_response_with_dynamic_message_fieldsresult onmain.0.0is the replacement used by the current patch. This makes the response serializable; it does not establish that the rollout is numerically valid. The warning/count preserves a diagnostic, but the policy remains under discussion: non-finite rollouts may need to be rejected or dropped instead of substituting logprobs.The unit test covers nested dict/list values, all three non-finite forms, finite and non-float passthrough, replacement count, one-warning behavior, and the no-warning finite path. Ruff lint/format, syntax compilation, and DCO pass on the rebased head.
Recent bounded retry and exhausted-rollout handling reduce the blast radius of a 500, but they do not make this response serializable; a deterministic NaN can still fail every retry. This keeps the fix at the source boundary.