Skip to content

fix(studio): discover On Device GGUFs from disk before Hub - #12460

Merged
danielhanchen merged 10 commits into
unslothai:mainfrom
Imagineer99:fix/issue-12415-local-discovery
Oct 4, 2026
Merged

danielhanchen merged 10 commits into
unslothai:mainfrom
Imagineer99:fix/issue-12415-local-discovery

Conversation

@Imagineer99

@Imagineer99 Imagineer99 commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

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

  • New regressions fail before the fix and pass after it, covering a browser reporting online, cache-mode separation, snapshot authorization and managed-account remote probes.
  • Local checks: 383 backend tests passed, 1 existing test skipped; 59 frontend tests and 201 picker contracts passed. Application/test type checking and the production build passed, with no new ESLint diagnostics compared with main.
  • The backend and picker-contract suites also passed with the fix combined locally with main at a7d24c820b.
  • Fork macOS verification: Apple silicon and Intel both passed 384 backend tests and 59 frontend tests, with no skips.
  • On both macOS runners, actual frontend-generated queries to both API endpoints returned a complete cached sole quant with zero remote attempts while WebKit reported online. The actual picker helper published cached quants during a deliberate remote stall and retained their load paths after the backend transport failed.
  • Missing companions stayed non-loadable, another credential was denied even with a snapshot path, and online remote discovery remained functional. A real cached Qwen3-0.6B Q4_K_M model produced 8 tokens through local CPU inference on each runner.

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)

  • On Device rows keep the Hub-only state the disk answer cannot know: per-quant update badges, a Hub-added drafter, the companion-inclusive and update download sizes, and the repo's published default. Remote discovery runs in the background for every On Device expander, not only with Show all quantizations on.
  • A sole cached quant collapses from the disk answer at once. A later Hub answer can only send it back to the expander when it reports an update or a missing drafter. These follow-up probes are bounded to the reader's worker pool.
  • A failed disk-only read falls back to the Hub listing when the Hub is reachable (moved cache, token-only access).
  • /api/models/gguf-variants passes offline into 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-GGUF Q4_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).

On Device picker, Hub unreachable: before vs after

… 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.
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 4, 2026
@shimmyshimmer

Copy link
Copy Markdown
Member

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 6e7257d7a (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] on studio/frontend/src/features/model-picker/components/model-selector/gguf-discovery.ts (on the mirror)

@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import type { GgufVariantDetail, GgufVariantsResponse } from "@/features/chat";
+
+/** Hub-only state the disk answer cannot know: a newer revision or a companion the Hub added. */
+function withHubState<V extends GgufVariantDetail>(
+  local: V,
+  published: V | undefined,
+): V {
+  const drafter = local.pending_drafter_filename ? local : published;
+  return {
+    ...published,
+    ...local,
+    update_available: published?.update_available ?? local.update_available,
+    pending_drafter_filename: drafter?.pending_drafter_filename,
+    pending_drafter_size_bytes: drafter?.pending_drafter_size_bytes,
+  };
+}
+
+export async function loadPickerGgufVariants<T extends GgufVariantsResponse>(
+  list: (localOnly: boolean) => Promise<T>,
+  options: {
+    onDevice: boolean;
+    canDiscoverRemote: () => boolean;
+    signal?: AbortSignal;
+  },
+  onCached: (response: T) => void,
+): Promise<T> {
+  if (!options.onDevice) return list(false);
+
+  const cached = await list(true);
+  onCached(cached);
+  // Remote discovery still runs with All quantizations off: update badges come only from the Hub.
+  if (options.signal?.aborted || !options.canDiscoverRemote()) {
+    return cached;
+  }
+
+  try {
+    const remote = await list(false);
+    const variants = new Map(
+      remote.variants.map((v) => [v.quant.toLowerCase(), v]),
+    );

P2 Badge Reconcile variants by checkpoint identity

Repositories can contain multiple checkpoints with the same quant label, such as mixed diffusion families distinguished by dependency_key; keying this map only by lowercase quant drops every such remote option except the last, and cached variants subsequently overwrite one another while potentially inheriting update or drafter state from a different checkpoint. The quant-only find in readSoleQuantLocalFirst repeats the same ambiguity for collapsed rows, so both paths should match using checkpoint/family identity in addition to the quant.

Useful? React with 👍 / 👎.

Rejected on the mirror

Reply from danielhanchen:

quant is the backend's selection identity: listings path-qualify it when a repo holds several checkpoints at one quant, and the rest of the picker keys rows, pins and loads on it, so the merge matches the same identity.

Round 2: reviewed mirror b4406dfce (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] on studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx (on the mirror)

@@ -1690,6 +1696,22 @@ async function readSoleQuant(
   }
 }
 
+function soleQuantNeedsExpander(
+  target: SoleQuantTarget,
+  quant: string,
+  hfToken?: string,
+): Promise<boolean> {
+  if (isHuggingFaceOffline()) return Promise.resolve(false);

P2 Badge Retry sole-quant reconciliation after Hub recovery

When the Hub is in backoff at this moment, returning false records the cached quant under its current key as if remote reconciliation definitively found no update or missing drafter. Neither a connectivity recovery nor an unchanged inventory makes that key stale, so the probe is never retried and the row remains permanently collapsed for this picker session, hiding the expander-only update/drafter actions. Preserve an unresolved state or rerun this check when Hub availability recovers.

Useful? React with 👍 / 👎.

Rejected on the mirror

Reply from danielhanchen:

Same as main: a sole-quant row resolved while the Hub was in backoff is not re-probed on recovery there either (the probe key never tracked connectivity). Nothing is lost; the next inventory or cache change re-reads it.

Round 3: reviewed mirror 03d1142ecd (this PR's 63396ee17)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 03d1142ecd

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 03d1142ecd (this PR's 63396ee17).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

@danielhanchen
danielhanchen marked this pull request as ready for review October 4, 2026 13:13
@danielhanchen
danielhanchen self-requested a review as a code owner October 4, 2026 13:13
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@danielhanchen
danielhanchen merged commit e4e875b into unslothai:main Oct 4, 2026
danielhanchen added a commit that referenced this pull request Oct 18, 2026
…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).
yannickloth added a commit to yannickloth/unsloth that referenced this pull request Oct 31, 2026
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.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 1, 2026
…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:

![On Device row menu, before vs
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/16271/pr16271_on_device_01-762fe44d5b86.png)

After choosing Show quantizations (before has no such item, so its list
is unchanged):

![On Device quant expander opened from the row
menu](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/16271/pr16271_on_device_02-00736739c0e0.png)

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Desktop: Hugging Face quant discovery blocks loading On Device models offline

3 participants