Repository navigation
Studio: validate the reasoning controls instead of coercing them - #9595
Conversation
f70b0cc to
fe247ac
Compare
a62ebdb to
cc8c05f
Compare
|
Reproduced each path against a loaded Qwen3.8-27B configuration. The three Codex items are real and are resolved at 7a6bdb8:
The Two things I want settled before this goes in. The undeclared request is still split. 7a6bdb8 moved the backend off the UI table. Before that commit The card is right and the frontend row is wrong, so I do not want this PR to move back to match it. It is also not specific to Qwen3.8: the Qwen3.6-27B card carries the same thinking / non-thinking split, Qwen3.5-9B differs again, and Smaller points:
Both CI failures are unrelated to the change. |
870cf61 to
24da80e
Compare
|
Addressed in a64e780: the Qwen3.8 Chat UI thinking row now matches the backend table (temperature 1.0, presence_penalty 0.0). The change is scoped to Qwen3.8 thinking mode; Qwen3.5, Qwen3.6, generic Qwen3, and all non-thinking defaults remain unchanged. A frontend/backend parity regression test was added. Local validation: 5387 frontend tests passed, plus typecheck, production build, bundle budget, focused ESLint, Prettier, and diff checks. |
The third surface this branch deliberately leaves mode-blind, after /v1/completions and the load/status .inference block. A transformers or MLX load has no recorded launch mode: Studio picks the llama.cpp one itself and stores it as reasoning_default, while detect_reasoning_flags only ever says whether a template CAN reason, never what it does when the kwarg is absent, and apply_chat_template_for_generation omits the kwarg entirely in that case. So a silent request there keeps the historical flat row, and an explicit control still reaches the mode row on the same load. Giving that path a real mode means declaring a per-family default (the shape external providers already use with thinking_default_on) or teaching the classifier to read the template's own, both of which change behaviour for every reasoning family. Test so the current answer has to be changed on purpose. 107 passed in test_sampling_resolution.py.
The migration recognized the previously generated Qwen3.8 thinking row by asking whether the row the session currently resolves to has presence penalty zero. That is only true in thinking mode. A Studio that came up with Think off resolved the non-thinking row, whose presence penalty is 1.5, so the guard rejected the snapshot and left temperature 0.6 / top_p 0.95 in place against the 0.7 / 0.8 the non-thinking row now asks for. It repaired itself only if the user happened to toggle Think. Ask the model instead: the family whose thinking row carries zero presence penalty is Qwen3.8 alone, and that answer does not move with the mode. The replacement row is still whichever one the session resolves, so a Think-off startup migrates to 0.7 / 0.8 and a Think-on startup to 1.0 / presence 0. The same substitution is made for the global snapshot, which had the identical guard.
Comment-only pass over the lines this PR adds: 61 comment lines removed, none of the facts. What survives is the invariant the code does not state (the lift has to be a fixed point, the id must match before the launch state may be read, the .inference block is not mode-aware, String.match takes the leftmost), one line each instead of a paragraph. Rationale that belongs in the PR description rather than the source is gone. Verified comment-only by comment_tools.py check (8/8, --strict-ext --allow-docstring-edits). Backend 117 passed, frontend 8169 passed.
Leaves only the fix that is independent of any model family: the validated
merge of typed and nested reasoning controls, shared by /v1/chat/completions,
/v1/responses, /v1/messages, /chat/count_tokens and the MLX token counter.
The headline case is a client sending the JSON string "false" for
extra_body.chat_template_kwargs.enable_thinking, which the old bool() lift
turned into True and so switched thinking on when it was asked to be off.
Removed, to be considered separately:
- the sampling_modes block in inference_defaults.json and the thinking_mode
argument threaded through load_inference_config, _recommended_sampling and
resolve_effective_sampling
- _sampling_thinking_mode, _normalized_sampling_thinking_mode and
_loaded_llama_backend_for, plus the two call sites that priced a request on
the mode generation would run in
- the frontend Qwen3.8 table change and its stored-defaults migration
Those changed sampling defaults for anyone already serving a Qwen3.8; this
half changes no default and only makes the reasoning controls mean what they
say. The two tests that asserted both halves now assert only the controls.
Backend 2172 passed, 71 skipped. Frontend 8165 passed. Ruff clean.
Scope narrowedThis PR now contains only the reasoning-control validation. The mode-aware sampling work has been removed, at Gone from the diff:
What remains is the validated merge of typed and nested reasoning controls, shared by This answers two things raised above rather than deferring them. @oobabooga asked for the frontend row to be left out: "That is a frontend change across the tier and it should not ride along in a backend PR, so please leave it out of this one." It is out. The Qwen3.6 and Qwen3.5 rows you noted carry the same thinking / non-thinking split, so that change belongs with a table-wide one. @Imagineer99 noted that Studio's Qwen defaults intentionally differ from the HF card and that this PR changed that alignment. It no longer does. No recommended sampling value moves in this PR. Two review threads above are now about code that is not in the diff: the Verification on the current head
Full CI on a staging mirror is green apart from five failures that reproduce unchanged on |
The body of this PR discloses that the string form is ignored rather than
honored, and the suite covers "false". The same rule applies to every
non-boolean JSON type, and one of them changes an answer in the other
direction: on main bool(0) is False, so a client sending
"chat_template_kwargs": {"enable_thinking": 0}
for "off" got thinking off, by accident of the coercion this PR removes.
It is now ignored and falls through to the mode the model was launched in,
exactly as "false" does. That is the right rule, but it was untested, so
nothing would have caught it changing again.
Three tests:
- a nested enable_thinking that is not a JSON boolean is ignored, over
"false", "true", 0, 1, null, [], {} and the empty string, and is consumed
either way so no render sees a value the validation just refused;
- the same for preserve_thinking;
- the property the other two are instances of: an ignored nested control
resolves exactly as omitting the key would, so "ignored" cannot become a
third outcome that still steers generation. A valid control sent beside an
invalid one is still honored.
Restoring main's bool() coercion fails 9 of the 16 added cases.
|
Review record for #9595, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#61. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. The mirror was built as a single squashed replay of this PR onto current upstream main, so its commit SHA has no counterpart here by construction. Mirror Round 1 — reviewed mirror
|
CI status on
|
…lothai#9595) * Studio: apply Qwen3.8 sampling defaults by reasoning mode * Studio: honor nested reasoning request controls * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Studio: complete nested reasoning request paths * Studio: align Qwen3.8 thinking sampling with model card * Resolve the reasoning mode from the same sentinels generation uses * Studio: align Qwen3.8 frontend thinking defaults * Tighten the comments on the reasoning-control paths * Price a silent request on the mode llama-server was launched in * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Pick sampling from the resolver generation already uses * Trust a backend that reports no reasoning, and drop an unknown effort * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Migrate prior Qwen3.8 thinking defaults * Say what is and is not mode-aware, and pin both Two claims in this branch were wider than the code. _sampling_thinking_mode said the Chat UI "already seeds itself this way" and pointed at apply-inference-status-to-store.ts. The UI does land on the same row, but not through the .inference block of load/status: that block is load_inference_config with no mode, and for a thinking-default Qwen3.8 it still answers temperature 0.7 / presence_penalty 1.5. The UI matches because resolveQwenThinkingParams is layered over mergeBackendRecommendedInference, so any other reader of /inference/status sees the flat row. Reworded to say that, and pinned by test_the_status_inference_block_is_not_the_mode_aware_one. /v1/completions was left on the flat row with no reason given, which reads as an oversight next to the chat path. It is not: the raw endpoint renders no chat template, so the launch --chat-template-kwargs that decide whether a chat request reasons never apply to it, and pricing a raw continuation on the launch mode would re-price it on the strength of how the model happens to be loaded. The two endpoints therefore answer with different sampling for one loaded model on purpose. Stated in the docstring and pinned by test_raw_completions_are_never_priced_on_the_launch_mode, which fails if that call is ever made mode-aware. No behaviour change: 93 passed in test_sampling_resolution.py, 91 of them the existing cases, unchanged. * Make the reasoning lift a fixed point and settle the family on 3.8 Two defects found while enumerating this branch against main. The lift was not idempotent. It writes its result onto the typed fields, so a second call reads a typed effort of None where the first read the client's, takes the nested-effort rescue the first deliberately skipped, and hands generation a level the request had already lost the right to: typed {enable_thinking: true, reasoning_effort: "none"} nested {reasoning_effort: "high"} pass 1 -> (True, None) pass 2 -> (True, "high") 36 of 576 typed x nested shapes drifted. /v1/responses is the live double call: _build_chat_request normalizes the request it builds and the chat route normalizes it again. It is inert today only because that rebuild drops the nested dict, so one line forwarding chat_template_kwargs would make it real. The lift now consumes the three reasoning keys it takes, rebinding a filtered copy rather than popping in place, since the dict comes from the parsed body. 0 of 576 shapes drift after it. resolveQwenThinkingParams picked the family from the leftmost regex match, so an id naming two Qwen families answered with the wrong one: Qwen3.5-Draft/Qwen3.8-27B-Q4_K_M.gguf UI 0.6 / p1.5 API 1.0 / p0.0 /models/qwen3.6/qwen3.8-27b.gguf UI 0.6 / p1.5 API 1.0 / p0.0 The backend strips the org prefix and scans its family patterns longest-first, so qwen3.8 wins wherever it appears. Before this branch gave the families different rows the divergence was invisible; a draft pairing or a per-family directory is enough to hit it. The 3.8 test is now its own boundary-anchored pattern, so position stops deciding. Qwen3.80 and Qwen3.8B are still not Qwen3.8, and the other 18 cells of the id x mode matrix are unchanged. Also drops a stale parity claim from _recommended_sampling's docstring for the same reason as the previous commit. Verified: the 232-cell base-vs-head differential is unchanged by these fixes, so no first-pass behaviour moved. studio/backend 2231 passed, 71 skipped; studio/frontend 8167 passed, 0 failed; build clean. Each fix reverted on its own fails the test added with it. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Pin the non-GGUF silent request on the flat row The third surface this branch deliberately leaves mode-blind, after /v1/completions and the load/status .inference block. A transformers or MLX load has no recorded launch mode: Studio picks the llama.cpp one itself and stores it as reasoning_default, while detect_reasoning_flags only ever says whether a template CAN reason, never what it does when the kwarg is absent, and apply_chat_template_for_generation omits the kwarg entirely in that case. So a silent request there keeps the historical flat row, and an explicit control still reaches the mode row on the same load. Giving that path a real mode means declaring a per-family default (the shape external providers already use with thinking_default_on) or teaching the classifier to read the template's own, both of which change behaviour for every reasoning family. Test so the current answer has to be changed on purpose. 107 passed in test_sampling_resolution.py. * Recognize the prior Qwen3.8 snapshot regardless of the startup mode The migration recognized the previously generated Qwen3.8 thinking row by asking whether the row the session currently resolves to has presence penalty zero. That is only true in thinking mode. A Studio that came up with Think off resolved the non-thinking row, whose presence penalty is 1.5, so the guard rejected the snapshot and left temperature 0.6 / top_p 0.95 in place against the 0.7 / 0.8 the non-thinking row now asks for. It repaired itself only if the user happened to toggle Think. Ask the model instead: the family whose thinking row carries zero presence penalty is Qwen3.8 alone, and that answer does not move with the mode. The replacement row is still whichever one the session resolves, so a Think-off startup migrates to 0.7 / 0.8 and a Think-on startup to 1.0 / presence 0. The same substitution is made for the global snapshot, which had the identical guard. * Cut the commentary this PR added down to the load-bearing lines Comment-only pass over the lines this PR adds: 61 comment lines removed, none of the facts. What survives is the invariant the code does not state (the lift has to be a fixed point, the id must match before the launch state may be read, the .inference block is not mode-aware, String.match takes the leftmost), one line each instead of a paragraph. Rationale that belongs in the PR description rather than the source is gone. Verified comment-only by comment_tools.py check (8/8, --strict-ext --allow-docstring-edits). Backend 117 passed, frontend 8169 passed. * Narrow this PR to the reasoning-control validation Leaves only the fix that is independent of any model family: the validated merge of typed and nested reasoning controls, shared by /v1/chat/completions, /v1/responses, /v1/messages, /chat/count_tokens and the MLX token counter. The headline case is a client sending the JSON string "false" for extra_body.chat_template_kwargs.enable_thinking, which the old bool() lift turned into True and so switched thinking on when it was asked to be off. Removed, to be considered separately: - the sampling_modes block in inference_defaults.json and the thinking_mode argument threaded through load_inference_config, _recommended_sampling and resolve_effective_sampling - _sampling_thinking_mode, _normalized_sampling_thinking_mode and _loaded_llama_backend_for, plus the two call sites that priced a request on the mode generation would run in - the frontend Qwen3.8 table change and its stored-defaults migration Those changed sampling defaults for anyone already serving a Qwen3.8; this half changes no default and only makes the reasoning controls mean what they say. The two tests that asserted both halves now assert only the controls. Backend 2172 passed, 71 skipped. Frontend 8165 passed. Ruff clean. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Studio: pin that a nested reasoning control must be a real JSON boolean The body of this PR discloses that the string form is ignored rather than honored, and the suite covers "false". The same rule applies to every non-boolean JSON type, and one of them changes an answer in the other direction: on main bool(0) is False, so a client sending "chat_template_kwargs": {"enable_thinking": 0} for "off" got thinking off, by accident of the coercion this PR removes. It is now ignored and falls through to the mode the model was launched in, exactly as "false" does. That is the right rule, but it was untested, so nothing would have caught it changing again. Three tests: - a nested enable_thinking that is not a JSON boolean is ignored, over "false", "true", 0, 1, null, [], {} and the empty string, and is consumed either way so no render sees a value the validation just refused; - the same for preserve_thinking; - the property the other two are instances of: an ignored nested control resolves exactly as omitting the key would, so "ignored" cannot become a third outcome that still steers generation. A valid control sent beside an invalid one is still honored. Restoring main's bool() coercion fails 9 of the 16 added cases. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: oobabooga <[email protected]> Co-authored-by: Daniel Han <[email protected]> Co-authored-by: danielhanchen <[email protected]>
Summary
Normalize the reasoning controls once per request, with real validation, and share that one result across every surface that renders a chat template:
/v1/chat/completions,/v1/responses,/v1/messages,/chat/count_tokensand the MLX token counter.enable_thinking,reasoning_effortandpreserve_thinkingout of OpenAIextra_body.chat_template_kwargs, and consume the keys so the lift is a fixed point.none,minimal,low,medium,high,max,xhigh); ignore an invalid nested type rather than coercing it.thinkingblock onto the boolean without recording it as an explicit field, so route precedence still ranks it below the nested controls.Why
The old helper coerced whatever arrived in
extra_body.chat_template_kwargs.enable_thinkingwithbool().bool("false")isTrue, so a client asking for thinking to be off with a JSON string turned it on. Nestedreasoning_effortwas ignored outright, including the named levels such asmediumandxhighthat some OpenAI-compatible clients send.Conflicting controls were the other half of it: a request carrying
enable_thinking=falsealongsidereasoning_effort="high"reasoned at high effort while the boolean said off. The effort is now dropped when it contradicts the boolean, before the model-specific translation runs, so this applies to every family and not only to the one that prompted it.Worth stating plainly, since the summary could be read the other way: a nested control that is not a real JSON boolean is ignored, not honored. A client sending
"false"no longer flips thinking on, but it does not turn it off either. The ignored value falls through to whatever mode the model was launched in, so such a client still ends up thinking on a template that reasons by default. Sending a real JSONfalseis what turns it off.That rule is symmetric, and one case moves the other way:
bool(0)isFalse, so a client sending{"enable_thinking": 0}for "off" used to get thinking off, by accident of the coercion being removed. It is now ignored like any other non-boolean type and falls through to the launch default. Same for1,null, a list or an object. Only a real JSON boolean steers the template, in either direction.This half changes no sampling default. A request that selects no reasoning mode resolves exactly as it did before.
Follow-up to #9372.
What is not here
This PR previously also made per-request sampling follow the reasoning mode and moved the Qwen3.8 Chat UI row onto its model card. That changed defaults for anyone already serving a Qwen3.8, so it has been taken out and left for a separate change. What remains is independent of any model family.
Validation
2172 passed, 71 skippedacross the sampling, thinking, Anthropic, Responses, OpenAI passthrough, auto-switch and MLX suites.8165 passed, 0 failed.false + highproduced no reasoning, explicittrue + nonepreserved reasoning, and nestedenable_thinking: "false"was ignored while a valid nestedreasoning_effort: "none"disabled reasoning.off,mediumandxhigh; final answers were correct and completion usage rose from 2 to 74 to 160 tokens.