Skip to content

Studio: vLLM thinking effort levels, preserve thinking and auto-compact - #13571

Merged
danielhanchen merged 8 commits into
mainfrom
studio-vllm-thinking-compaction
Oct 13, 2026
Merged

danielhanchen merged 8 commits into
mainfrom
studio-vllm-thinking-compaction

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Fixes #11664

With a vLLM connection, Studio only offered Thinking on or off, and Studio's own vLLM engine had no thinking at all and no auto-compact. This PR gives vLLM the same thinking controls and auto-compact as GGUF.

vLLM connections

  • Effort levels. Studio collapsed every vLLM effort ladder to low / medium / high (xhigh and max became high). Qwen3.8's template accepts only low / medium / xhigh, so picking High on a Qwen3.8 connection failed every message with Unexpected reasoning effort high. Supported types are xhigh (default), medium, and low., and xhigh could not be picked. The model's own levels now go out unchanged when the server is vLLM 0.21 or newer, the first release whose reasoning_effort accepts none / minimal / low / medium / high / xhigh / max. On an older server, or one whose GET /version cannot be read, low / medium / high go out as before and a wider level is left to the template's own default rather than rewritten to a neighbour the template may refuse. The version is cached for a minute per connection.
  • Reasoning model toggle. With the connection marked as a reasoning model, Studio used to offer on or off only. It now shows the catalog's effort ladder when the model is known and keeps on or off when it is not.
  • Preserve thinking now works for vLLM as it does for llama.cpp connections. preserve_thinking goes out in chat_template_kwargs, merged with enable_thinking, and earlier thinking is replayed as reasoning, the field vLLM 0.17+ hands to the template.

Studio's vLLM engine

  • Studio picks a --reasoning-parser from the model's own chat template, the same way it already picks the tool parser, following vLLM's reasoning outputs table: qwen3 for Qwen3 templates with enable_thinking, deepseek_r1 for R1, QwQ and Qwen3 Thinking-2507, deepseek_v3 for DeepSeek V3.1 style templates gated on thinking, plus glm45, minimax_m2, kimi_k2 and openai_gptoss. If no template matches, the launch command is unchanged.
  • When a parser is chosen, the load reports the template's thinking style and effort levels, the same template check GGUF uses. Thinking on / off, the effort level and preserve thinking then reach vLLM, and the thinking stream shows in the Thinking panel on both the plain and tool paths.
  • A request that says nothing about thinking still runs with thinking off, as before. Models without a parser are byte-identical to main.
  • Auto-compact now covers the managed vLLM engine. Plain chats reuse the MLX fit, which counts tokens exactly through the engine's /tokenize, against the engine's --max-model-len. Chats that go through Studio's tool loop are fitted every turn with the same estimate vLLM connections use. Preserve thinking also keeps each tool turn's thinking.
  • Adapters, structured output and continuation are still refused on the managed engine.

Auto-compact on vLLM connections (already on main)

#12975 already compacts long chats on vLLM and Custom connections to the window the server reports. I checked it on real servers with Studio's proxy, Qwen3-0.6B, --max-model-len 4096 and a chat of about 12k tokens:

vLLM GPU Auto-compact off Auto-compact on
0.31.0 L4 400 maximum context length is 4096 tokens 20 oldest messages dropped (12296 to 2086 prompt tokens), answer France's capital is Paris.
0.30.0 L4 same 400 same, France's capital is Paris.
0.11.2 A100 same 400 same, Paris.

Evidence

vLLM 0.31.0 connection, Qwen3-0.6B served with the Qwen3.8 chat template, through Studio's proxy:

Request main this PR
effort xhigh 400 Unexpected reasoning effort high 200, The word "strawberry" contains 3 r letters.
effort low / medium 200 200, unchanged
thinking off 200, no thinking 200, no thinking
2 turns, preserve thinking on 80 prompt tokens (earlier thinking dropped) 102 (earlier thinking reaches the template)

Studio's vLLM engine, Qwen3-0.6B, --max-model-len 2048:

Request main this PR
launch no reasoning parser --reasoning-parser qwen3
thinking on 400 does not support ... reasoning controls 935 chars of thinking, answer 17 multiplied by 3 equals 51.
thinking off / omitted answer, no thinking same
Qwen3.8 template, effort low / medium / xhigh 400 200, prompt length changes per level
long chat, auto-compact on not compacted 12 messages dropped, 3856 to 1948 prompt tokens, answers
long chat with tool history, auto-compact on context_length_exceeded fitted to 1106 prompt tokens, answers

Tests

  • New tests: tests/test_managed_engine_reasoning.py, tests/test_vllm_connection_reasoning.py.
  • Updated tests: external preserve thinking, model catalog, provider capabilities, auto-compaction settings.
  • Backend: 493 passed across the managed engine, external provider, reasoning wire and auto-compaction suites.
  • Frontend: 75 passed in the touched suites; typecheck is clean.

Notes

  • A vLLM connection now sends preserve_thinking with its default value of false, as llama.cpp connections already do. A template that reads it (Qwen3.6 and later) no longer renders an empty think block for each past turn.
  • SGLang is unchanged: no reasoning parser and no compaction, since it has no exact token count.

Screenshots

Merge base (left) vs this PR (right). The vLLM connection serves Qwen/Qwen3.8-27B from a stub vLLM 0.31 server.

Thinking menu on a plain vLLM connection: High becomes the template's own Extra High, and Preserve thinking appears.

Thinking menu on a vLLM connection

The top level picked and sent: the request carried reasoning_effort: high before (which the Qwen3.8 template rejects) and xhigh now.

Top effort level sent

Connection marked as a reasoning model: an on/off pill before, the effort ladder now.

Reasoning model connection

… engine

Launch vLLM with the reasoning parser the model's chat template matches, report the
template's reasoning flags on load, pass enable_thinking / reasoning_effort /
preserve_thinking through to the engine, stream its reasoning as <think> markup, and
fit long chats to --max-model-len when Auto-compact is on.
@danielhanchen danielhanchen self-assigned this Oct 13, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T14:45:02.479216Z 186dbbb Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 13, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 13, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 13, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 5c19614ec5

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3cfc96b155

ℹ️ 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".

"Select one GPU, use Replicas, or load an unquantized checkpoint with 4-bit precision."
)
template = _model_chat_template(config, hf_token)
reasoning_parser = reasoning_parser_for_template(template, engine)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Classify reasoning from every active named template

When tokenizer_config.json provides separate default and tool_use templates, _model_chat_template() always collapses them to tool_use at line 169, so this new parser detection never examines the default template that vLLM renders for requests without tools. A model whose default template contains Qwen/DeepSeek reasoning markers but whose tool template does not will therefore record no reasoning parser or flags, causing otherwise-supported plain reasoning requests to be rejected; preserve both named branches or classify the template selected for each request shape.

Useful? React with 👍 / 👎.

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.

Not changing: models whose default template carries thinking markup but whose tool_use template does not are rare, and for them the managed engine behaves exactly as on main (thinking off, controls refused), so nothing regresses.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 13, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 13, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 13, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 13, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 13, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 13, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 13, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 13, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 13, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 13, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 13, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 13, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 13, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: a7d85cadfb

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 186dbbb30c

ℹ️ 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".

Comment on lines +5671 to +5672
const isManagedEngineForCompaction =
!isExternalModelId(params.checkpoint) && runtime.loadedEngine === "vllm";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include managed vLLM in the manual-compaction gate

When a user invokes /compact while a managed vLLM model is loaded, takeThreadCompactionRequest() consumes the pending request, but compactNow remains false because its gate still checks only GGUF and MLX. Consequently, the newly forwarded isManagedEngine flag enables ordinary auto-compaction but never sends compact_context: true, so an explicit compaction request is silently ignored; include isManagedEngineForCompaction in that gate.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not reachable: /compact is refused before the request is queued unless a GGUF or MLX model is loaded (thread.tsx shows "/compact works with GGUF and MLX models that support tools"), so with a managed vLLM model takeThreadCompactionRequest never has anything to consume.

if "<think>" not in template or "</think>" not in template:
return None
for marker, parser in (
("<arg_key>", "glm45"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Select the GLM-4.7 reasoning parser

When loading GLM-4.7 or its variants, the template contains <arg_key>, so this unconditional marker mapping launches vLLM with --reasoning-parser glm45. GLM-4.7 prefills <think> in its generation prompt and requires the glm47 parser; vLLM's official GLM-4.7 recipe specifies --reasoning-parser glm47, and the upstream parser bug report documents that glm45 mishandles this prompt shape. As a result, managed GLM-4.7 responses can put reasoning in the wrong field or leak its markup into visible content, so the parser selection must distinguish this template from GLM-4.5/4.6.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In every vLLM release Studio's engine pins (0.26.0, 0.30.0) and in 0.31.0, vllm/reasoning/init.py maps both glm45 and glm47 to glm47_moe_reasoning_parser.Glm47MoeParserReasoningAdapter, so --reasoning-parser glm45 already runs the GLM-4.7 parser. vllm#33348 is closed by that alias.

Comment on lines +1865 to 1866
if effort in ("minimal", "low", "medium", "high", "xhigh", "max"):
body["reasoning_effort"] = effort

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid sending none to older vLLM servers

When an external vLLM server predates the widened effort enum and the user turns thinking off, effort is "none", but it bypasses the version guard because _LOCAL_SERVER_EFFORT_ALIASES contains only minimal, xhigh, and max. The expanded tuple here then sends reasoning_effort: "none" even though chat_template_kwargs.enable_thinking=false already carries the off switch, causing servers whose schema accepts only low/medium/high to reject the entire request with 400, as demonstrated by this upstream vLLM validation failure. Apply the same version fallback to none or omit the top-level field for those versions.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

"none" is never sent at top level: the forwarded tuple is (minimal, low, medium, high, xhigh, max), so thinking off travels only as chat_template_kwargs.enable_thinking=false, which vLLM 0.11+ accepts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Feature request: vLLM support — thinking depth selection and context auto-compression

2 participants