Skip to content

Studio: fit the context again on a same-model GGUF reload under any preset - #18379

Merged
Lyxot merged 8 commits into
unslothai:mainfrom
oobabooga:worktree-auto-ctx-refit-reload
Nov 19, 2026
Merged

Lyxot merged 8 commits into
unslothai:mainfrom
oobabooga:worktree-auto-ctx-refit-reload

Conversation

@oobabooga

@oobabooga oobabooga commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Problem

With Context on Auto, reloading the same GGUF model fitted the context again only when the active preset was the untouched built-in Default. Under a saved preset, or after any Run settings edit such as Temperature (which marks Default as modified), changing the KV cache type, vision or the GPU set and clicking Reload model kept the old context:

  • A change that frees memory (f16 to q8_0 KV) did not grow the context.
  • A change that needs more memory (q8_0 to f16 KV) kept the old context and gave up something else instead. In the run below, the vision projector moved to the CPU.

Cause

resolveLoadMaxSeqLength (preset-policy.ts) returned 0 for an Auto GGUF load only when presetSource === "builtin-default". Under custom and modified, a same-model reload resent loadedContextLength, the context the resident model was fitted to, with max_seq_length_auto_derived: true. The backend treats any positive max_seq_length as explicit. It fits a resent value again only when MTP is forced, an exception added by #12231 for the MTP case of this bug (#9550). This PR removes the resend itself.

Fix

  • An Auto GGUF load always sends 0, so a reload is sized like a fresh load whatever preset is active.
  • isReplayedLoadContext and the frontend's max_seq_length_auto_derived field are removed. This reload was their only sender.
  • The memory estimate on the model config page follows the same rule.
  • The config page's two fixed-layer checks (estimate and Apply) now treat an unset per-model GPU memory mode as the standing preference, as performLoad does. Without this, with fixed layers and an inherited Manual mode, the estimate would price a context of 0 while Reload keeps the resident context.

Unchanged

  • A typed Context Length is still sent as typed.
  • Manual GPU memory with fixed layers still keeps the resident context on a same-model reload (performLoad), since --fit off would otherwise launch at the native context.
  • Rollback after a failed model switch can still resend the previous model's fitted context.
  • Non-GGUF, MLX and the backend. The backend still accepts max_seq_length_auto_derived from API clients.
  • Picking the resident model again after an Auto load still uses it without a reload.

Verification

Live A/B through the real UI with Playwright. The same backend served the main and PR frontend builds. The model was unsloth/Qwen3.5-9B-GGUF Q4_K_M on an RTX 6000 Ada with about 10 GB of VRAM free, so Auto fits below the native context. The /load body was captured in the browser, and the context was read from /api/inference/status.

Step main, Default untouched main, Temperature edited PR, Temperature edited
Load on Auto, f16 KV 64,512 64,512 64,512
KV f16 to q8_0, Reload sends 0, gets 96,768 sends 64512, stays 64,512 sends 0, gets 96,768
KV q8_0 to f16, Reload sends 96768, stays 96,768 with --no-mmproj-offload sends 0, gets 64,512, projector on GPU

In the main q8_0 to f16 step, the model was already at 96,768 (reached through the Default path) before the Temperature edit.

Tests:

  • replayed-load-context.test.ts, which asserted the resend, is replaced by auto-context-reload.test.ts. The new file also covers the inherited Manual estimate case. The same-model reload cases in context-pin-survives-load.test.ts and the two fixed-layer contract tests in test_model_picker_contracts.py are updated.
  • npm test has 8 failures, the same 8 as on unmodified main, and none involve this change. npm run typecheck passes, and ESLint output for the changed files is unchanged.
  • The Python tests that read the changed frontend files (29 modules, 1,507 tests) pass.

…reset

On Auto context, resolveLoadMaxSeqLength sent 0 for a GGUF load only when the
active preset was the untouched built-in Default. Under a saved preset, or after
any Run settings edit (which marks Default as modified), a reload of the same
model and variant resent the resident fitted window with
max_seq_length_auto_derived. The backend reads a positive max_seq_length as an
explicit context and only re-fits it when MTP is forced, so switching the KV
cache type, vision or GPUs kept the old window: a change that frees memory
never grew it, and one that needs more memory kept the window and gave up
something else (the vision projector moved to the CPU).

An Auto GGUF load now always sends 0, so a reload is sized like a fresh load
whatever preset is active. A typed Context Length is still sent as typed, and
Manual memory with fixed layers still pins the resident context before the
resolver runs. The replay flag no longer has a sender and is removed from the
frontend; the backend keeps accepting it. The memory estimate follows the same
rule.
… pin

The config page decided whether a same-model reload keeps the resident context
from the raw per-model gpuMemoryMode, but an unset per-model mode means the
standing preference, which is what performLoad resolves. With 20 fixed layers,
no per-model mode, Auto context and a standing Manual preference, Reload sends
the resident 32768 while the estimate priced 0. Both fixed-layer checks on the
page now go through fixedLayerContextPin, which resolves the mode the same way.
test_fixed_layer_gguf_pins_displayed_context and test_fixed_layer_pin_recomputed_after_committing_gpu_layers matched the inline conditions that moved into fixedLayerContextPin. They now check that the estimate pin reads the rendered loadableConfig and the Apply pin reads the committed effectiveConfig, both with the standing GPU memory preference.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T03:22:07.647595Z 6fa9600 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.

@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: a20dfdd2b1

ℹ️ 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 added a commit to oobabooga/unsloth that referenced this pull request Nov 18, 2026
oobabooga added a commit to oobabooga/unsloth that referenced this pull request Nov 18, 2026
@Lyxot Lyxot self-assigned this Nov 19, 2026
…ory estimate context

Every Auto GGUF load now sends 0, and the resident context is only known for a GGUF, so the estimate's resident fallback and its skip flag can no longer change the result. resolveEstimateContext takes the pin alone.
…and the config page

performLoad kept its own copy of the Manual fixed-layer rule that keeps the resident context on a same-model Auto reload, so a change there was only caught by a source match. It now calls fixedLayerContextPin, which takes the resolved GPU memory mode and keeps no context of 0. The MLX estimate uses resolveEstimateContext, which now does the same thing. Tests check the rule by behavior instead of by source text.
Also clarify which loads fixedLayerContextPin answers for, describe resolveEstimateContext for both engines, and drop a comment that repeated the helper's docstring.
@Lyxot

Lyxot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Pushed four commits on top of a20dfdd after a local review. The fix itself is unchanged.

  • c8cea935506: resolveEstimateContext takes only the pin. Its resident fallback could no longer be reached once every Auto GGUF load sends 0.
  • af548d47b63: performLoad now calls fixedLayerContextPin instead of its own copy of the Manual fixed-layer rule, so the load and the config page share one rule that is tested by behavior. The helper takes the resolved GPU memory mode and keeps no context of 0. resolveMlxEstimateContext, which had the same body, is merged into resolveEstimateContext.
  • 6a821a175ed, 6fa9600aadd: tests now pin the arguments at the load, the /load request and the re-pick check, so a change that resent the resident context on Auto, or dropped a typed one, fails a test. Comments are trimmed.

Related frontend tests (78 files, 1,184 tests), typecheck and tests/studio/test_model_picker_contracts.py pass.

@Lyxot

Lyxot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

@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: 6fa9600aad

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

@Lyxot

Lyxot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 6fa9600aad

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

@Lyxot

Lyxot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Wrap-up for head 6fa9600aadd. It is unchanged since the change comment above.

Codex: Round 1 raised one P2. With Manual fixed GPU layers and Auto context, it said re-picking a resident kept at its fitted context reloads it. I left the code as is and explained why in the thread. The reuse check only runs on a switch, and a switch sends 0. After that one reload the resident records 0, so it does not repeat. The check also can't tell a kept context from one the user typed earlier. Round 2: "Didn't find any major issues": #18379 (comment)

CI: Upstream jobs stayed queued, so CI ran on a staging PR with the same head and base (Lyxot#262, now closed). 56 pass, 3 fail, none from this PR:

  • Repo tests (CPU, rest): test_every_constexpr_line_has_a_comment flags unsloth/optimizers/bf16_stochastic_rounding.py, which this PR does not touch. Those lines are the same on the base.
  • Core zoo (HF=default + TRL=default): test_fp16_then_bf16_matches_fresh_bf16[2-gemma4], an unsloth_zoo training-numerics test. This PR changes only the Studio frontend.
  • Frontend build + bundle sanity: both attempts hit the job's 40-minute limit. The build, the frontend tests and the typecheck passed both times. In the second attempt every browser check passed, and only the final non-blocking Biome step was cut off.

Changed during this workflow: the four commits in the change comment above. No code changed after Codex review.

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Every Auto GGUF load now fits the context again under any preset, and a typed context is still sent as typed.

@Lyxot
Lyxot merged commit 2e54c26 into unslothai:main Nov 19, 2026
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.

3 participants