Repository navigation
Studio: load a repo id from its scan-folder copy instead of re-downloading it - #13034
Conversation
…of downloading it
… remote path The local resolver index also covers the active Hugging Face cache, so the scan-folder rewrite fired for every ordinary cached repo-id load and swapped its identity for a snapshot path. Rewrite only when the hit lives outside the active hub cache, and cover source precedence with real-index tests instead of a mocked resolver.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
The chat flow calls /validate before /load. Offline, validate probed the repo id remotely and refused it as not cached, so the load never ran even though the weights were in a registered scan folder. Apply the same rewrite in validate.
…e active hub cache Take the local copy only when its snapshot path maps back to the requested repo id, so status, unload and the remote-code consent scan keep one identity; LM Studio style dirs and non-GGUF checkpoints keep the existing remote path. Compare the copy's repo directory with the active hub cache directly, so a scan folder nested inside the cache is still loaded from disk.
…he requested repo id API key and managed callers may not read the owner's copies (same rule as the cached weights path), so they keep the repo id and its Hub check. A rewritten load reports the repo id it was asked for in LoadResponse.model, which the chat UI stores as the checkpoint. Guard tests now use pytest.fail so the helper's broad except cannot hide a consulted resolver.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2cf0df9ed6
ℹ️ 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".
| wanted = f"{identifier}:{request.gguf_variant}" if request.gguf_variant else identifier | ||
| try: | ||
| resolved = resolve_local_gguf(wanted) |
There was a problem hiding this comment.
Search later local copies for the requested quant
When the active Hub cache already contains this repo but lacks the explicitly requested quant, while a registered scan folder contains that quant, resolve_local_gguf(wanted) cannot find the scan-folder copy. _build_index() processes the active cache before custom scan folders and uses setdefault, so only the active cache's entry is retained for the repo ID; resolving repo:Q8_0 therefore returns None if that entry only has Q4, even when the later scan-folder entry has Q8. The request remains a repo ID and downloads Q8 again (or fails offline), defeating this change for mixed-cache repositories; the lookup needs to consider all matching local entries before falling back to the Hub.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: that case falls back to today's behaviour (the quant is fetched as before), and it is listed under known limitations. This PR only removes the duplicate download where no hub copy serves the repo.
| if resolved is None: | ||
| return request | ||
| load_path, variant = str(resolved[0]), resolved[1] | ||
| # GGUF snapshots of this very repo only: their path maps back to the repo id for status, | ||
| # unload and consent, which an LM Studio dir or a non-GGUF checkpoint would not. | ||
| if not variant or (hf_cache_repo_id(load_path) or "").lower() != identifier.lower(): |
There was a problem hiding this comment.
Verify cached resolver hits still exist before rewriting
resolve_local_gguf() can return its index unchanged for _CACHE_TTL_S (currently five seconds), but this code only validates the path lexically with hf_cache_repo_id; it never checks that the selected snapshot and quant are still readable. If a scan-folder model is deleted, moved, or its drive is unmounted after the index was built, a normal repo-ID load during that window is rewritten to the stale local path and ModelConfig.from_identifier() fails instead of falling back to the Hub. Confirm that the resolved variant still exists—or invalidate/retry the index—before replacing the otherwise valid remote identifier.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: it needs the scan folder removed inside the 5 s index TTL between two loads; the load then reports the missing path, the same as any local load whose folder disappears.
…a scan-folder load Bundled templates (gemma-4 preserve_thinking) are keyed by repo id, so a copy loaded from its snapshot path launched with the GGUF's embedded template instead.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cad4b443d0
ℹ️ 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".
| else scan_folder_public_id or public_model_identifier, | ||
| display_name = model_log_label if native_grant_backed else config.display_name, |
There was a problem hiding this comment.
Preserve the repo display name after rewriting
For a newly loaded scan-folder copy, model is restored to the requested repo ID, but display_name still comes from the local ModelConfig. Because the rewritten identifier is a snapshot directory such as .../snapshots/abc, ModelConfig derives the display name as abc; frontend paths that add a missing model use this response field directly, so a manually entered repo or otherwise absent catalog row appears under its snapshot hash instead of its model name. Derive the display name from scan_folder_public_id (and the selected variant) when this rewrite occurred.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not reproduced: a real rewritten GGUF load answers display_name from the GGUF file (Qwen3-0.6B-Q4_K_M for unsloth/Qwen3-0.6B-GGUF in the before/after run), not the snapshot hash.
| request = await asyncio.to_thread( | ||
| _as_local_scan_folder_request, request, _owner_session(fastapi_request) | ||
| ) |
There was a problem hiding this comment.
Check the llama runtime before treating the repo as local
When a scan-folder GGUF is selected on an installation without llama-server, this rewrite makes ModelConfig.from_identifier() take its local-path branch, which omits the runtime preflight performed for remote and refused-cache repo IDs. As a result /validate can succeed and /load can pass all rejection checks, unload a currently resident Transformers or NPU model, and only then raise LlamaServerNotFoundError from the backend launch. Preserve the repo path's runtime preflight—or add an equivalent check before teardown—for rewritten requests.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this: a rewritten request is an ordinary local GGUF path load, which already runs this way for every picker row loaded by path; it only differs on an install whose llama.cpp binary is missing.
A scan-folder copy of a gemma-4 GGUF runs from its snapshot path, so /status recomputed no bundled template and reported the bundled one as the user's override.
A client reloads a scan-folder copy by the snapshot path that /status publishes, which skipped the bundled gemma-4 template. Read an HF cache snapshot path as its repo id in the template matcher instead of patching each caller; other local paths still never match.
The repo-name segment check read the snapshot revision when a copy loads from its snapshot dir, so the high effort tier was dropped.
|
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". |
|
Thanks @danielhanchen for taking this over (my #12254) and keeping the commit Follow-up for the two remaining cases in this family — the |
… claim A quant pin resolves to the row holding that quant (alternates beside the cache-first key, per the unslothai#13034 chosen-artifact ordering), /v1/models advertises the row a bare id loads, and only a row with weights claims a repo id.
Fixes #12253. Takes over #12254 (thanks @VTplus, your commit is kept as is with authorship) and adds a guard so ordinary Hugging Face cache loads are not affected.
Problem
POST /api/inference/loadwith a repo id such asunsloth/Devstral-Small-2-24B-Instruct-2512-GGUFonly checks the active Hugging Face hub cache. If the complete repo lives in a registered scan folder (Hub, On Device), Studio does not look there and starts a full download into the hub cache, a byte-identical duplicate of weights already on disk. In the report this was a 16.8 GB download that stalled the load for over 25 minutes.Fix
_as_local_scan_folder_request(from Studio: resolve a repo-id load to the local scan-folder copy instead of downloading it #12254) runs right after the Ollama manifest rewrite in_load_model_impl. It asks the same local index the OpenAI auto-switch path uses (resolve_local_gguf). On a hit, the request is rewritten to the local path and quant; on a miss, nothing changes.New in this PR: that index also covers the active hub cache, and it is consulted before scan folders. Without a guard, every normal repo-id load of an already cached model was rewritten from
org/nameto its snapshot path, which changes the loaded model identity for the most common load path. The rewrite is now skipped when the hit lives inside the active hub cache, since the existing remote path already reuses that copy without downloading. Only copies the hub path cannot serve are rewritten, and only when the hit is a GGUF snapshot (models--org--name/snapshots/<rev>) of the requested repo, so its path maps back to the sameorg/namefor status,/v1ids, unload and the remote-code consent scan. LM Studio style folders and non-GGUF checkpoints keep the existing remote path.The same rewrite runs in
POST /api/inference/validate. The chat flow validates before it loads, and without Hub access validate probed the repo id remotely and refused it as not cached, so/loadwas never sent. The validate response the frontend reads (flags such asis_lora) is unaffected;/loadstill receives the picked repo id.The rewrite runs only for the owner's own Studio session, the same rule the cached weights path uses (
_refused_repo_cached_gguf): API key and managed account callers keep the repo id and its Hub access check. A rewritten load answers with the requested repo id inLoadResponse.model, which the chat UI keeps as the selected checkpoint; the snapshot path is only used to load.The bundled chat template matcher reads an HF cache snapshot path (
models--org--name/snapshots/<rev>) as its repo id, so a scan-folder copy, a reload by the path/statuspublishes, and a cache row pinned to its snapshot all get the same bundled template (gemma-4preserve_thinking) as loadingorg/name. Other local paths still never match.Unchanged: bare names, absolute paths, Ollama refs, API key and managed account callers, native path leases, resolver errors, and a pinned quant the local copy does not hold (that one still goes remote rather than loading different weights). The rewrite is idempotent: a rewritten request carries a path, which the helper skips.
Behavior
The table was produced against a real resolver index (temporary hub cache plus a registered scan folder, no resolver mocks), base
mainvs this branch.Tests
studio/backend/tests/test_load_scan_folder_resolution.py: the 9 helper tests from #12254 plus real-index tests (validate offline, a scan folder nested inside the hub cache, scan-folder only copy with and without a pinned quant, active hub cache copy with and without a scan-folder duplicate, weightless hub skeleton). The hub-cache tests fail without the guard and the validate test fails without the validate rewrite; all pass with them.Before and after in Studio
Two fresh Studio installs (base
mainand this branch), Hub offline, empty hub cache, and a registered scan folder holding a Hugging Face layout copy ofunsloth/Qwen3-0.6B-GGUF(Q4_K_M). Both sides sendPOST /api/inference/loadforunsloth/Qwen3-0.6B-GGUF, then open the chat page.400 Bad RequestloadedLoadResponse.modelunsloth/Qwen3-0.6B-GGUF/api/inference/status)unsloth/Qwen3-0.6B-GGUFKnown limitations