Skip to content

Studio: keep the last used model when its auto-load fails, and say why another model loaded - #18106

Merged
danielhanchen merged 4 commits into
mainfrom
studio-autoload-keep-last-used
Nov 17, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
studio-autoload-keep-last-used

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Fixes #18002

When you press Send with no model loaded, Studio auto-loads your last used model first. If that load fails, for example because llama-server cannot start it, the remaining models on disk are tried smallest first. Today that fallback is silent: the toast just says Loaded <small model>, and the fallback also replaces the remembered model. The next Send then loads the small model again, which looks like Studio forgot the model you use. This is the "forcing a small Gemma E2B model" part of the report.

This PR keeps the fallback, so the message still gets an answer, and changes two things:

  • The fallback's success toast becomes a warning that starts with Your last used model <id> (<quant>) did not load: <reason>.
  • A fallback load (a cached model, or the default download) no longer overwrites the remembered model, so the next Send tries your model again.

Nothing changes when the last used model loads, when there is no remembered model, or when the remembered quant is gone from disk (then the next quant still loads and is remembered, as before).

The logic is unchanged in v0.1.917-beta, v0.1.918-beta and main, so this is not a 918 regression. 918 is where the reporter's remembered load started failing.

Tests:

  • studio/frontend/tests/auto-load-remembered-fallback.test.ts: note wording, warning severity, case-insensitive quant match, and that every auto-load record site is gated (fails on main).
  • tests/studio/test_chat_autoload_failure_gate.py runs the real auto-load cascade in node: a failed last used model is tried first, the fallback warns and records nothing (fails on main); controls show a healthy last used model and a fallback with nothing remembered are recorded as before. The 21 chat test files in tests/studio: 715 passed (main 712).
  • npm test (16476 tests) and scripts/typecheck.mjs pass.
  • The note keeps only the failure summary, not the llama-server log tail the backend appends.

Checked on two GGUF-only CPU Studios (merge base c0ef23bceb vs this branch, separate homes and HF caches). Qwen3-0.6B Q4_K_M was loaded through the picker so it became the last used model, then unloaded, its GGUF header corrupted, then New chat + Send:

main this PR
Last toast Loaded unsloth/SmolLM2-135M-Instruct-GGUF (Q4_K_M) (success) warning Loaded unsloth/SmolLM2-135M-Instruct-GGUF (Q4_K_M): Your last used model unsloth/Qwen3-0.6B-GGUF (Q4_K_M) did not load: Failed to load model: llama-server failed to start. ...
Remembered model after unsloth/SmolLM2-135M-Instruct-GGUF unsloth/Qwen3-0.6B-GGUF (Q4_K_M)
Server log load 500, load 200, PUT last-local-model 200 load 500, load 200, no PUT

With the Qwen file restored, the next Send on this branch shows Loading last used model… unsloth/Qwen3-0.6B-GGUF (Q4_K_M) and loads it.

Auto-load fallback toast, before and after
Remembered model's GGUF corrupted, then Send with nothing loaded. Before: plain success for the stand-in. After: a warning that names the last used model and why it did not load.

@danielhanchen danielhanchen self-assigned this Nov 17, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 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-17T09:55:31.818946Z 26be656 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 91da180e35

ℹ️ 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 pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 17, 2026
danielhanchen added a commit that referenced this pull request Nov 17, 2026
…ne as benign (red since #18103) (#18114)

`tests/studio/test_backend_ci_parallel_isolation.py::test_every_tight_elapsed_bound_is_isolated`
fails on main (workflow-trigger lint, "Workflow guard suites"), seen on
the staging runs of #18077 and #18106:

```
E   assert not {'test_anthropic_admission.py': ['test_anthropic_admission.py:239 one duration against another']}
```

## Cause

#18103 replaced the fixed 0.1 s sleeps in `test_anthropic_admission.py`
with `_until_queued`, which polls the admission queue with `assert
loop.time() < deadline` as a 5 s timeout. The lint flags any clock
comparison in a backend test that runs under `-n 4` until a human
records it. This one is a poll deadline: descheduling only delays the
poll and cannot make the condition false, which is exactly the case
`BENIGN_TIMING` is for. #18103 should have recorded it; this does.

## Fix

Add `("test_anthropic_admission.py", "_until_queued")` to
`BENIGN_TIMING` with a one-line reason, next to the other poll
deadlines.

## Verification

- main: `test_every_tight_elapsed_bound_is_isolated` fails with the CI
message.
- this branch: `tests/studio/test_backend_ci_parallel_isolation.py` 43
passed.
danielhanchen added a commit that referenced this pull request Nov 17, 2026
…re (intermittent Broken pipe) (#18115)

`tests/test_tp_host_input_embedding_gloo.py::test_tp_narrower_than_world_keeps_the_embedding`
(added in #18068) fails intermittently in the `Repo tests (CPU,
gloo-tp-env)` shard, seen on the staging run of #18106 (a frontend-only
PR):

```
[rank1] TCPStore.cpp:106 sendBytes failed ...: Broken pipe
  File "tests/test_tp_host_input_embedding_gloo.py", line 107, in _case_world_wider_than_tp
    mesh = init_device_mesh("cpu", (world, 1), mesh_dim_names = ("dp", "tp"))
torch.distributed.DistNetworkError: Broken pipe
E   AssertionError: rank exit codes [0, 1]
```

## Cause

In the `dp_x_tp` case each rank builds a `(world, 1)` mesh, so its `tp`
group has one member and rank 0 never waits for rank 1. Rank 0 hosts the
TCPStore, finishes, destroys its process group and exits. If rank 1 is
still creating its mesh groups through that store, its next store write
hits a closed socket. The TP code is fine; the test worker let rank 0
leave first.

## Fix

The worker calls `dist.barrier()` after a case has saved its result,
before `destroy_process_group()`, so no rank tears the store down while
another still uses it. On a failure path nothing changes.

## Verification

- Rank 1 delayed by 3 s before `init_device_mesh` (local only, not
committed):
  - main: `rank exit codes [0, 1]` with the same `Broken pipe` as CI.
  - this branch: passes.
- Whole file: 5 passed.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 26be656974

ℹ️ 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
danielhanchen merged commit ff10fa7 into main Nov 17, 2026
@danielhanchen
danielhanchen deleted the studio-autoload-keep-last-used branch November 17, 2026 12:40
danielhanchen added a commit to debojyoti-dev/unsloth that referenced this pull request Nov 18, 2026
… keep the hf_cache repo id match

[skip ci]
danielhanchen added a commit that referenced this pull request Nov 18, 2026
… its HF cache path (#18104)

Follow-up to #18106 for #18002.

## What was wrong

When you press Send with no model loaded, Studio auto-loads your last
used model first. #18106 made a failed load of that model show a warning
and keep it remembered. One case still slipped past it: when the managed
cache listings fail, the cascade falls back to `/api/models/local`, and
there a model in another Hugging Face cache (for example the default
`~/.cache/huggingface` next to a custom Studio cache) is listed by its
snapshot path. The remembered repo id did not match that row, so the
model was not tried first, the smallest model on disk loaded with a
plain success toast, and its snapshot path replaced the remembered
model. That is the original #18002 symptom again. The toasts also named
both models by their full snapshot path.

## What changed

- `AutoLoadSource` carries the Hub repo id (`model_id`) of `hf_cache`
rows. A row matching the remembered model by id or load id still ranks
first; a snapshot matching it only by repo id ranks right after, ahead
of every other model. Rows from other sources (models folder, LM Studio,
...) match on their own id or load id only.
- Auto-load toasts name such a snapshot by its repo id (`Loaded
unsloth/SmolLM2-135M-Instruct-GGUF (Q4_K_M)`) instead of its snapshot
path.
- The first version of this PR also stopped the cascade after the last
used model failed. That is superseded by #18106 (fallback with a
warning) and conflicted with it, so it is removed.

## Testing

- `tests/studio/test_chat_autoload_failure_gate.py` runs the real
auto-load cascade:
-
`test_a_failed_last_used_model_in_another_cache_is_still_named_and_kept`:
cached listings down, two other-cache snapshots, the last used 26B fails
to load. main loads only `gemma-4-E2B-it-GGUF` (the 26B is never tried);
this PR tries the 26B, falls back to E2B with `Your last used model
unsloth/gemma-4-26B-A4B-it-GGUF (UD-Q4_K_XL) did not load: ...`, and
records nothing.
- `test_an_exact_last_used_row_outranks_a_snapshot_matched_by_repo_id`:
the remembered `Q8_0` row still loads ahead of a smaller snapshot of the
same repo that only has `Q4_K_M`.
  - The whole file passes (91 tests).
- `studio/frontend/tests/auto-load-target-key.test.ts` ranking check
fails on main and passes here; all `auto-load-*`,
`last-local-model-load` and `queued-model-lifecycle` tests pass (55),
`scripts/typecheck.mjs` is clean, biome reports the same findings as
main.
- Two real Studios (merge base vs this PR), CPU, GGUF only:
`unsloth/SmolLM2-135M-Instruct-GGUF` and `unsloth/Qwen3-0.6B-GGUF` in a
non-active HF cache, Qwen's GGUF header corrupted, last used model set
to `unsloth/Qwen3-0.6B-GGUF` (Q4_K_M), the two managed listing requests
failed in the browser, then New chat + Send:

| | merge base | this PR |
|---|---|---|
| `/api/inference/load` | SmolLM2 only | Qwen3-0.6B, then SmolLM2 |
| Toast | success, snapshot path | warning: `Loaded
unsloth/SmolLM2-135M-Instruct-GGUF (Q4_K_M)` + `Your last used model
unsloth/Qwen3-0.6B-GGUF (Q4_K_M) did not load: ...` |
| Last used model after | SmolLM2 snapshot path |
`unsloth/Qwen3-0.6B-GGUF` |

![Auto-load toast, before and
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/18104/pr18104_toast_before_after-5a6fb8e5a64c.png)
*Last used model in another HF cache with a corrupted GGUF and the
managed listings failing, then Send with nothing loaded. Before: plain
success for the stand-in, named by its snapshot path, and the stand-in
becomes the last used model. After: a warning naming the last used model
and why it did not load; it stays remembered.*

---------

Co-authored-by: Daniel Han <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Unsloth v0.1.918 Beta has model loading issues immediately after update and is sluggish

1 participant