Repository navigation
fix(nvidia_nim): forward logprobs and top_logprobs to NIM models that serve them - #54008
Conversation
…ponses NVIDIA NIM serves logprobs and top_logprobs, but nvidia_nim refused both with UnsupportedParamsError. The Responses bridge also never asked chat for logprobs when include requested message.output_text.logprobs, leaked top_logprobs on its own, and dropped the logprobs the model returned. It now maps include to chat logprobs and puts the tokens on output_text and the streaming events
…and keep this change to nvidia_nim params
…gprobs # Conflicts: # tests/unit/llms/nvidia_nim/test_nvidia_nim.py
[Medium impact] The PR appears safe to merge with no new actionable findings.
|
surlymochan
left a comment
There was a problem hiding this comment.
Verified the logic against the source rather than just the diff, and it holds up:
drops_unsupported_params(litellm/litellm_core_utils/core_helpers.py:424-425) returns true for either the per-call flag or the globallitellm.drop_params, so the parametrized test's global-flag cases exercise a real path, not just the argument.- Branch order in
map_openai_paramsis correct: thetop_logprobsdrop is checked before the genericparam in supported_openai_paramsbranch — sincetop_logprobsis now in the supported list, the check has to come first or the drop could never trigger. - The live-run matrix in the PR body (before: 400
UnsupportedParamsErroron all six cases; after: 200 with per-token logprobs on chat, including streaming) matches what the unit tests pin, including the/v1/responsescase returning 200 without logprobs until #49536.
One question, not a blocker: asks_logprobs uses non_default_params["logprobs"] is True, so a caller passing a truthy non-bool (e.g. logprobs=1) would be treated as not asking and top_logprobs would be dropped under drop_params. Is the strict check intentional, or should it be a truthiness check?
Non-binding review — leaving the merge decision to the maintainers.
…apes NIM cannot take
…gprobs # Conflicts: # litellm/llms/nvidia_nim/chat/transformation.py
…ls and name the proxy drop_params setting
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit d5c800d. Configure here.
…answering 400 Port of the nvidia_nim change in #54008 onto lts/1.108.x. NIM's supported params now list logprobs and top_logprobs, and top_logprobs sent without logprobs is dropped only under drop_params Source commits on main: e2a826c, 695e0e8, 537b438 (the first commit's Responses bridge work was reverted by the second, so only the nvidia_nim files move)
…s_1_108_x fix(nvidia_nim): forward logprobs and top_logprobs to NIM models that serve them on lts/1.108.x (#54008)
Handwritten 1-3 sentence description
Asking an NVIDIA NIM model for
logprobsortop_logprobson chat completions through LiteLLM now works on the models NVIDIA serves them for. Before this, LiteLLM refused the request with a 400, so people had to setallowed_openai_paramsordrop_params, and the second one threw away what they asked forDetails
TLDR
Problem this solves:
nvidia_nim/chat calls 400 onlogprobsandtop_logprobsHow it solves it:
User Flow
Before: a developer who wants token probabilities from an NVIDIA NIM model gets a 400 from LiteLLM
"model": "<nim model>"and"logprobs": truelitellm.UnsupportedParamsError: nvidia_nim does not support parameters: ['logprobs']"top_logprobs": 2gets the same 400 for both paramsAfter: the same request reaches NVIDIA and the reply carries per-token logprobs
"logprobs": truechoices[0].logprobs.contenthas itstokenandlogprob, streaming included"top_logprobs": 2returns the 2 most likely tokens for each positionPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Live runs against NVIDIA's hosted API (
integrate.api.nvidia.com).nim-lightningisnvidia/nemotron-3.5-lightning-30b-a3b, which NVIDIA serves logprobs for (openai/gpt-oss-20b, the model first used to reproduce this, was retired by NVIDIA on 2026-11-18).nim-kimiismoonshotai/kimi-k3.1-pro, which NVIDIA refuses logprobs for. Before runs at the merge base fbf539e and After at d5c800d. Cases 12 and 13 read the two model info routes, which should list logprobs only for a model whose chat accepts them. Every case prints the exact command it ran, including thejqfilter that keeps the reply readable, and that command's output. The first scored tokens ("Here", "'s") come from the model's reasoning, which NVIDIA scores too, as the direct call showsSetup, the same for both legs: 2 uvicorn workers sharing one dedicated Redis for router state and coordination, no DB since the change touches no DB path, and no
--reloadbecause it ignores--num_workers.LITELLM_LOCAL_MODEL_COST_MAP=Truemakes the proxy read the cost map from its own tree instead of the copy on main. Each leg ends with a worker check that sends 8 parallel streaming requests and lists which worker pid holds each connection. Env vars areNVIDIA_NIM_API_KEY,LITELLM_MASTER_KEYandLITELLM_LOCAL_MODEL_COST_MAP=Trueconfig.yaml and commands
NVIDIA directly
NVIDIA returns logprobs and top_logprobs, ignores top_logprobs alone, rejects an integer logprobs, and refuses logprobs on kimi-k3.1-pro
Before (fbf539e)
Every logprobs request answers 400, only drop_params or allowed_openai_params gets a 200 with no logprobs, and no model lists logprobs
After (d5c800d)
Chat and streaming return logprobs, kimi drops them under drop_params and does not list them, and shapes NVIDIA cannot take still get the clear 400
After, with #49536 merged in (21ec4635153)
This PR's commits through d5c800d, without its latest merge of main, with #49536 at 1bc94cb merged in. It is a local tree for this check only, since #49536 does not merge cleanly into the current main, and it uses the same setup as the other legs
/v1/responses returns logprobs with both PRs in, streaming included
Type
🐛 Bug Fix
Caveats (if any)
Medium
top_logprobsstill answers 400 until fix(responses): carry logprobs across the chat completions bridge #49536 mergesdrop_paramsif they refuse logprobsnvidia_nim/model with no cost-map row getslogprobssent to NVIDIA. If that model refuses them, the caller now gets NVIDIA's 400. Before,drop_params: truegave a 200 without logprobsmodel_info: supports_logprobs: falsedoes not turn it off. The only opt-out isadditional_drop_params, which drops the params even withoutdrop_params./model/infostill lists logprobs for that deploymentnemotron-safety-guard-8b-v3now returns 200 with no logprobslogprobs: truealone used to get LiteLLM's 400. It now gets a 200 withlogprobs: null, and the model lists logprobs as supportedtop_logprobsis also sent. The PR flags the three other models that return no logprobs, but not this one, since the flag would also blocklogprobswithtop_logprobs, which works thereLow
response_costwasNonewith a "model isn't mapped" error and is now0.0, sox-litellm-response-costreads0.0logprobs=true, which a Responses caller cannot send. fix(responses): carry logprobs across the chat completions bridge #49536 sends both params, so this goes away with ittop_logprobswithoutlogprobson a NIM deployment now answers 400 unlessdrop_paramsis on# mutable-okfollow the dict thatget_optional_paramsfills in place, and the cost-map read is acast, since validating the whole map on every call is slow. The tests setlitellm.drop_paramsandlitellm.model_costthroughmonkeypatch, the way callers set themDecisions
supports_logprobs, gets both params sent to NVIDIA. Most hosted chat models that answered a probe return logprobs, so sending them by default is right. Dropping them for unknown models instead would hide logprobs from most callers. Gemini uses the same rule, and an operator can drop them per deployment withadditional_drop_params: ["logprobs", "top_logprobs"]logprobs, which /v1/completions sends as a count, is refused withoutdrop_paramsand dropped with it, the same as before this PR. NVIDIA only takestrueorfalse. Translating it tologprobs: trueplustop_logprobswas rejected because the text completion bridge returns no logprobs from a chat provider, so the caller would get nothing back for ittop_logprobswithoutlogprobs: trueis refused withoutdrop_paramsand dropped with it, the same as before this PR. NVIDIA ignores it on some models and answers a bare 400 on others (kimi-k3.1-pro,muse-glimmer-30b), so LiteLLM's error naming the param and the fix is clearer.allowed_openai_params: ["top_logprobs"]still sends it as istop_logprobskeeps the 400 from before this PR, because the Responses bridge sendstop_logprobswithoutlogprobs. fix(responses): carry logprobs across the chat completions bridge #49536 sends both and carries the logprobs back, and the run with both PRs merged in shows /v1/responses returning logprobsFinal Attestation
Bugbot summary