Skip to content

Studio: make the Min P and Repetition Penalty sliders work - #10456

Merged
danielhanchen merged 7 commits into
unslothai:mainfrom
NilayYadav:fix-external-min-p-repetition-penalty
Sep 8, 2026
Merged

danielhanchen merged 7 commits into
unslothai:mainfrom
NilayYadav:fix-external-min-p-repetition-penalty

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

On OpenRouter, vLLM and llama.cpp connections the chat settings panel shows Min P and Repetition Penalty sliders and remembers their values per model and per thread. The request never carried either one, so moving the sliders had no effect on the output.

Top K had a second problem in the same area. The value was passed all the way through to the client and then never written into the request body, even though the code comment said it was forwarded.

All three are now sent, and only when a value was actually set, so a request that does not mention them still sends nothing. For llama.cpp the field is renamed to repeat_penalty, which is the name that server reads. Sending repetition_penalty to it is accepted and then ignored, so the slider looked broken. The in process llama.cpp client in this repo already uses the correct name.

Ollama does not accept any of the three on its OpenAI compatible endpoint. They belong to its own API instead, and unknown fields there are dropped without an error. Those sliders are now hidden for Ollama, and the fields are also stripped on the server side, since that endpoint can be called directly and not only from the app.

Custom connections stay on the standard OpenAI fields. An unknown server behind a custom base URL may reject fields it does not know, and the vLLM and llama.cpp presets accept any base URL if you want the extra sliders.

Hosted providers are unchanged. They already report these sliders as unsupported, so nothing new appears in their requests.

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 7, 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-09-08T09:28:54.519735Z 04db26c 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 468321e16b

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

Confirmed the body built in studio/backend/core/inference/external_provider.py never carried top_k, min_p or repetition_penalty, so those sliders were inert on vLLM, llama.cpp and OpenRouter, and the repeat_penalty rename matches what llama-server reads. Will get this reviewed.

The two test files here read source rather than running the flow. The backend
one hands the client an httpx.MockTransport, and the route half is checked by
AST-parsing routes/inference.py and comparing the names passed to dict(...)
against the strings _top_k_explicit and friends. That proves the source says
the right words. It cannot fail on the runtime hazard those words exist to
prevent: pydantic v2 records every setattr in model_fields_set, so a write to
the payload before those three reads turns an omission into an explicit request
for the schema default.

Adds test_external_provider_sampling_over_the_wire.py, which drives
_proxy_to_external_provider itself and a real http.server on loopback records
the bytes. Stdlib only, port 0, no external network, so it runs the same on the
Linux, macOS and Windows legs. Against the merge base 11 of its 13 cases fail;
they pass here.

Also corrects two comments. The note above the model_fields_set reads implied
_fill_recommended_sampling_openai runs on this path; it does not, the external
branch returns well before its call site, so the note now says what the ordering
rule actually is and what enforces it. And the sampling test docstring still
described custom as offering all three, which this PR is what makes false.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 8, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Ran this end to end against the merge base. The bug is real, the fix works, and the sliders that disappear are the ones that were never going anywhere. Details and evidence below.

What changes, before and after

Base 6133092453, head 468321e16. Two Studio installs built from detached worktrees at those two commits, one scene driven against both.

1. The sliders that get hidden

provider-capabilities.ts moves ollama and custom from ALL_SUPPORTED to OPENAI_COMPAT_BASE, so the Sampling section of Run settings loses three rows for those connection types. vLLM is the control and does not move.

Ollama connection:

Ollama before and after

Custom connection:

Custom before and after

vLLM connection, the control:

vLLM before and after

Rows read out of the DOM rather than counted by eye, so "gone" means gone and not scrolled out of view:

connection before after
Ollama (ollama) Temperature, Top P, Top K, Min P, Repetition Penalty, Presence Penalty, Max Tokens (7) Temperature, Top P, Presence Penalty, Max Tokens (4)
Custom (custom) same 7 same 4
vLLM (vllm) same 7 same 7, unchanged

The vLLM pair is byte-identical, which is the control doing its job, so that run needed --allow-identical. The panel does not name the connection it belongs to, so the captions come from the connection type the server actually stored, which the scene reads back and asserts before shooting. A connection whose type failed to persist would fall through to DEFAULT_EXTERNAL_CAPABILITIES, which is the same baseline set, and would have imitated the after state perfectly.

2. The request body

A real http.server on loopback, recording what Studio posted, driven through the actual route rather than a mock transport.

case merge base this PR
vLLM / OpenRouter, all three set nothing sent top_k, min_p, repetition_penalty
llama.cpp, all three set nothing sent repeat_penalty, and no repetition_penalty
Ollama, all three set explicitly nothing sent still nothing, the new body_omit
nothing set at all nothing sent nothing sent
top_k=0, min_p=0.0 nothing sent both present as 0, not swallowed as falsey
explicit 20 / 0.01 / 1.0, equal to the schema defaults nothing sent all three present
second turn of a tool loop nothing sent same three values as the first turn

On the base, even an explicit top_k=40 never reaches the wire for any provider, which confirms the Top K half of the report. repeat_penalty is the right name: llama-server documents repeat_penalty and does not read repetition_penalty.

The explicit-versus-default handling matches how OpenRouter documents its own behaviour, which is that an absent parameter is left out so the provider applies its default, while a parameter explicitly sent at its conventional default is still forwarded and can differ from omitting it. That distinction is exactly what model_fields_set preserves here.

Test results

  • New backend suite: 12 passed. New frontend suite: 8 passed.
  • Backend suites around the change (external provider, provider config and registry, inference routes, chat settings and thread settings): 752 passed, 42 skipped.
  • Full frontend suite: 6981 passed, and npm run typecheck clean.
  • Per-OS CI on a staging replica of this branch: ubuntu-latest, macos-15 and windows-latest all green.
  • The Run settings panel renders the same row set in all three browser engines, so this is not Chromium-only behaviour: Chromium (Chrome, Edge), Gecko (Firefox) and WebKit (Safari) each measured [Temperature, Top P, Presence Penalty, Max Tokens] for Ollama and Custom and all seven for vLLM.

One commit pushed

79594b14c, Studio: cover the sampling forwarding over a real socket.

Both test files here read source instead of running the flow. The backend one hands the client an httpx.MockTransport, and the route half is checked by AST-parsing routes/inference.py and comparing the names passed to dict(...) against the strings _top_k_explicit and friends. That proves the source says the right words, but it cannot fail on the runtime hazard those words exist to prevent: pydantic v2 records every setattr in model_fields_set, so a write to the payload before those three reads would turn an omission into an explicit request for the schema default.

So the commit adds test_external_provider_sampling_over_the_wire.py, which drives _proxy_to_external_provider itself while a loopback http.server records the bytes. Stdlib only, port 0, no external network, so it runs the same on all three OS legs. Against the merge base 11 of its 13 cases fail, and they pass on this branch.

It also corrects two comments. The note above the model_fields_set reads implied _fill_recommended_sampling_openai runs on this path, which it does not, since the external branch returns well before that call site on the local path; it now states the ordering rule and what enforces it. And the sampling test docstring still described custom as offering all three, which this PR is what makes false.

Two things worth calling out, neither a blocker

Existing vLLM, llama.cpp and OpenRouter connections will sample differently after upgrading. The panel spreads these fields whenever the capability flag is true, and the store's defaults are topK: 20, minP: 0.01, repetitionPenalty: 1.0. So a user who never touched a slider goes from sending none of the three to sending all of them. Against documented server defaults that is: llama-server top_k 40 to 20, min_p 0.05 to 0.01, repeat_penalty 1.1 to 1.0; vLLM top_k disabled to 20 and min_p 0.0 to 0.01, and vLLM 0.8 and newer would otherwise have taken top_k from the model's generation_config.json. That is arguably the whole point, since the panel was already showing those numbers and now they are true, but it is a silent generation change on upgrade for everyone with one of these connections, and nobody reading the title expects Top K to start clamping their vLLM to 20. Worth a line in the description or release notes.

A vLLM server saved under the Custom preset cannot be migrated without losing its threads. The description suggests moving to the vLLM or llama.cpp preset to keep the extra sliders, but ProviderUpdate has no provider_type field, so the type of a saved connection cannot be edited. The only route is delete and recreate, which mints a new connection id, and chat threads pin external::<providerId>::<modelId>, so every existing thread on that connection lands on the "not enabled" path. Not caused by this PR, but this PR is what makes people want to do it.

Nothing else stood out. The body_omit guard being Ollama-only means an explicit top_k or min_p now reaches DeepSeek, Mistral, Qwen and HuggingFace connections through the public /v1/chat/completions surface, where before the PR nothing but temperature, top_p, presence_penalty and max_tokens ever left the box. The panel never sends them there, so this only affects a caller who names them deliberately, and honouring an explicit request beats silently dropping it. Flagging it as a judgement call rather than a defect.

Opening comment-reduction pass. Added comment lines across the PR go from 74 to
28, and the six that remain untouched are the SPDX and copyright headers. Cuts
are deletions where a test name or the code already carried the fact, and the
survivors are the ones neither states: that llama-server reads repeat_penalty,
that Ollama's /v1 silently drops these three, that 0 means disabled so a
truthiness gate would restore the server default, that the schema defaults are
non-None so only model_fields_set separates an omission from a request for the
default, and the Ollama compatibility citation.

No code touched.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex security 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: d90a11ab61

ℹ️ 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 +1294 to +1295
if top_k is not None:
body["top_k"] = top_k

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 Strip extension sampling fields for custom providers

When provider_type="custom", this now forwards top_k (and the adjacent new extensions) even though the capability map deliberately treats Custom as a strict OpenAI-compatible endpoint. In particular, a cached pre-deploy frontend still classifies Custom as ALL_SUPPORTED and includes top_k on every request, so after only the backend updates, strict custom gateways can start returning 400s where the same requests previously worked. Direct API callers can trigger the same regression. Add these fields to Custom's server-side body_omit, as done for Ollama, while users needing them can select the vLLM or llama.cpp provider type.

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.

Correct, and reachable without a raw API caller. Fixed in a933d60.

Reproduced the exact path: the pre-PR bundle classifies custom as ALL_SUPPORTED and the body spreads top_k on every request, so the wire body for an untouched Custom connection carries top_k 20. index.html is served no-cache and the assets are content-hashed, so a reload does pick up the new bundle, but a tab left open across a Studio upgrade keeps running the old one and never re-fetches index.html. Against a gateway that validates its input, that identical body returns 200 on the merge base 6133092 (top_k dropped) and 400 on this branch (top_k forwarded), and a strict endpoint rejects the whole turn rather than ignoring the key, which is the documented behaviour for an unrecognized top-level argument.

custom now carries the same body_omit as ollama. Servers that do want these stay reachable through the vllm and llama_cpp presets, which take any base URL. test_the_sliders_reach_the_server dropped its custom parametrization since it asserted the behaviour this changes, and the ollama strip test became one parametrized guard over both providers; a new over-the-wire case replays the stale-bundle body against a validating gateway. Both fail without the registry entry.

The capability map now treats Custom as a strict OpenAI-compatible endpoint, but
the backend still forwarded top_k, min_p and repetition_penalty for it, so the
panel and the request disagreed in the one direction this PR exists to close.

That is reachable without a raw API caller. The pre-PR bundle classified custom
as ALL_SUPPORTED and spread top_k on every request, and a browser tab left open
across an upgrade keeps running it: index.html is served no-cache, but a loaded
SPA does not re-fetch it until someone reloads. Measured against a gateway that
validates its input, the identical body goes 200 on the merge base and 400 on
this branch, because the merge base dropped top_k and this branch forwards it.
A strict endpoint rejects the whole turn rather than ignoring the key.

Adds body_omit to the custom preset, the same guard ollama already carries here,
so neither can leak a field its endpoint cannot take. Servers that do want these
are reachable through the vllm and llama_cpp presets, which accept any base URL.

test_the_sliders_reach_the_server dropped its custom parametrization because it
asserted the behaviour this changes, and the ollama strip test is now one
parametrized guard over both. Both new cases fail without the registry entry.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: a933d606e4

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

Final comment-reduction pass. The stale-tab rationale was written out three
times, once at the registry entry and once in each test. It belongs at the
registry entry that exists because of it; the tests name the behaviour they
check, not the history. Twelve lines become five, and the PR's added comment
lines land at 33 against 74 on the original branch.

No code touched.
@danielhanchen

Copy link
Copy Markdown
Member

@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: 04db26cf9a

ℹ️ 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 +1294 to +1298
if top_k is not None:
body["top_k"] = top_k
if min_p is not None:
body["min_p"] = min_p
if repetition_penalty is not None:

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 Restrict sampling extensions to supported providers

When a direct /v1/chat/completions caller explicitly supplies one of these fields for an OpenAI-compatible hosted provider whose capability row disables it, such as Kimi or DeepSeek, this unconditional insertion now forwards the unsupported extension upstream. The registry only strips these fields for Custom and Ollama (Kimi's body_omit covers only temperature and top_p), so requests that previously succeeded while ignoring the extension can now be rejected by the provider. Gate forwarding server-side to vLLM, OpenRouter, and llama.cpp, or add matching omission rules for unsupported providers; frontend capability checks do not protect public API callers.

Useful? React with 👍 / 👎.

@danielhanchen
danielhanchen merged commit 19f283a into unslothai:main Sep 8, 2026
50 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants