Skip to content

Studio: still try the last used model first when it is only listed by its HF cache path - #18104

Merged
danielhanchen merged 11 commits into
unslothai:mainfrom
debojyoti-dev:fix/remembered-model-load-failure-18002
Nov 18, 2026
Merged

danielhanchen merged 11 commits into
unslothai:mainfrom
debojyoti-dev:fix/remembered-model-load-failure-18002

Conversation

@debojyoti-dev

@debojyoti-dev debojyoti-dev commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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 Studio: keep the last used model when its auto-load fails, and say why another model loaded #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
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.

…g another (fixes unslothai#18002)

When a send auto-loads a model and the remembered one fails, stop and
show its error rather than falling through to the smallest model on disk.
Also match the remembered repo id against Hugging Face cache rows from
/api/models/local, which are named by their snapshot path.
@danielhanchen danielhanchen changed the title Studio: report a failed load of the last used model instead of loading another Studio: still try the last used model first when it is only listed by its HF cache path Nov 18, 2026
@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-18T13:08:01.934971Z c1bec5f 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 02a4d45086

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

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit that referenced this pull request Nov 18, 2026
## Gate the split-GPU DPO prefix-share test on a real CUDA device


`tests/python/test_accelerator_skip_guards.py::test_no_skip_guard_reads_a_spoofable_accelerator_probe`
fails on `main` since #18273. It shows up on unrelated PRs, for example
#18104's `Repo tests (CPU, studio)`:

```
these skip guards read a probe tests/_zoo_aggressive_cuda_spoof.py patches to True process-wide ...
    test_dpo_prefix_share.py:490: torch.cuda.is_available()
```

### Cause

#18273 added `test_verify_with_hidden_states_on_another_device`, a
CUDA-only test, behind `@pytest.mark.skipif(not
torch.cuda.is_available(), ...)`.

`tests/_zoo_aggressive_cuda_spoof.py` patches that probe to `True`
process-wide. As a result, the test un-skips on a CPU-only runner
whenever it shares a pytest session with `tests/version_compat` or
`tests/vllm_compat`.

### Fix

The guard now uses `has_real_cuda()` from
`tests/_shared/real_accelerator.py`, the same helper the other CUDA-only
tests use (#18204, #18224). The test body is unchanged, so on a real GPU
it runs exactly as before.

### Verification

- `tests/python/test_accelerator_skip_guards.py`: fails on `main` on
this line, passes with this change.
- `tests/test_dpo_prefix_share.py`: passes on CPU, and the CUDA-only
case still skips. 58 passed, 1 skipped across both files.
- ruff is clean.
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 18, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit that referenced this pull request Nov 18, 2026
## Read the NPU compat fixtures as UTF-8


`tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding`
fails on `main` since #18050. It shows up on unrelated PRs as `Repo
tests (CPU, rest-2)`, for example #18104 and #17627:

```
E   AssertionError: 1 file reads in the test trees touch a checked-in file with the platform default encoding ...
E     Left contains one more item: 'studio/backend/tests/test_npu_compat.py:18: read_text()'
```

### Cause

#18050 added two reads of the checked-in fixture
`fixtures/npu_compat/hf_configs.json` that call `.read_text()` with no
encoding:

- `studio/backend/tests/test_npu_compat.py:18`
- `studio/backend/tests/test_export_npu_q4nx.py:677`

Without an encoding, Python decodes with the platform default, which is
the ANSI codepage on Windows. The lint fails that as soon as a fixture
gains a non-ASCII byte.

### Fix

Both reads now pass `encoding = "utf-8"`. The fixture is JSON, so it is
UTF-8 by definition. Nothing else changes.

The other bare `.read_text()` in `test_npu_compat.py`, at line 88, reads
a file the test itself wrote into `tmp_path`. The lint deliberately
leaves those alone, so it is unchanged.

### Verification

- `tests/test_source_read_encoding.py`: fails on `main` on both lines
and passes with this change (16 passed).
- `tests/test_npu_compat.py` and `tests/test_export_npu_q4nx.py`: 96
passed.
- ruff is clean.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 18, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 18, 2026

@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: dcbdcacdb1

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

isSkipped: (candidate: AutoLoadCandidate) => boolean,
): Promise<AutoLoadCandidate | null> {
// Like a cached repo row: the repo id keys saved settings and the record, the snapshot path loads.
const id = source.repoId ?? source.id;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve path-keyed settings when canonicalizing cache snapshots

When a user has selected an inactive-cache GGUF through the local picker and the managed cache listings are unavailable, the last-used ID and saved configuration can both be the snapshot path (toLocalModelInfo exposes row.loadId as id). This substitution changes candidate.id to the repo ID even for an exact remembered-path match, so loadAutoLoadCandidate calls resolveInitialConfig with a different key and silently uses defaults or repo-keyed settings instead. The saved context and GPU-layer settings are consequently dropped, potentially preventing a previously working model from loading. Preserve the path-keyed configuration or adopt it before replacing the candidate identity.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in c1bec5f: the candidate id is the repo id only when the snapshot matched the last used model by repo id alone; a snapshot remembered by its own path keeps its path-keyed settings and record (test_a_snapshot_remembered_by_its_path_keeps_its_path_keyed_settings, fails on the previous head). The repo id stays a display label only.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: c1bec5fdb0

ℹ️ 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 1d930ce into unslothai:main Nov 18, 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.

2 participants