Skip to content

Studio model picker: On Device rows re-render only when their own data changes - #16316

Merged
danielhanchen merged 8 commits into
mainfrom
perf/r16-frontend-model-picker
Nov 1, 2026
Merged

danielhanchen merged 8 commits into
mainfrom
perf/r16-frontend-model-picker

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

What changes

The chat model picker's On Device tab rendered every row inline from the picker, so each render rebuilt every row's handlers, tooltip and menu. With a few hundred models on disk that made each search keystroke re-render every row (with ~2,900 tooltip subtrees), and while the tab settled each /api/hub/gguf-variants answer re-rendered all of them again.

  • The cached safetensors rows, the sole-quant GGUF rows, the multi-quant GGUF rows (with their quant expander) and the custom folder / LM Studio / models-directory rows are now memo components (DownloadedModelDeviceRow, SoleQuantGgufDeviceRow, DownloadedGgufDeviceRow, LocalModelDeviceRow). They take only per-row data: the repo or model object, selected / loaded / pinned / expanded flags, the option id and active flag.
  • What the rows call back into (select, configure, pin, delete, expand, reveal vision, footprint, focus moves) sits in one per-picker holder. The picker refills it in useLayoutEffect after each commit, and rows read it only from event handlers. Nothing is written during render. This is the same pattern as the Images / Video strip change.
  • useRovingModelList also exposes its focus and key handlers through such a holder, plus getOptionId, so a memoized row builds the same option props (id, tabIndex, data-model-picker-active-option, aria-current, arrow / Home / End handling) from data. getOptionProps is unchanged for the other rows and shares the key handling.
  • loadedQuantsFor returns one shared empty list when nothing is loaded, so a row with no loaded quant keeps equal props.
  • The three local sections render through one renderLocalDeviceRow. Each section keeps its own option-key prefix and its own rule for a direct GGUF file (custom folders still count Ollama manifests as direct).

No markup, copy, styling or behaviour changes. The diff to pickers.tsx is mostly the row JSX moving into the components.

The quant expander under the memoized On Device GGUF rows gets the page's resolveDownloadFootprint as is, so when the Images or Video page rebuilds it (text encoder, VAE, memory mode, transformer quant or GPU changed), the expander refetches the extra download sizes exactly as before. tests/model-picker-device-footprint-identity.test.ts guards that.

Results

Production build, headless Chromium, 4x CPU throttle, mocked API (300 local models, 150 cached GGUF repos with one quant each, 150 cached safetensors repos, so 600 rows). Six interleaved base / head runs. Base spread is the A/A noise.

Metric Base median [range] Head median [range]
Search keystroke to next paint ("model-01", median per run) 1177 ms [1065-1282] 66 ms [50-76]
Longest task while typing 1384 ms [1175-1566] 568 ms [480-792]
Long-task total while typing 9820 ms [9005-10455] 707 ms [480-992]
On Device: first rows painted 6110 ms [5760-6504] 3221 ms [2891-3524]
On Device: last commit (all 300 probes settled) 32.8 s [31.9-33.3] 6.4 s [5.3-7.6]
On Device: long-task total while settling 31.3 s [30.3-31.8] 3.1 s [2.5-3.4]
Tooltip re-renders while settling 44,582 ~2,130
Tooltip re-renders while typing 14,376 301

The longest single task on opening the tab (the first mount of 600 rows) is unchanged within noise: 2366 ms [2274-2668] on base, 2514 ms [2254-2840] on head.

Render counts from the new check (dev build, deterministic across runs):

Base Head
ModelRow re-renders while the tab settles 19,350 750
ModelRow re-renders while typing "model-01" 5,000 100

Tests

  • New tests/studio/playwright_model_picker_renders.py, wired into studio-frontend-ci.yml (path filters plus a step on port 5237). It has a warm-up pass and loose bounds: 3000 for the settle (head 750) and 1500 for typing (head 100). It fails on base (19,350 / 5,000) and passed 5/5 on head. It also checks that the rows still work: ArrowDown / ArrowUp move focus and the active marker, and a row menu opens.
  • Parity, base vs head, in 20 states: open, On Device settled, five queries (including one with no matches), arrows, End, Home + ArrowUp, row menu open and closed, settings button tooltip, row tooltip, pick a GGUF quant, reopen, switch to Recommended and back, local search, pick a local model. outerHTML, innerText, the ARIA snapshot, the focused element, the active option and every non-GET request are identical in all 20 states. Screenshot pixel differences between base and head (119-149 px) are within base-vs-base and head-vs-head noise (0-144 px).
  • npm test: 14523 pass, 0 fail, the same as base. Source-text guards that pointed at the old inline render functions now point at the row components. Their assertions are unchanged, and the pin-scope fixture provides the actions holder.
  • npm run typecheck and npm run build pass. eslint and biome report the same findings as base on pickers.tsx. On the touched tests the only new findings are more of the existing inline-regex useTopLevelRegex notes.

Not covered

  • The Recommended / Hub search rows, loaded rows, pinned quant rows, connected-provider rows, NPU rows and the additional On Device rows still render inline. Hub search results come from the network, so those keystrokes are not dominated by local rows. They can move to the same components later.
  • The first mount of a long On Device list still takes one long task. There is no virtualization in the picker, and this change does not add any.
  • Timings are from headless Chromium on Linux only. No Firefox / WebKit, real hardware, Windows or macOS runs. The touch tooltip path was not exercised. Delete, update and reveal menu actions were checked by unit fixture and menu open only, not end to end against a backend.

…a changes

Search keystrokes and each quant probe answer re-rendered every row of the
On Device tab (with its tooltips and menus). The cached, sole-quant, multi-quant
and local folder rows are now memoized components that take per-row data, and
reach the picker's callbacks through one holder refilled after each commit and
read only from event handlers. The roving list exposes stable focus and key
handlers the same way.

Adds a Playwright render-count check for search typing and probe settling.
…e quant lists as is

The Images and Video pages rebuild the resolver when the text encoder, VAE, memory mode or GPU
change, and the quant list refetches companion sizes when its identity changes. A stable
forwarder hid that change, so On Device quant rows kept sizes from the old settings.
@danielhanchen

Copy link
Copy Markdown
Member Author

Frontend build + bundle sanity fails in this PR's new tests/studio/playwright_model_picker_renders.py:

AssertionError: only 120 GGUF rows show their sole quant

The run's own measurements were {"rows": 600, "variant_probes": 300, ..., "quant_chips": 120}. The probes all landed (300, against the 150 required) and all 600 rows rendered, but only 120 Q4_K_M matches turned up in document.body.innerText, against CACHED = 150. Two causes would fit:

  • 30 cached GGUF rows really do not show their chip after the reload and settle.
  • The count misses chips that are in the DOM. innerText skips text that is not rendered, such as display: none, content-visibility, or collapsed or clipped sections, so it changes with layout and viewport.

Counting the chip elements directly, for example a data- attribute on the quant chip queried with querySelectorAll, would tell the two apart and remove the layout dependence. The same job passes on the other open PRs, so this comes from the new test or the pickers.tsx change rather than from main.

@danielhanchen danielhanchen self-assigned this Nov 1, 2026
@danielhanchen
danielhanchen marked this pull request as ready for review November 1, 2026 09:31
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T08:56:58.896486Z 89127aa 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

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: cd6e4d7267

ℹ️ 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 c802f93 into main Nov 1, 2026
@danielhanchen
danielhanchen deleted the perf/r16-frontend-model-picker branch November 1, 2026 09:49
@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. Hooray!

Reviewed commit: 89127aa654

ℹ️ 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 added a commit to yannickloth/unsloth that referenced this pull request Nov 1, 2026
Main moved the On Device rows into memo components (unslothai#16316). The sole-quant row
component keeps its gear and menu, drops the Hub follow-up probe, and opens the
shared quant expander from a Show quantizations item in its menu.

[skip ci]
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant