Skip to content

Studio: bring the Llasa top_p default inside the range the API accepts - #9194

Merged
oobabooga merged 3 commits into
mainfrom
fix-llasa-top-p
Sep 3, 2026
Merged

oobabooga merged 3 commits into
mainfrom
fix-llasa-top-p

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

studio/backend/assets/configs/model_defaults/llasa/unsloth_Llasa-3B.yaml ships top_p: 1.2. top_p is a probability, and the OpenAI-shaped request models bound it at le=1.0 (studio/backend/models/inference.py:1062 GenerateRequest, :1962 ChatCompletionRequest, :3049 ResponsesRequest). So the value this config recommends to the Chat UI cannot be sent back to the endpoint that served it.

Nothing range-checks it on the way out. load_inference_config returns the YAML block as it is. The load and status handlers put that dict straight into LoadResponse.inference and InferenceStatusResponse.inference, both untyped dicts (models/inference.py:1386, :1514). mergeBackendRecommendedInference then adopts it through a finiteness check only (studio/frontend/src/features/chat/presets/preset-policy.ts:268), so top_p: 1.2 reaches the chat's live params and is posted verbatim on /v1/chat/completions (chat-adapter.ts:5304, chat-api.ts:1573).

Against the real request models and error handlers:

POST /v1/chat/completions             top_p=1.2 -> 400  {"error":{"message":"top_p: Input should be less than or equal to 1","type":"invalid_request_error","param":"top_p"}}
POST /api/inference/chat/completions  top_p=1.2 -> 422  {"detail":[{"type":"less_than_equal","loc":["body","top_p"],"input":1.2,"ctx":{"le":1.0}}]}
POST /v1/chat/completions             top_p=1.0 -> 200

400 is the shape the Chat UI gets. install_api_error_handlers rewrites RequestValidationError into the OpenAI envelope for every /v1/* path (utils/api_errors.py:319-336). 422 is the non-/v1 mount.

Fix: set the default to 1.0. That is nucleus sampling off, which is what a value above 1 was reaching for, so it keeps the intent and makes it expressible.

Scope, since this value has shipped since February:

  • The server never forwarded 1.2 to llama-server. _clean_sampling_value returns None for an out-of-range value, so _recommended_sampling drops the field and resolve_effective_sampling falls through to the static 0.95. The rejection is the request model's bound alone.
  • Sampling for this model does change, and in the intended direction. Now that the value is valid the recommendation survives cleaning, so a request that omits top_p resolves to 1.0 rather than the static 0.95, on /v1/chat/completions, /v1/completions and /v1/messages alike. 1.0 is what the Llasa reference code asks for: it passes top_p = 1.2 (tests/saving/text_to_speech_models/test_lasa.py:200), and _get_logits_processor builds a TopPLogitsWarper only when top_p < 1.0, so 1.2 and 1.0 are the same no-truncation setting there. Studio was applying 0.95 only because the recommendation was unparseable.
  • Reaching that rejection needs the model already resident by another route, such as a direct /api/inference/load. A Generate-picker pick of unsloth/Llasa-3B never loads it. Llasa speaks XCodec2, which AudioCodecManager cannot decode, so communityAudioRowIsRunnable refuses the row and the curated catalog leaves it out (audio-picker-policy.ts, model-catalog.ts). The pick ends at a toast. This YAML's live use is training.
  • Not every request model carries the bound. AnthropicMessagesRequest.top_p (models/inference.py:3404) is unbounded, unlike the min_p and repetition_penalty two lines below it, so /v1/messages forwards an out-of-range value unvalidated. Left alone here: adding a bound there would reject requests that are accepted today.

The new test_model_recommended_sampling_values_are_in_range walks every assets/configs/model_defaults/**/*.yaml and puts each UI-adopted sampling field through _clean_sampling_value, so the next out-of-range default fails a test instead of reaching the UI. It scans 78 files, and this was the only value outside the range. assets/configs/inference_defaults.json, the family defaults on the same resolution path, has none either.

Verification, end to end against a running Studio on an RTX 6000 Ada with unsloth/Llasa-3B loaded through POST /api/inference/load:

head (top_p 1.0)  GET /api/inference/status -> inference.top_p 1.0
                  replaying it on /v1/chat/completions -> 200, 16 speech tokens
                  omitting top_p entirely                -> 200
main (top_p 1.2)  GET /api/inference/status -> inference.top_p 1.2
                  replaying it on /v1/chat/completions -> 400 top_p: Input should be less than or equal to 1

python3 -m pytest studio/backend/tests/test_sampling_resolution.py -q is 32 passed at head, 51 passed with test_yaml_trust_remote_code_removed.py and test_muse_glimmer_sampling_defaults.py added, and the new test goes red on its own if the YAML is put back to 1.2. The frontend sampling and audio-picker suites are 52 passed. The 400/422 status shapes are also reproduced by a TestClient over the real install_api_error_handlers and ChatCompletionRequest.

Found while reviewing #9056, unrelated to it, so it goes separately.

The shipped default was 1.2, but top_p is a probability: every request
model bounds it le=1.0 and _SAMPLING_FIELDS uses (0.0, 1.0). So the
value the Chat UI was handed for this model was rejected with a 422 by
the endpoint the UI sends it to, and every generation on Llasa-3B
failed. 1.0 is nucleus sampling off, which is what a value above 1 was
reaching for.
@danielhanchen

Copy link
Copy Markdown
Member Author

Confirmed the Llasa default still sits at 1.2 while both ChatCompletionRequest and _SAMPLING_FIELDS bound top_p to 1.0, so the recommended value never survives the trip back to the endpoint. Will get this reviewed.

@mahiatlinux

Copy link
Copy Markdown
Contributor

studio/backend/assets/configs/model_defaults/llasa/unsloth_Llasa-3B.yaml:47 the endpoint the Chat UI posts to answers 400, not 422

The Chat UI's local send is chat-adapter.ts:5440 into streamChatCompletions, which posts to /v1/chat/completions (studio/frontend/src/features/chat/api/chat-api.ts:1344). install_api_error_handlers rewrites RequestValidationError to 400 in an OpenAI envelope for every /v1/* path (studio/backend/utils/api_errors.py:329-338). 422 is the shape on the non-/v1 mount:

POST /v1/chat/completions             top_p=1.2 -> 400  {"error":{"message":"top_p: Input should be less than or equal to 1","type":"invalid_request_error","param":"top_p"}}
POST /api/inference/chat/completions  top_p=1.2 -> 422  {"detail":[{"type":"less_than_equal","loc":["body","top_p"],"input":1.2,"ctx":{"le":1.0}}]}

Llasa never reaches the 422 mount. That is the audio branch at chat-adapter.ts:4599, gated on activeModel.isAudio, and is_audio is false for this model: its tokenizer carries 65,800 added tokens (<|s_0|> through <|s_65535|>) and matches none of _AUDIO_TOKEN_MARKERS, so detect_audio_type returns None and utils/models/model_config.py:3664 leaves the flag false. studio/frontend/tests/audio-catalog-decodable.test.ts:6-9 records the same result from a running Studio.

Drop the status code. The bound is the part that holds.

unsloth_Llasa-3B.yaml:45-46 _SAMPLING_FIELDS is why the server used 0.95, not why the request was rejected

_clean_sampling_value returns None for an out-of-range value (studio/backend/utils/inference/inference_config.py:197-210), and resolve_effective_sampling then falls through to the static default (:266-287). Against the merge base:

load_inference_config('unsloth/Llasa-3B')  -> {'temperature': 1.2, 'top_p': 1.2, ...}   served to the UI
_recommended_sampling('unsloth/Llasa-3B')  -> {'temperature': 1.2, ...}                  top_p dropped
resolve_effective_sampling(top_p omitted)  -> {..., 'top_p': 0.95, ...}

The constant never produced an HTTP error. The rejection comes from ChatCompletionRequest (studio/backend/models/inference.py:1425) alone, and the same fallback is why a client that omits top_p was never affected: the Audio page sends temperature only, and only when edited (studio/frontend/src/features/audio/audio-page.tsx:1387-1391), and never sends top_p at all.

unsloth_Llasa-3B.yaml:47 "failing every generation on this model" is not a state Studio reaches

unsloth/Llasa-3B carries the Hub text-to-speech tag, so a chat pick routes to the Audio page (pickers.tsx:2067, :2085-2092), and communityAudioRowIsRunnable admits only orpheus|csm|spark-?tts|outetts (audio-picker-policy.ts:54-63). The pick ends at the toast "is not a speech model Unsloth can run yet" (pickers.tsx:3678-3682) without loading. The Audio page's curated catalog leaves Llasa out for the same reason (model-catalog.ts:491-496). Reaching the rejection needs the model already resident by another route.

studio/backend/utils/inference/inference_config.py:95 the block handed to the UI still bypasses the guard the server path applies, and nothing locks the range

load_inference_config returns the YAML values unchecked, and routes/inference.py:10619 and :10705 put that dict straight into InferenceStatusResponse.inference and LoadResponse.inference, both typed as a bare dict (models/inference.py:910, :1032). The UI adopts it through a finiteness check only (presets/preset-policy.ts:239-244, :295), so the same value is guarded on the server path and raw on the client path. The next out-of-range default lands in the UI the same way.

The value shipped in 238fdc5c4 and survived since February with no test failing. Both halves of the missing one already exist: studio/backend/tests/test_yaml_trust_remote_code_removed.py:66-92 already walks every model_defaults/**/*.yaml through load_inference_config, and tests/test_muse_glimmer_sampling_defaults.py:77-85 already reads a ChatCompletionRequest field bound and asserts a default sits inside it. A range assertion inside the existing sweep fails at the merge base on this file and passes at head.

PR description: "every request model bounds it at le=1.0" is not true

AnthropicMessagesRequest.top_p is Optional[float] = None with no bound (studio/backend/models/inference.py:2661), while min_p and repetition_penalty two lines below carry theirs. It backs a live route (routes/inference.py:19747). Three of the four OpenAI-shaped request models bound top_p; /v1/messages forwards 1.2 unvalidated.

@mahiatlinux
mahiatlinux self-requested a review August 19, 2026 09:46

@mahiatlinux mahiatlinux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review posted as a comment above.

@Imagineer99

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 2287998db2

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

@oobabooga
oobabooga self-requested a review as a code owner September 3, 2026 15:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 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-03T15:37:25.080735Z 632cfa6 New commits
ℹ️ 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.

@oobabooga

Copy link
Copy Markdown
Member

@mahiatlinux the four factual corrections hold. I reproduced each and rewrote the description around them.

400, not 422. wants_api_error_envelope is true for every /v1/* path, so install_api_error_handlers turns the RequestValidationError into the OpenAI envelope at status 400 (utils/api_errors.py:319-336); only the non-/v1 mount keeps 422. A TestClient over the real handlers and ChatCompletionRequest:

POST /v1/chat/completions             top_p=1.2 -> 400  {"error":{"message":"top_p: Input should be less than or equal to 1","type":"invalid_request_error","param":"top_p"}}
POST /api/inference/chat/completions  top_p=1.2 -> 422  {"detail":[{"type":"less_than_equal","loc":["body","top_p"],"input":1.2,"ctx":{"le":1.0}}]}
POST /v1/chat/completions             top_p=1.0 -> 200

The _SAMPLING_FIELDS attribution was wrong. At the merge base I get the same three lines you posted: load_inference_config('unsloth/Llasa-3B') returns top_p 1.2, _recommended_sampling drops the field, and resolve_effective_sampling with top_p omitted returns 0.95. The rejection is ChatCompletionRequest's bound alone, and the description now says that.

Reachability. communityAudioRowIsRunnable admits snac, bicodec, dac, csm and the orpheus/csm/spark-tts/outetts families only, and its own comment names Llasa as deliberately excluded; model-catalog.ts:567 repeats it and adds that the YAML's live use is training. The description no longer claims every generation fails. It now says the rejection needs the model resident by another route, such as a direct /api/inference/load.

AnthropicMessagesRequest.top_p is unbounded. models/inference.py:3404 carries no bound while min_p:3415 and repetition_penalty:3418 do. "Every request model" is out of the description. I am not adding the bound here: it would reject requests that are accepted today, which is its own change.

On the guard, I kept it in test_sampling_resolution.py instead of folding it into the model_defaults/**/*.yaml sweep in test_yaml_trust_remote_code_removed.py. That file owns the trust_remote_code invariant, while the assertion is against _UI_RECOMMENDED_FIELDS and _clean_sampling_value, which test_sampling_resolution.py already owns. It scans 78 YAML files, fails on this one at the merge base, and passes at head.

I did not widen it to assets/configs/inference_defaults.json, which the same resolution path also reads. It has no out-of-range values today, so that would be coverage with no defect behind it.

@oobabooga

Copy link
Copy Markdown
Member

I confirmed this against a running Studio with unsloth/Llasa-3B loaded: on main the status envelope serves top_p: 1.2 and replaying it on /v1/chat/completions returns 400, while at head it serves 1.0 and returns 200. The new test in test_sampling_resolution.py goes red if the value is put back, and it runs clean on Linux, macOS and Windows.

This also restores the recommendation itself. The out-of-range value was being discarded, so Studio substituted the static 0.95 on any request that omitted top_p; it now resolves to 1.0, which is what the Llasa reference code asks for, since nucleus truncation is only applied below 1.0. Generations on this model change accordingly.

Thanks also to @mahiatlinux, whose review corrected the status code, the attribution and the reachability claim in the description.

@oobabooga
oobabooga merged commit ef8f965 into main Sep 3, 2026
40 checks passed
@oobabooga
oobabooga deleted the fix-llasa-top-p branch September 3, 2026 18:50
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