Repository navigation
Studio: serve /v1/completions from managed vLLM and SGLang engines - #14227
Conversation
A resident vLLM or SGLang model answered /v1/completions with the GGUF-only 503. Relay the body to the engine's own /v1/completions with the served model id swapped in, so logprobs, echo and prompt_logprobs reach clients such as lm-evaluation-harness local-completions. GGUF and MLX routing are unchanged.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 943a29f78c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| engine = backend._managed_engine | ||
| public = api._orchestrator_public_model_id(backend) or engine.model | ||
| stream = bool(body.get("stream")) | ||
| include_usage = bool((body.get("stream_options") or {}).get("include_usage")) |
There was a problem hiding this comment.
Preserve engine validation for malformed stream_options
When a managed-engine request supplies a truthy non-object stream_options value (for example, {"prompt":"hi","stream":true,"stream_options":true}), this .get() raises AttributeError before the request reaches vLLM/SGLang, producing a Studio 500 instead of the engine's normal validation response. The mapping expansion on line 496 has the same problem; check that the value is a dict before inspecting or merging it so invalid client input remains a 4xx.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
A non-object stream_options is malformed input, and the pre-existing GGUF branch of this same endpoint reads it the same way two lines below, so this is existing behaviour rather than something introduced here.
| response = await client.send( | ||
| client.build_request("POST", url, headers = engine.headers, json = upstream), | ||
| stream = True, | ||
| ) |
There was a problem hiding this comment.
Avoid waiting for the first SGLang token before responding
For streaming SGLang completions, the supported 0.5.17 server consumes the first generated chunk before sending its HTTP 200 response (SGLang handler), while this eager client.send() must receive those upstream headers before Studio constructs its own streaming response. A queued or long-prefill request therefore sends neither headers nor keepalives to the caller until the first token, so clients and proxies can time out even though engine_request_timeout() deliberately permits a much longer generation; start the upstream request from the relay and pace the silent wait instead.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The GGUF completions path awaits its upstream send before responding too (_send_stream_with_preheader_cancel), as does managed chat, so this matches the shipped contract rather than regressing it. Moving the send into the relay would change that contract for all three paths, and a disconnect during the wait is already handled: the watcher closes the client and the send raises into the 499 branch.
| if response.status_code != 200: | ||
| await close() | ||
| api.api_monitor.fail(monitor_id, response.text[:500]) | ||
| raise api._openai_passthrough_error(response.status_code, response.text) |
There was a problem hiding this comment.
Attribute managed completion overflows to prompt
When vLLM or SGLang rejects an oversized completion prompt, _openai_passthrough_error() recognizes the context-overflow text but hard-codes param="messages", because it was written for chat requests. Calling it here therefore returns context_length_exceeded for a field that does not exist on /v1/completions; clients that use the parameter to decide what to trim cannot identify prompt. Pass a completions-specific parameter to the error mapper on this path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed that param names a field this endpoint does not have, but it is an error-payload label with no behaviour attached, and threading an override through a helper shared with chat is not worth it here.
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Review + reproduction evidencePinned review: I reproduced loading Qwen/Qwen2.5-0.5B-Instruct on the managed vLLM 0.26.0 engine and calling
Conclusion: This is a real gap and the PR fixes it. It merges cleanly with #14229 in either order. SGLang and Windows were not run. |

Problem
/v1/completionsonly served a resident GGUF (llama-server) or MLX model. With a model running on the opt-in managed vLLM or SGLang engine, every completions request got theNo GGUF model loaded503, even though both engines serve/v1/completionsnatively, includinglogprobs,echoandprompt_logprobs.That blocks log-likelihood evaluation (lm-evaluation-harness
local-completions, MMLU, HellaSwag and similar multiple-choice tasks) through Studio for any non-GGUF model on Linux GPUs.Part of #7703.
What changed
/v1/completionsnow relays the request to the managed engine when one is resident and alive. Onlymodelis rewritten (public id to the served name on the way in, and back on the way out); every other field reaches the engine as sent, so vLLM / SGLang validate and servelogprobs,echoandprompt_logprobsthemselves.stream_options.include_usage.echois no longer refused up front while an engine is resident.suffixandbest_ofare still refused as before.What does not change
/v1/completions; a request naming the resident engine model is served.Tests
studio/backend/tests/test_managed_engine_completions.py(9 tests): non-stream logprobs + echo relay with the model rewritten both ways, streaming with and without usage, engine 400 keeps its status, echo reaching a resident engine, plus controls (dead engine still 503, safetensors without an engine still 503, echo still refused with no engine, a loaded GGUF still wins). The 5 behaviour tests fail on main and pass here; the 4 controls pass on both.cd studio/backend python -m pytest -q tests/test_managed_engine_completions.py tests/test_managed_engine_tools.py tests/test_openai_tool_passthrough.py tests/test_openai_auto_switch.pyAgainst a real
vllm serveofQwen/Qwen2.5-0.5B-Instructin fp16 on a T4, with the lm-eval scoring shape (logprobs: 2,echo: true,max_tokens: 1): the merge base answers 503, this branch answers 200 with the public model id, and the prompt logprobs equal what vLLM returns when asked directly. Streaming answers 200 as well.