Repository navigation
Studio: improve Auto context selection and share remembered model settings - #9492
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5a7a09ae5b
ℹ️ 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".
| customContextLength: | ||
| override.custom_context_length ?? local.customContextLength, | ||
| maxSeqLength: override.max_seq_length ?? local.maxSeqLength, |
There was a problem hiding this comment.
Preserve valid override lengths when hydrating
When an API-authored override contains a valid custom_context_length below 128 or a max_seq_length that is not a multiple of 128, the backend accepts and applies that exact value, but passing it through normalizePerModelConfig floors the former to 128 and rounds the latter to a 128-token boundary. Opening this panel therefore makes picker loads differ from API auto-switch loads and can persist the altered value on the next save; either align the backend contract with the UI restrictions or preserve server values during hydration.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving this as it is. Neither value can come from the panel: the context input has min 128 and normalizeMaxSeqLength snaps to the 128 step on every save, so a sub-128 custom_context_length or an unrounded max_seq_length only reaches a row through the overrides API. normalizeV1 has always clamped such a value when reading a local blob, and hydration puts the row into that same schema, which is what makes it editable here. Preserving the raw number would defer the clamp to the first edit rather than avoid it, and tightening ModelOverridePayload to the panel's step would start refusing rows the loader accepts today.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7b28ad778
ℹ️ 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".
| customContextLength: | ||
| override.custom_context_length ?? local.customContextLength, | ||
| maxSeqLength: override.max_seq_length ?? local.maxSeqLength, |
There was a problem hiding this comment.
Honor backend precedence for dual context overrides
When a legacy or API-authored GGUF override contains both max_seq_length and custom_context_length and is not using Manual mode with Auto layers, this hydration preserves both fields. The picker then sends customContextLength because resolveLoadMaxSeqLength gives it precedence, while the server's resolve_fit_max_seq_length explicitly gives max_seq_length precedence. Opening the picker and loading the model can therefore use a different context than API auto-switching the same stored row; collapse the two fields according to the backend's precedence during hydration.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The two resolvers do disagree on a both-fields row, but this PR does not move either load. resolveLoadMaxSeqLength returns customContextLength when it is set and 0 for any other GGUF load, so a local config that also carries maxSeqLength sends exactly what it sent before hydration existed, and resolve_fit_max_seq_length has always read the row itself. A row holding both is legacy or hand written, as the comment above that function says, and copying it into local storage leaves both paths where they were.
Collapsing one of the two during hydration would delete a stored field to cover a resolver mismatch that predates this change and applies equally to a local config the panel never touched. If the precedence should be one rule, that belongs in resolveLoadMaxSeqLength or resolve_fit_max_seq_length, on its own.
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Confirmed the overrides route in studio/backend/routes/settings.py still drops load_mode, spec_draft_cache_type, ctx_checkpoints and cache_ram, so those remembered values never reach a load, and the hydration fix follows from it. The direction is right, but this also carries the Auto slider rework and the 4096 to 8192 offload fallback; could you split those two out so the settings fix can go in on its own? |
mahiatlinux
left a comment
There was a problem hiding this comment.
studio/backend/core/inference/llama_cpp.py:17368 lets --fit reduce the new 8,192 fallback to 4,096
Both new host-offload branches replace -c 0 with -c 8192, but _ctx_integrity_flags() only emits --fit-ctx for an explicit context or auto_fit. A full load_model call with Auto, a native context of 196,608, 131 GiB of weights, 97,000 MiB of free GPU memory, and supports_fit_ctx produced -c 8192 --fit on without --fit-ctx. This file documents that llama.cpp's fit minimum defaults to 4,096 and only -c 0 disables that reduction, so the fitter can undo the fallback this PR adds.
Track entry into either Auto host-offload branch and emit --fit-ctx <effective_ctx> when the binary supports it. Add an argv-level regression test. All 65 context-fit tests still pass when both production assignments are restored to 4,096 because _drive() mirrors the changed block and reads the production constant instead of exercising the command builder.
studio/frontend/src/features/model-picker/api/model-overrides.ts:324 preserves settings another origin cleared
A normal override PUT replaces the complete server entry, but fromApiOverride() treats every omitted field as missing data and restores it from local storage. For example, if Desktop holds nParallel=4 and physical GPU [1], then LAN clears both while retaining kv_cache_dtype=q8_0, the server row contains only the KV dtype. Hydrating that row on Desktop returns nParallel=4, GPU [1], and q8_0. A full remote reset is also ignored because model-config-page.tsx:2182 maps a missing row to null and never updates the config or local storage. Desktop therefore keeps loading stale settings and its next save resurrects them on the server.
The response needs authority metadata or field tombstones so a successful hydration can distinguish a clear from a legacy or incomplete row. An omitted GPU pin should preserve local IDs only when their namespace is Vulkan, not when they are a stale physical pin.
studio/frontend/src/features/model-picker/components/model-config-page.tsx:2701 exposes Auto as a numeric zero
The new 0 sentinel is visual only. In Chromium, the rendered Radix thumb has aria-valuenow="0" and no aria-valuetext; the visible Auto text is not programmatically attached to it. aria-label is passed to the slider root, while components/ui/slider.tsx:103 creates the thumb without that label or value text. Assistive technology therefore receives an invalid custom context of zero instead of the Auto mode.
Pass the accessible name and aria-valuetext to the thumb, with Auto for zero and the token count for custom values.
The safe zone this branch publishes as max_context_length was still pinned to a literal 4096, with a comment saying it sits there so the slider warns above the fallback. Raising the fallback to 8192 put it below instead, so every Auto load that reaches this branch now exceeds the ceiling it published: measured over 300,000 planner points, 109,732 of 109,732 affected loads. The chat settings sheet reads that as "Context length exceeds the estimated VRAM capacity (4,096 tokens)" and advises lowering the context or leaving it on Auto, when Auto is what produced the value, while the picker stays silent on the same load because its warning is gated on the context not being Auto. Anchor it at _AUTO_OFFLOAD_CTX so the two move together. Three test mirrors had hand-copied the old literal. test_llama_cpp_max_context_ threshold.py re-implements this whole block and asserted == 4096, which is why nothing went red when production drifted; it now tracks the constant. test_compute_buffer.py's reduced-loop mirror drove a hardcoded 4096 under a docstring naming "the reduced-to-4096 loop", and reads _FIT_MIN_CTX now, which is the floor it was actually exercising. test_mmproj_placement_policy.py's offload test was genuinely failing on this branch and passing on the merge base, asserting -c 4096 against an 8192 launch; the placement is unchanged either way, so it asserts the constant. test_auto_offload_ctx_invariants.py pins both halves: the ceiling follows the constant, and the constant stays at or above the fit search floor. That second one is load-bearing and was previously implicit in the two being the same literal. The offload re-check can only award GPU residency below the floor, so raising the constant is placement-neutral only while it stays above it; below, the re-check hands over a device and flips --fit off. The floor is the min_ctx default on _fit_context_to_vram and _cap_ctx_to_per_device_reserve rather than _FIT_MIN_CTX, since neither auto call site passes the argument, so the test pins those defaults too. Also corrects the projector comment, which said Auto reaches --fit on only once 4096 will not place without noting that it then raises the context to 8192.
Two accessibility gaps, both invisible on screen and both reproduced in Chromium 151, Firefox 153 and WebKit 26.5 against the built component. Radix puts role="slider" on the Thumb, but the wrapper spreads its props onto Root, so aria-label="Context Length" landed on a plain div and the actual control had no accessible name at all. Radix only synthesises a label of its own for multi-thumb ranges, so a single-thumb slider had none. Forward aria-label and aria-labelledby to the thumb. Radix does not synthesise aria-valuetext either, so a slider whose positions mean something other than their number announces the number and nothing else. With Auto at position 0 the leftmost stop read as "0", the one value on that track that is not a context length. Add an optional thumbValueText so a caller can say what a position means, and use it for "Auto, currently 8,192 tokens" against "4,096 tokens" for an explicit pin. Measured before and after on all three engines: role=slider name=None valuenow=0 valuetext=None becomes name="Context Length" valuenow=0 valuetext="Auto, currently 8,192 tokens".
The 4096 to 8192 change touches one branch of the placement chain, so what needed proving was which cells reach that branch and that none of them move. 108 cells: Linux, WSL2, Windows and macOS against NVIDIA single and multi, AMD Vulkan, AMD ROCm, an AMD APU and a Vulkan iGPU with total 0, Apple Metal and CPU only, each at three model shapes, plus manual placement and the ROCm arch gate. Arm, site, --fit, devices and whether the offload re-check awarded residency are identical in all 108 against the merge base; 48 differ in the context alone. Worth recording from that run: sys.platform on its own changes nothing here, the four platform blocks are byte-identical. Platform reaches placement only through the numbers the probe produces, which is why the Windows ROCm cell is called out separately: rocm_windows_free_is_untrusted caps free at total minus reserved, so on one card reporting 16000 MiB free with 6000 reserved, Linux awards residency and Windows reaches the offload branch. Same hardware, and Windows AMD users meet the new value where Linux AMD users do not. Metal is pinned rather than changed. It still floors Auto at 4096 while discrete GPUs now get 8192, so an offloading model gets half the context on a Mac. That asymmetry is left as it is. The coupling file measures the floor rather than asserting it: with the constant swept below the fit floor the re-check starts awarding residency again (five awards at 256 down to one at 3072 on a 20 GB card, zero at 4096 and above), so the invariant is pinned against behaviour and not just against two numbers. Platforms other than Linux and vendors other than NVIDIA are the repo's existing monkeypatch seams, not hardware. These cover what placement does with the numbers a probe hands it, not whether the probes are right on a real Windows ROCm or Apple Silicon box.
Declaring the four tuning fields on the route moves them from browser-only to a server row that older clients can also write, so both upgrade and downgrade paths need pinning. Backend: a row written before these fields existed loads unchanged; a row carrying a key this build does not know is dropped rather than raising; and the one that matters, a PUT from an older frontend that simply omits the four removes them from the row, because a write replaces the entry and the row has no version stamp of its own. That loss reaches the command line. Nothing restores it automatically: hydration writes browser storage but does not re-mirror, so the values come back only on the user's next explicit save. Worth knowing before this lands rather than after, since before this change there was nothing on the server to lose. Also covered: spec_draft_cache_type is silently dropped unless the speculative mode uses a separate drafter, and the key folding a browser and the server must agree on, nine cases across Windows drive, UNC, WSL and POSIX paths, repo ids and quant suffixes, asserted identical from both ends. Frontend: v0 through v5 records all load with every field they carried and are re-stamped at the oldest version that understands them; a record stamped beyond this build is not read, written, deleted, listed or evicted, and its bytes are unchanged afterwards; a localStorage that throws on both get and set degrades instead of propagating; and eviction terminates rather than spinning when the budget cannot be met without touching a future record. Two behaviour changes are pinned as such. A tuning-only config is no longer judged default, so it is now stored where it was previously dropped on the way to storage, and it is now also uploaded by the one-time server backfill, which went from zero PUTs to one on the same input.
|
Simulated this properly rather than reasoning about it, and pushed four commits to the branch with the fixes that were unambiguous. Everything below is measured. Before and after, per changeThe settings fix. Before: The 8192 fallback. Before: Auto dropped to 4096 once no GPU subset could hold the model. After: 8192. Your no-placement-change claim holds. I did not take it on trust, because the branch re-checks residency at the reduced context and prices KV, MTP and compute buffers there, so doubling the context looked like it should be able to flip a borderline subset. 3,197,616 before/after pairs through the real The reason is worth writing down, because it is not luck. Pass 1 can only reject a subset when the footprint or the per-device reserve already fails at the fit floor, and the re-check uses the same floor, so anything winnable at or above it was already taken. Swept below the floor it is a different story: five awards at 256 down to one at 3072 on a 20 GB card, zero at 4096 and up. Your change sits entirely in the dead region. The Auto slider. Before: the leftmost position was What I pushed1. The UI ceiling, which the 8192 change broke. Three test mirrors had hand-copied the old literal. 2. A test pinning 3. Slider accessibility. Radix puts 4. Compatibility and platform coverage. 108 placement cells and a schema matrix, described below. Two I did not pushBoth change what the PR sets out to do, so they are yours. Clearing a setting on one origin resurrects it on another. Related, in the same function: because the merge takes the server value first and One keystroke from an explicit pin to Auto. Compatibility, since this PR changes where settings liveDeclaring the four on the route moves them from browser-only to a server row older clients can also write. The browser store already refuses to read, write, delete, list or evict a record stamped beyond its schema. The server row has no such stamp, and a write replaces the entry. So: a PUT from an older frontend, or from a stale cached bundle, removes the four from the row, and it reaches the command line. Nothing restores them automatically, because hydration writes browser storage but does not re-mirror; they return on the user's next explicit save. Before this change there was nothing on the server to lose, so this is new exposure rather than a regression. Pinned as a test rather than fixed, since the fix is the same authority question as above. Old installs are otherwise fine: v0 through v5 records all load with every field intact and are re-stamped at the oldest version that understands them, a pre-tuning row is a no-op, an unknown key is dropped rather than raising, a throwing or full localStorage degrades instead of propagating, and eviction terminates rather than spinning when it cannot skip a future record. Two behaviour changes on upgrade that the description does not mention, both now pinned: a tuning-only config is no longer judged default, so it is stored where it was previously dropped, and it is now uploaded by the one-time server backfill, which went from zero PUTs to one on the same input. Platform matrixLinux, WSL2, Windows and macOS against NVIDIA single and multi, AMD Vulkan, AMD ROCm, an AMD APU and a Vulkan iGPU with Two things fell out. Mac question for you. Metal still floors Auto at 4096 while discrete GPUs now get 8192, so an offloading model gets half the context on a Mac. The description says Metal planning is intentionally unchanged, so I have pinned the 4096 rather than touched it, but is the split deliberate? ScopeHonest about the simulation: one Linux host, one NVIDIA card. Only Linux plus NVIDIA is native. The other platforms and vendors are the repo's own monkeypatch seams, so this covers what placement does with the numbers a probe hands it, not whether the probes are right on real Windows ROCm or Apple Silicon. Browsers are real, all three engines actually executed the component. Edge is Chromium and has no separate engine; WebKit stands in for Safari and for the WebKitGTK the Linux desktop shell embeds, which is worth noting because One pre-existing thing I will not touch here: the no-KV-metadata path publishes a ceiling below its context in 61,848 sweep points, unchanged before and after this PR and unaffected by the anchor fix, since that branch never runs the ceiling probe at all. 1381 backend tests pass across every affected suite, including the one that was red. Typecheck and production build are clean. The split request still stands, and I think the evidence makes the case better than I did. The settings fix is self-contained, has a data-loss path on main, and I would take it today. The 8192 change I now believe is safe, and with the ceiling fix and the floor test it is ready. The hydration authority question and the Auto detent are the two I would rather settle separately. |
savePerModelConfig says "no settings" by deleting the entry, so a merge that comes out default is a clear that has to be written, not a write to skip. The adopt block gated the call on the merge being non-default, which is exactly the case that needed to travel. Reachable shape: a model whose only remembered setting is its extra arguments. Clearing them on another origin leaves the row as an explicit empty list, the merge is then a default config, the write was skipped, and this browser kept the old flag. model-selector's quick select reads local storage through resolveInitialConfig without opening the panel, so the next launch got the flag back that was just cleared. Dropping the guard is enough: savePerModelConfig already no-ops when there is no entry to delete.
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
A load stops at the first non-empty override row rather than merging across spellings, so tuning sitting in a row the qualified key shadows never applies. Filling one field of the winning row from a later fallback promoted a dormant value into an active one, as a side effect of a save about something else. Take the group from the first row that exists and stop there.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 70945861e7
ℹ️ 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".
| const contextInputValue = contextIsAuto | ||
| ? Math.min( | ||
| Math.max( | ||
| activeLoadedContext ?? AUTO_OFFLOAD_CONTEXT_LENGTH, |
There was a problem hiding this comment.
Seed Auto edits from the Metal fallback on Apple
On an unloaded GGUF on an Apple/Metal host, focusing the Auto input exposes 8,192 as the editable value because this seed is unconditional, while the Metal planning branch deliberately keeps overflowing Auto loads at 4,096 (effective_ctx = max_available_ctx, with the fallback capped at 4,096). A user trying to adjust the value Auto would choose therefore starts at twice the actual Metal fallback and can turn that into an exact request that overcommits unified memory; select the seed based on the Metal platform or derive it from the backend-reported policy.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The Apple fallback really is 4,096 against 8,192 on discrete (llama_cpp.py:17505 and :17510 versus :17225), and the seed at :2412 really is unconditional, so the two numbers do disagree on a Mac. But I do not think the conclusion follows.
The stated harm does not exist. An explicit Metal request the budget cannot vouch for is refused, not launched: _metal_ctx_refusal is built at :17576 and raised at :17684. Pinning 8,192 on a Mac that can only do 4,096 gets the overcommit message naming the largest context that fits, not an overcommitted load.
The deeper issue is the premise that this seed predicts Auto. It does not, on any platform. maxContext at :2389 comes from the GGUF's own contextLength, not from the backend's published ceiling, so nothing clamps the seed to what planning decided. Take a 32,768-native model that fits comfortably on a discrete GPU: Auto launches at 32,768 and the seed still reads 8,192. The Mac overflow case is one instance of a general property, not a Metal-specific defect. It is the same reason I stopped the thumb announcing "Auto, currently 8,192 tokens" in 74d126a: the number is a starting point for editing, not a prediction.
So branching on deviceType === "mac" would not make the seed correct, it would move the error. A Mac with a model that fits natively would seed 4,096 where Auto picks 32,768, which is further off than 8,192 was.
The other half of the suggestion, deriving it from the backend-reported policy, is the right answer, and I am flagging it for @oobabooga rather than doing it here. It means the panel reading the published max_context_length instead of GGUF metadata, which changes what the ceiling and both amber warnings compare against. That is a design change to this feature and belongs to whoever owns it.
tsc -p tsconfig.test.json is a second pass over the test tree and caught both: an as const case table produced a readonly llamaExtraArgs tuple that Partial<PerModelConfig> will not accept, and an unused fetch handler parameter.
… write Two fixes to code added earlier in this branch. The tuning carry-over walked its candidate list in collection order, leading with the id the payload sent. A lookup reads the concrete load path before the advertised repo id, so on a cache upgraded from a build that keyed rows by path the snapshot row is the live one. Saving under the repo id took the unit off the dormant row and then retired the snapshot row, replacing tuning that was applying with tuning that never had. Order the candidates the way a load resolves them, via a predicate shared with the resolver so the two cannot drift. The hydration write ignored savePerModelConfig's result while having already marked the state saved. A full or unavailable store, or a record from a newer build, returns false without throwing, leaving the panel claiming the server settings were remembered while quick select and background loads still read the stale record. Feed the result back so it stays a pending change.
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…its text (unslothai#9591) * Read the settings route's contract off its parse tree, not its text `Repo tests (CPU)` has been red on main since unslothai#9492 (1f475d7) on test_the_backfill_fills_in_fields_rather_than_skipping_known_keys. The rule the test guards did not change. unslothai#9492 added a third name to the `model_dump(exclude = {...})` set in `update_openai_auto_switch_override`, the formatter then split the set one name per line, and assert '"remove", "fill_absent_fields"' in route no longer matched, because `route` is the raw source text of studio/backend/routes/settings.py and the two names now have a newline and sixteen spaces between them. Both names are still excluded. Nothing about the write-mode-is-not-a-saved-field rule moved. This is the third failure of this shape on main in as many days (unslothai#9578, unslothai#9579), so pinning a new literal only moves the next one into the future. A test that has to be re-edited whenever a set literal is reflowed is not testing the thing it names. The frontend greps in this file have no parser to hand. The backend does. Three helpers read the rule out of settings.py's AST instead: - `_model_dump_exclusions` returns the names the one `model_dump(exclude = ...)` in a given function leaves out. Exactly one such call, or the answer would be a union and a name dropped from the call that matters could hide behind another. - `_annotated_field` returns the annotation and literal default of a field on a pydantic model, so "declared as a bool defaulting to False" is asserted as that rather than as a substring. - `_forwarded_keywords` returns the keyword arguments passed as `name = payload.name`, which is the part the storage layer depends on. Each raises rather than returning empty when it cannot find what it was pointed at, so a renamed handler or field reddens here instead of passing vacuously. Verified by mutation against the repaired test, one at a time on settings.py: | Mutation | Result | |---------------------------------------------------|--------| | unmodified main | pass | | `"fill_absent_fields"` dropped from the exclude set| fail | | the exclude set reflowed onto one line, reordered | pass | | the payload field defaulted to True | fail | | `fill_absent_fields` no longer forwarded to the db | fail | | the route handler renamed | fail | | the payload field renamed | fail | The reflow is the case that caused this outage and is now the only one that stays green; every mutation that actually breaks the contract still reddens. Local: `tests/studio/test_model_picker_contracts.py` 187 passed, was 186 passed 1 failed. No production code changed. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…Auto offload context (unslothai#9594) * Price the serving-slot reduction at the fit floor, not the Auto offload context `Backend tests` has been red on main since unslothai#9492 (1f475d7), 26 failures across test_slot_reduction_context_refit.py and test_slot_refit_platform_matrix.py, both added by unslothai#9345 (1c06bc4). All 59 pass on unslothai#9492's merge base (15b9102). The two files were not run on that branch. The tests are reporting a real regression, not a stale baseline. unslothai#9492 introduced _AUTO_OFFLOAD_CTX = 8192 and put it in three places that had a literal 4096. Its reasoning: "Auto only reaches this path when no discrete-GPU subset can hold the model. llama.cpp must offload layers to host RAM either way, so prefer a context that remains useful for chat." That is true of two of the three sites, which are display values. The third, in load_model's auto arm, is the probe context of a placement search that runs AFTER it, in a block whose entire purpose is to overturn the premise "no subset can hold the model" by re-asking at fewer serving slots. Offload is not unavoidable at that point; it is avoidable in roughly the band where the constant now breaks it. What that costs, measured on a 12 GiB card at 4 requested slots: | weights | before unslothai#9492 | on main | |--------------------|-------------------------|------------------------| | hybrid 10,900 MiB | 1 slot, ctx 7,680, GPU | 4 slots, ctx 8,192, offload | | hybrid 11,000 MiB | 1 slot, ctx 6,144, GPU | 4 slots, ctx 8,192, offload | | hybrid 11,100 MiB | 1 slot, ctx 4,608, GPU | 4 slots, ctx 8,192, offload | | dense 9,800 MiB | 2 slots, ctx 4,608, GPU | 4 slots, ctx 8,192, offload | | dense 10,000 MiB | 1 slot, ctx 6,144, GPU | 4 slots, ctx 8,192, offload | | dense 10,500 MiB | 1 slot, ctx 4,096, GPU | 4 slots, ctx 8,192, offload | 8 of 14 sizes swept flip from fully GPU-resident to host offload, the ~3x decode collapse (unslothai#6718) named in _slots_that_fit_on_gpu's own docstring as the thing it exists to prevent. The failure is all-or-nothing: when no slot count fits at the probe, the block returns early, so the load keeps the full slot count it could not afford AND offloads. It gets 8,192 tokens at a third of the speed where it previously had 6,144 at full speed. Not a Pareto move. The arithmetic, at 10,200 MiB against a 12288 x 0.97 = 11,919.36 MiB budget. Candidates are 707.375 MiB apart (557.75 MiB of per-slot compute buffer plus 149.625 MiB of per-slot Mamba state, both context-independent), while probing higher costs a uniform 64 KiB/token. The 2-slot candidate is 11,685.0 MiB at 4096 and 11,947.0 MiB at 8192. A display constant moved it across the budget by 27.6 MiB. Two further consequences, both of which unslothai#9492 explicitly claimed it would not have. Its own comment at llama_cpp.py:2831-2841 makes placement-neutrality the correctness criterion for moving this constant. Placement moved anyway, through a call site the analysis did not enumerate: - Device pinning. At 10,200 MiB on a 12 GiB plus 1.25 GiB pair, the 2-slot candidate no longer fits card 0 alone, so the selector adds card 1 and the re-fit runs across both: CUDA_VISIBLE_DEVICES goes from "0" to "0,1", the layer split the block's comment says this path avoids. - Monotonicity. Asking for 2 slots returns 2; asking for 3 returns 1. unslothai#9492's coverage was structurally blind to all of this: test_auto_offload_ctx_platform_matrix.py never passes n_parallel, so all 108 cells ran at the GgufLoadIntent default of 1, and the block is gated on n_parallel > 1. ## The fix Three changes in llama_cpp.py, all in the reduction block: 1. The search is priced at a new local `_reduce_ctx`, which is `min(effective_ctx, _FIT_MIN_CTX)` and never _AUTO_OFFLOAD_CTX. An explicit context is the exception and keeps its own value, since it launches verbatim and a slot count picked at a lower context would not hold. `_FIT_MIN_CTX` rather than a literal because _largest_ctx starts its binary search at the same floor and the two have to agree; that search's `min(4096, _native)` now reads the constant too. 2. The re-fit is applied whenever it exists, not only when it exceeds effective_ctx. That gate was safe only while the search and effective_ctx shared a value. The re-fit is the largest context the FINAL slot count holds on the cards the reduction chose, so anything else launches a context that was never priced. 3. The published ceiling replaces the offload anchor rather than max()-ing with it. Reaching there means the anchor described a plan this block superseded, and max() would advertise a context the launched plan cannot serve, the same ceiling/selection inversion unslothai#9492 removed, pointing the other way. Placement is now invariant to _AUTO_OFFLOAD_CTX, which is what the constant being a display value means. unslothai#9492's intended improvements are all kept: the UI ceiling anchor, the file-size-only arm, and the 8,192 context on loads that do genuinely offload. ## Tests Two of the 26 were genuinely stale: both assert the offload fallback itself, never reach the reduction, and hardcoded 4096. They now read `min(_AUTO_OFFLOAD_CTX, NATIVE_CTX)` so the constant can move again, each with a guard asserting the case still lands in the branch its name claims. The explicit-context one keeps its 32768 literal, since honouring the request verbatim is the contract and a derived value there would assert nothing. TestTheReductionIsPricedAtTheFitFloor is new and pins the root cause: - the plan's slots, residency, context and devices are unchanged across _AUTO_OFFLOAD_CTX in {4096, 8192, 16384, 32768}, so this cannot be satisfied by re-baselining the constant into the expectation; - every size in the rescued band launches --fit off, with `slots < 4` proving it was rescued by the reduction rather than fitting outright; - a counterweight at 11,400 MiB that must still offload, so the band above is not green merely because everything is; - the final slot count is monotone in the requested count, with a guard that the row is not all the same number. test_compute_buffer.py's test_wired_into_both_call_sites counted source substrings and reddened on the variable rename here. It now reads the call sites out of load_model's parse tree and requires every one that passes split_extra_bytes to pass `_cc_split_extra(<name>)`. That turned up a fourth call site the counting version could not see: it counted the two spelled `effective_ctx` plus one spelled `ctx`, and the projector-floor site spells its context `_mm_floor_ctx`, so the check that claimed to cover every call site had never covered it. It has been wired correctly all along. ## Anti-vacuity One mutation at a time against the repaired suites (77 tests): | Mutation | Result | |---------------------------------------------------|------------------| | this branch | 77 passed | | probe put back at the offload fallback | 35 failed | | ceiling put back to max() | 7 failed | | re-fit gated on being an increase again | 16 failed | | explicit context probed at the floor | 2 failed | | _AUTO_OFFLOAD_CTX moved to 4096 | 77 passed | | _AUTO_OFFLOAD_CTX moved to 16384 | 3 failed | Every reintroduction of the defect reddens. Moving the constant to 4096 is fully green, which is the invariance the fix is for. At 16384 the three remaining failures are in test_slot_refit_ctx_checkpoints.py, where the charged case stops reaching the re-fit at all; placement there is still identical at both anchors (4 slots, --fit on, same search) and only the launched context tracks the constant, by design. Left alone rather than re-scoped: that file is green before and after this change. ## Local runs - the three re-fit suites: 77 passed, was 33 passed 26 failed. - 81 placement, VRAM, GPU, context and llama.cpp backend test files, the blast radius of this change: 4033 passed, 2 skipped, 0 failed. Was 1 failed. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Stop the slot re-fit tests encoding the fit floor as a literal These three files pin placement outcomes that are arithmetic against _FIT_MIN_CTX, so moving the floor re-edits the tests and the re-edit is indistinguishable from noticing that placement changed. #9492 already moved it once; test_weights_that_fit_nowhere_still_offload reads _AUTO_OFFLOAD_CTX for exactly this reason, and this extends that treatment. - test_the_reduction_still_pins_without_a_native_context read the floor as 4096 and pinned the surviving slot count. Read the constant, and assert a reduction happened rather than which number it landed on. - The _AUTO_OFFLOAD_CTX sweeps were literals including values below a raised floor, so they drove the planner through a state the product never reaches (_AUTO_OFFLOAD_CTX is documented to sit at or above _FIT_MIN_CTX). Expressed as multiples of the floor: identical values today, still intended after a move. - The checkpoint reserve test asserted the reserve is paid in context. There are three ways to pay -- context, a slot, or residency -- and at 16 and 32 checkpoints this fixture already offloads, where the old assertion held only because the offload fallback happens to be shorter. Name all three so 'nothing was charged' stays distinguishable from 'a different axis paid'. - The platform matrix shares one fixture across nine cells, and whether it reaches the re-fit at all depends on the floor. A floor change turned all nine red with 'assert 0 > 0', which reads like the re-fit was deleted when the block is untouched. Added an anti-vacuity test that names the fixture, the floor and the plan the planner actually returned, and pointed the cells at it. No production change: these pass at the current floor and report the cause rather than the symptom at any other. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: danielhanchen <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Summary
This PR makes Auto a clear context choice, increases the default context when system RAM offload is unavoidable, and keeps remembered model settings consistent across Studio entry points.
Make Auto a real slider position
The far-left position on the context slider now means Auto, and the input displays
Autoinstead of the value chosen during the current load. Moving the slider to the right or typing a number creates an exact custom request.This makes it clear whether Studio will fit the context automatically or use the requested value. The existing info icon explains both modes and shows the selected and native context sizes when available. The warning below the slider only appears when a custom value exceeds the context that fitted during the current load.
The picker Playwright regression that re-types the shown context now reads that number from the focused input, since the box reads
Autountil it has focus. Re-typing the number Auto would pick still commits nothing, which is what the step guards.Increase the offload fallback to 8,192
When a model cannot fit on any available combination of discrete GPUs, llama.cpp must move some layers to system RAM. Studio previously reduced Auto to at most 4,096 tokens before allowing this.
Auto now uses a fallback of up to 8,192 tokens in that case. Reducing it to 4,096 cannot keep the model fully on GPU once weight offload is already required. This does not change explicit context requests, models that fit on GPU, or Metal planning.
Share remembered settings across Studio
The picker previously started with settings from browser storage, which is separate for the Desktop app, LAN addresses, and tunnels. The same model could therefore show different remembered settings depending on how Studio was opened.
The picker now loads the complete remembered GGUF configuration from the Studio server. This gives every entry point the same shared settings.
Two things were needed before that was safe to do.
The overrides route was dropping
load_mode,spec_draft_cache_type,ctx_checkpointsandcache_ram. The storage normalizer and the auto-switch loader have handled all four since they were added to Run settings, butModelOverridePayloadnever declared them, so a value set in the panel reached a picker load and nothing else. The route declares and forwards them now, which also means an API auto-switch load applies the tuning the model was remembered with.Hydration merges rather than replaces. The server row wins for every field it carries, and a field it does not carry keeps the value this browser holds: the mirror is best-effort, so an absent field is as much a gap as a chosen default, and adopting the row wholesale erased settings a PUT never delivered or a legacy config had just migrated in. What is written back to browser storage is merged onto the stored record rather than onto what the panel shows, because an active model seeds the panel from the config the resident model is running with. The trade is that clearing one field on another origin does not travel until this one saves again, which the schema cannot express in any case. Hydration also preserves explicitly cleared extra arguments and local Vulkan GPU selections, and it does not overwrite edits made while the request is in flight.
Screenshot
Verification
git diff --checkpassed.