Repository navigation
Studio: apply remembered settings for MLX and safetensors models to API loads - #11904
Merged
Merged
Conversation
The OpenAI API auto-switch applies a model's server override row to MLX and safetensors loads too, but the settings panel read that row only for GGUF models, so a non-GGUF panel showed this browser's copy while API loads used another. The panel now adopts the row for every non-diffusion model, without the llama-server arguments a non-GGUF load never sends, and Load waits for the read as it does for GGUF: with Remember unchecked, Load forgets the row, so loading before it was read would delete settings the panel never showed.
"Remember for this model" only mirrored settings to the server override store for GGUF models, so an OpenAI API auto-switch loaded MLX and safetensors checkpoints with defaults (chat template, KV cache bits, context) even though the auto-switch has served them since non-GGUF weights became loadable through it. Both settings targets now share apiAutoSwitchMayLoad, which only excludes identities the resolver never serves: a LoRA adapter and a materialized Ollama link. The chat sidebar passes whether the loaded model is a LoRA adapter. A cached repo loads from its snapshot directory and /api/inference/status reports that path, while the picker keys the repo id; the backend folds those two spellings only for a quant. The sidebar and the resident config resolver now key a snapshot directory loaded without a quant by its repo id, and a record an older build saved under the path is moved to the repo id, so a bare snapshot-path row can no longer outrank the picker's row or survive its Forget.
The one-time upload of settings remembered only in this browser skipped every model that was not a GGUF quant, a .gguf file or an Ollama tag, so MLX and safetensors settings saved before the API mirror covered them kept loading with defaults through an API auto-switch. The pass now offers any remembered model except identities the resolver never keys (materialized Ollama links, bare file labels) and reruns once under a new done flag. A record an older build saved under a cached repo's snapshot path is moved to its repo id first, and one that cannot be moved is not uploaded, since a bare snapshot-path row would outrank the repo's.
Lyxot
force-pushed
the
fix/non-gguf-override-mirror
branch
from
September 25, 2026 08:29
35c2de7 to
b7f57f6
Compare
Collaborator
Author
|
Codex review on the staging copy converged on head Staging CI on the same head (https://github.com/Lyxot/unsloth/pull/88/checks): all 46 checks passed.
|
NilayYadav
approved these changes
Sep 25, 2026
shaojun
pushed a commit
to shaojun/unsloth
that referenced
this pull request
Sep 29, 2026
…PI loads (unslothai#11904) * fix(studio): show the server settings row in the non-GGUF settings panel The OpenAI API auto-switch applies a model's server override row to MLX and safetensors loads too, but the settings panel read that row only for GGUF models, so a non-GGUF panel showed this browser's copy while API loads used another. The panel now adopts the row for every non-diffusion model, without the llama-server arguments a non-GGUF load never sends, and Load waits for the read as it does for GGUF: with Remember unchecked, Load forgets the row, so loading before it was read would delete settings the panel never showed. * fix(studio): mirror remembered settings for non-GGUF models to the API "Remember for this model" only mirrored settings to the server override store for GGUF models, so an OpenAI API auto-switch loaded MLX and safetensors checkpoints with defaults (chat template, KV cache bits, context) even though the auto-switch has served them since non-GGUF weights became loadable through it. Both settings targets now share apiAutoSwitchMayLoad, which only excludes identities the resolver never serves: a LoRA adapter and a materialized Ollama link. The chat sidebar passes whether the loaded model is a LoRA adapter. A cached repo loads from its snapshot directory and /api/inference/status reports that path, while the picker keys the repo id; the backend folds those two spellings only for a quant. The sidebar and the resident config resolver now key a snapshot directory loaded without a quant by its repo id, and a record an older build saved under the path is moved to the repo id, so a bare snapshot-path row can no longer outrank the picker's row or survive its Forget. * fix(studio): backfill browser-only settings for non-GGUF models The one-time upload of settings remembered only in this browser skipped every model that was not a GGUF quant, a .gguf file or an Ollama tag, so MLX and safetensors settings saved before the API mirror covered them kept loading with defaults through an API auto-switch. The pass now offers any remembered model except identities the resolver never keys (materialized Ollama links, bare file labels) and reruns once under a new done flag. A record an older build saved under a cached repo's snapshot path is moved to its repo id first, and one that cannot be moved is not uploaded, since a bare snapshot-path row would outrank the repo's.
shimmyshimmer
pushed a commit
to shimmyshimmer/unsloth-staging-4
that referenced
this pull request
Oct 23, 2026
unslothai#14515) Fixes unslothai#10631 ## Problem Studio already saves each model's run settings (context length, KV cache, speculative decoding, GPU placement), and the OpenAI-compatible auto-switch applies them when an API request loads that model (unslothai#7473, unslothai#11904, unslothai#10216). Sampling is the gap: - Chat only remembers the last values used with each model. There is no way to say "this is how I want this model to sample" outside the chat sidebar. - An API request that switches to a model and leaves `temperature`, `top_p` and so on unset always gets the model's recommended values. Nothing the user set in Studio reaches it. ## What this adds A **Save for this model** button at the bottom of Chat settings, below Retrieval. It saves the sampling currently shown (Temperature, Top P, Top K, Repetition Penalty, Presence Penalty, and Min P when it is set to a custom value) as the loaded model's defaults. It is hidden for external providers. Seed and Max Tokens are not part of it. A save writes to two places: - **API requests.** The values go to a per-model, per-account server store (`model_sampling_defaults`, `PUT /api/settings/model-sampling-defaults`). `resolve_effective_sampling` reads it, so `/v1/chat/completions`, `/v1/completions`, `/v1/responses` and `/v1/messages` fill unset fields from it, including the request that switches the model in. The order is: operator `UNSLOTH_SAMPLING_*` pin, then the request's own value, then the saved default, then the model's recommendation, then the schema default. The `/sampling-defaults` route behind the API page's example request uses the same function. - **Chat.** The same values go into the per-model memory Chat already restores on every load, so new chats with that model start from them. Without the button, sampling edits made inside a conversation stay with that conversation. If a slider moves while the save is in flight, the newer value is kept on screen. How defaults are keyed: - One row per model, not per quant. - A cache snapshot path is stored under its repo id, so a new revision still finds the row. - Repo ids and Windows, UNC and WSL paths match regardless of case, using the launch overrides' `_fold_case_insensitive_path` rule. POSIX paths match exactly. - The server resolves reads itself, so the browser does not mirror these rules. ## Not changed - Nothing changes for anyone who never saves a default. The store is empty, the lookup returns early and resolution is the same as before. - Run settings and load overrides are untouched. The sampling store is separate from the launch override map on purpose: a row there counts as a load override, can shadow a broader repo row and re-ticks "Remember for this model". - Explicit request values and operator pins still win. - `/v1/completions` on a vLLM or SGLang engine still forwards the body without any per-model fill, as before. - The button and its save code are loaded lazily. The startup bundle grows by 274 B raw / 131 B transfer, inside the existing budget, so `scripts/check-bundle-budget.ts` is unchanged. ## End to end Real Studio installs at the merge base and at this branch, CPU only, `unsloth/gemma-3-270m-it-GGUF` Q8_0, auto-switch on. Values are what llama-server reports in `/slots` after the request: | | merge base | this PR | |---|---|---| | Save temperature 0.123, top_k 7, repetition 1.17 | route absent (405) | 200 | | `/v1/chat/completions` that switches the model in, no sampling fields | temp 1.0, top_k 64, repeat 1.0 (recommended) | temp 0.123, top_k 7, repeat 1.17 | | Same request with `temperature: 0.9` | 0.9 | 0.9 | ## Cost `resolve_effective_sampling` runs once per request, never per token. The store read reuses the 2 s cached setting the auto-switch already uses, and an index is rebuilt only when that cache refreshes. Per-call timing on this host (median of 5 x 20k calls, base and head alternating, two rounds): | | base | head | |---|---|---| | nothing saved | 6.5 / 8.1 us | 8.6 / 9.9 us | | 50 models saved, miss | - | 10.1 / 10.0 us | | 50 models saved, hit | - | 10.4 / 11.4 us | ## Tests `studio/backend/tests/test_model_sampling_defaults.py` (16 tests) covers: - precedence against explicit values, operator pins and the Qwen3 thinking table; - the `/v1/completions` passthrough `repeat_penalty` alias; - snapshot path and quant-qualified ids; - POSIX and Windows path matching, and ambiguous case folds; - out-of-range and NaN values dropped, idempotent saves, clearing; - an unreadable store never failing a request; - `/sampling-defaults` reporting the saved value. Reverting only the resolution hook makes 5 of them fail. Backend tests touching the settings routes fail the same 27 pre-existing cases on the merge base and on this branch, and nothing new. Frontend: `tsc` clean, `vite build` OK, `npm test` 13619 passed, 0 failed. ## Screenshots Bottom of Chat settings with a GGUF loaded, merge base vs this PR. Clicking the button on the right stored the sampling shown for the model, and `/api/inference/sampling-defaults` then reported those values:  --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11821
Problem
In Unsloth Studio, "Remember for this model" saved settings only in the browser for MLX and safetensors models. The server override store, which the OpenAI API auto-switch applies to
/v1/*loads, was updated only for GGUF targets. Since #8768 the auto-switch also loads non-GGUF weights, so an API request loaded those models with defaults and ignored the remembered context length, KV precision, or chat template.Root cause
Both settings targets (the model picker and the chat sidebar) set
apiLoadabletoisGguf && !ollamaLink. The one-time backfill filtered to GGUF ids in the same way. Neither was widened when the auto-switch gained non-GGUF support. The panel's server-row hydration also returned early for every non-GGUF model, so even a row written by another origin or a manual PUT never showed in the panel.Changes
llama_extra_args(panelOverrideRow), since a non-GGUF load never sends them. Load now waits for this read on every non-diffusion model, as it already did for GGUF. With Remember unchecked, Load forgets the server row, so a load started before the read settled would delete settings the panel had never shown. The existing release paths (settle, failure, 15 s backstop) are unchanged.apiAutoSwitchMayLoad, which excludes only what the backend resolver never serves: bare LoRA adapters and materialized Ollama links. For a cached Hugging Face repo loaded with no quant,/api/inference/statusreports the snapshot path. The sidebar now keys that model by its repo id (cachedRepoConfigId), matching the picker; otherwise a bare snapshot-path row would outrank the picker's row on the backend and survive its Forget. Browser records an older build saved under the snapshot path are adopted to the repo id lazily. A record already under the repo id wins.v3so installs that already ranv2pick them up. It still fills only absent rows and never overwrites; snapshot-path records are adopted to the repo id first, so it never uploads a snapshot-path row.The commits are ordered so the Load wait lands before non-GGUF mirroring; no commit has forget-on-load without it.
Risks and tradeoffs
resolve_override_for_loadandmodel_override_load_kwargs(is_gguf=False)already honor non-GGUF rows.Validation
Targeted frontend tests pass at each commit, and every new assertion fails when its production change is reverted:
End to end against an isolated Unsloth Studio on Apple Silicon: I saved the override row the panel now sends for
Qwen/Qwen3-0.6B(custom chat template,mlx_kv_bits=8). A/v1/chat/completionsrequest that auto-loaded the model applied both settings.Not exercised in a browser: the brief Load wait for a non-GGUF model. It's covered by source-level tests only, because the panel has no renderer in this test suite.