Repository navigation
fix(studio): discover On Device GGUFs from disk before Hub - #12460
Conversation
… discovery The disk-only answer never carries update_available or a Hub-added drafter, so gating remote discovery on Show all quantizations hid the Update action and let a sole quant with a pending update collapse. Remote discovery now runs in the background for every On Device expander, and the sole-quant probe collapses from disk unless a reachable Hub reports an update or missing drafter for that quant.
The route checked model access before the service with no offline flag, so a managed account's local-only request still probed the Hub for public-repo proof.
…ate sizes and default The sole-quant probe commits the disk verdict at once and a later Hub answer can only withdraw it for an update or missing drafter. An update keeps the published transfer size, and a successful remote listing's default variant wins as on main.
|
Review record for #12460, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#386. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
|
You have reached your Codex usage limits for security reviews. Please try again later. |
…talled Hub cannot block downloaded models (#14134) Fixes #14038 ## Problem When Hugging Face stops responding, the chat model picker can no longer expand a downloaded GGUF on the On Device tab: the row sits on "Loading variants..." and then shows "Timed out listing quantizations. Check your connection to Hugging Face, then retry.", even though the quant is on disk. The On Device expander already asks for the disk-only listing first (#12460), and that listing alone answers in about 0.1 s. The problem is where it runs. Every GGUF variant listing, disk-only or Hub-bound, ran through `asyncio.to_thread`, i.e. the event loop's default executor. A remote listing against a Hub that accepts the connection but keeps the response trickling never hits the per-read timeout, so it holds its worker until the Hub answers. Once enough of those are in flight (one per On Device repo checked for updates, every Recommended row, every retry), the default executor is full and: - the disk-only listing of the downloaded repo queues behind them and the picker times out, and - every other `asyncio.to_thread` caller in Studio (model load, chat routes) queues too. ## Fix GGUF variant listings get their own thread pools instead of the default executor: - Hub-bound listings run on `gguf-hub-listing`, so stalled Hub calls can no longer starve the rest of Studio. - Disk-only (`offline=true`) listings run on `gguf-disk-listing`, so the On Device answer never queues behind Hub-bound work. Both pools use the default executor's sizing, context variables are carried into the worker exactly as `asyncio.to_thread` does, and the in-flight sharing of identical listings is unchanged. The same routing applies to the audio.cpp and MLX precision listings in the same module, and to the managed-account access preflights the listing runs first (route and service), which can ask the Hub for an ungranted repo. No frontend, API or UI change. ## Evidence Backend repro against a Hub endpoint that accepts and trickles one header byte every 2 s (`PYTHON_CPU_COUNT=4`, so 8 default workers), 12 concurrent remote listings in flight, then the disk-only listing the On Device expander sends for a downloaded repo: | | main | this PR | |---|---|---| | disk-only listing of the downloaded repo | no answer after 90 s | 0.03 s, `['Q8_0', 'UD-Q4_K_XL']` | | unrelated `asyncio.to_thread` call (what load / chat use) | no answer after 20 s | 0.00 s | Same result through both `/api/models/gguf-variants` and `/api/hub/gguf-variants`. New tests in `studio/backend/tests/test_gguf_listing_threads.py`: a disk-only listing answers while the default executor is saturated, a stalled Hub listing leaves the default executor free, and a stalled managed-account preflight leaves it free too. All three fail on main and pass here. They pass on ubuntu-latest, macos-15 and windows-latest (31 passed on each, with the MLX precision listing tests).
Fixes unslothai#16267. Every picker open issued one Hugging Face listing per cached GGUF repo, from the sole-quant probe unslothai#12460 added: a disk read filled the chip, then a second listing without offline=true asked the Hub whether an update or a missing companion should send the row back to its expander. With the Hub slow that is one round-trip per installed repo on the popup path, and ten of them at once took 150-215 s server-side (client timeout 30 s) in the report. The probe is gone. A sole-quant row renders the disk answer and carries the same chevron as every other On Device row, so the expander — which already merges the Hub listing and the update/companion state that comes with it — is reachable without asking the Hub to decide whether the row can be opened. Its settings move into that expander, keeping the row's one 38px gutter, as multi-quant rows do. Also moves the cached-inventory walk off the loop's default executor onto its own two-thread pool: asyncio.to_thread there queued every other to_thread caller behind a cold walk, the starvation unslothai#14038 fixed for the variant listings. Verified on a 10-repo cache against the same build: 7 disk-only variant requests and 7 Hub probes per picker open before, 7 disk-only and 0 probes after, three opens each. Expanding a row issues its disk listing plus one Hub listing, for that repo only. Tests: picker contracts updated for the removed probe and the moved gear; a new backend test pins the walk to its own pool.
…othai#16271) Fixes unslothai#16267. ## Summary With **Show all quantizations** off (the default), every picker open issued one Hugging Face listing per cached GGUF repo. The sole-quant read answered from disk, and then a second listing **without** `offline=true` asked the Hub whether an update or a missing companion should send the row back to its expander. That follow-up is the probe unslothai#12460 added in review, and it sits on the popup's critical path: on the cache in the report (10 GGUF repos) opening On Device meant 10 Hub round-trips, and when the Hub was slow the whole endpoint stack queued — `/api/models/gguf-variants` p50 155 s, max 216 s, peak 18 concurrent, with the client giving up at 30 s. A collapsed row now never asks the Hub. A sole-quant row renders the disk answer and carries the same chevron as every other On Device row, so the expander — which already merges the Hub listing and the update/companion state that comes with it — is reachable without asking the Hub to decide whether the row can be opened. ## Change **Frontend** - `pickers.tsx`: the post-commit probe, `soleQuantNeedsExpander` and its `createTaskLimiter` pool are gone. `useSoleDownloadedQuants` is disk-only. - `renderSoleQuantGgufRow` gets the expander every other On Device row has, and its inference-settings action moves into that expander (which already renders one per downloaded variant). The row keeps its single 38 px gutter — chevron plus the existing row menu — so columns do not shift between row types, and pin/delete/eject stay where they were. - `renderGgufExpandRow` is the shared expander block both row kinds now use. - `gguf-discovery.ts`: `hubWithdrawsSoleQuant` and `createTaskLimiter` are deleted; nothing else used them. **Backend** - `cache_inventory.py`: the cached-inventory walk moves off `asyncio.to_thread` (the loop's default executor) onto its own two-thread pool, with context variables carried along. One cold walk over a large cache used to queue every other `to_thread` caller behind it — the starvation unslothai#14038 fixed for the variant listings, still open for the inventory scan. Two workers cover the two inventories; the existing flight table coalesces callers of the same one. Not in this PR: the persistent variant index (item 4 in the issue). That is a storage change and deserves its own review. ## Verification Same 10-repo cache, both builds served against an unroutable `HF_ENDPOINT` (a stalled Hub), three fresh picker opens each, requests counted from the browser's resource timeline: | | disk-only variant requests | Hub listings | chevrons on sole rows | | --- | ---: | ---: | ---: | | `main` at caf0a3b | 7 | **7** | 0 | | this branch | 7 | **0** | 7 | All three opens of each build produced identical rows, so this is not a first-open effect. Every collapsed row still shows its quant chip (IQ4_XS, UD-IQ3_XXS, UD-Q4_K_XL, P2Q_0, Q8_0, Q4_K_M). Expanding a row issues that repo's disk listing plus exactly one Hub listing — for that repo only — and the expander shows the cached quant with `downloaded`, settings, pin and delete: ``` unsloth/Hy-MT2-1.8B-GGUF [disk] unsloth/Hy-MT2-1.8B-GGUF [hub] ``` Also checked online, with the real Hub reachable: opening On Device is still 7 disk reads and 0 Hub listings, and expanding still runs the full remote discovery. ## Tests - `tests/studio/test_model_picker_contracts.py` — the contract that required the probe now requires its absence, and pins the sole-quant reads to `readSoleQuant` (the only caller that passes `offline=true`). The "parent row has no gear" contract reads the shared expander call; 202 passed. - `studio/frontend/tests/picker-gguf-discovery.test.ts` — the two tests for the deleted helpers are removed; the remaining 12 pass. - `studio/frontend/tests/model-picker-partial-downloads.test.ts` — asserts the sole-quant row has no gear that spreads its `selectMeta` into a load. - `studio/backend/hub/tests/test_model_services.py` — new `test_cached_inventory_scan_keeps_off_the_default_executor` fails on `main` (asyncio's default pool names its threads `asyncio_0`) and passes here; the existing shared-scan test now stubs the new helper. - Gates: `npm run typecheck`, `npm run i18n:check:strict`, the full frontend suite (14520 pass, 1 pre-existing date-dependent failure in `halloween-trick-or-treat` that also fails on `main`), ESLint on the touched files (same 9 pre-existing errors as `main`, no new ones), and the backend files above (356 pass; the 12 failures in `test_model_services.py` also fail on `main` in this environment). Biome reports pre-existing drift across `pickers.tsx`, so I did not run `biome check --write` over it — the diff stays scoped to this change. ## Next step (not in this PR) An expander still asks the Hub for what the disk cannot know — an update, a pending companion, the published default — and loses that answer whenever the Hub is slow or down. The follow-up keeps the Hub-derived fields of the last live answer beside the cache and replays them, marked `cached`, with the update/companion actions withheld while they cannot be verified. Design and open questions are in unslothai#16267; the implementation is written and verified on `feat/on-device-hub-state-fallback`, held back until this lands so nothing upstream is a stacked duplicate. ## Maintainer update Main moved the On Device rows into memoized components (unslothai#16316), so this branch now merges main and applies the same change to `SoleQuantGgufDeviceRow`. One part of the row change was adjusted so the collapsed row looks and behaves exactly as it does on main: - A single-quant row keeps its inference settings gear and its hover menu, and clicking the row still loads the model. The CI Playwright drivers (`playwright_model_config.py`, `playwright_memory_estimate.py`) open run settings from that gear, and keyboard users reach it with Tab. - The quant expander, which carries the Hub-only state (update available, pending companion), opens from a new **Show quantizations** item in the row menu instead of a chevron. Nothing asks the Hub until it is opened. - The collapsed row still reads disk only; the post-commit Hub probe stays removed. The backend inventory pool change is unchanged. Before / after against a Hugging Face endpoint that accepts connections and never answers, three cached single-quant GGUF repos (Qwen3-0.6B, gemma-3-270m-it, SmolLM2-135M-Instruct, Q4_K_M each), base `ea69b9cf2` vs head `0caba9251`, each side its own fresh install: | | before | after | |---|---:|---:| | `gguf-variants` requests without `offline=true` when On Device opens | 3 | 0 | | requests that reached the Hub endpoint while On Device opened | 7 | 2 | | row gear present | yes | yes | | row menu | Pin, Delete | Pin, Show quantizations, Delete | | Hub listings after Show quantizations | n/a | 1 (that repo only) | Row menu on a single-quant row:  After choosing Show quantizations (before has no such item, so its list is unchanged):  --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Han <[email protected]>
Fixes #12415.
On Device GGUF discovery currently makes Hugging Face metadata or authorization requests before using a complete cached model. This also happens when the webview reports online but the backend cannot reach Hugging Face. Both the collapsed single-quant check and the expanded quant list now explicitly request the existing disk-only backend mode, independently of browser connectivity detection.
With Show all quantizations enabled, the picker publishes cached quants first and discovers remote options in the background. A stalled or failed remote request retains their cached filenames, load paths and completeness verdicts. Online discovery can still add undownloaded quantizations.
The change preserves shard, companion and manifest checks, separates strict local responses from cache-preferred responses in the frontend cache, and keeps authorization local through existing account grants and remembered public-repo proofs. A named Hub snapshot also retains cache authorization when reached through the filesystem fallback.
Related work: #12451 by Souravrajvi0. This uses explicit local-only requests for both On Device discovery paths and leaves the general cache-preference behavior intact.
Validation
a7d24c820b.The macOS evidence covers checkout backend routes and bundled frontend helpers through a WebKit request harness, with source checksums matching the fix commit. The native Tauri shell was not exercised. The reproduction confirmed unnecessary Hub requests and cache fallback, not a permanent native-app loading failure.
Review follow-ups (danielhanchen)
/api/models/gguf-variantspassesofflineinto its own access gate, so a managed account's local-only request no longer probes the Hub for public-repo proof.Before / after: On Device picker with an unreachable Hub
Both Studios ran against a local Hub endpoint that accepts connections and never answers, with an isolated cache holding one complete
unsloth/Qwen3-0.6B-GGUFQ4_K_M. Each shot is taken 2 s after the cached row appears. Before, the row has no quant yet because the sole-quant probe waits on the Hub (Q4_K_M shows about 5 s later). After, the row already carries the Q4_K_M chip from disk (about 70 ms after the row).