Repository navigation
Studio model picker: On Device rows re-render only when their own data changes - #16316
Conversation
…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.
…in the picker contracts [skip ci]
|
The run's own measurements were
Counting the chip elements directly, for example a |
… the model picker check
|
@codex review |
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. |
|
@codex review |
|
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". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
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]
…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]>
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-variantsanswer re-rendered all of them again.memocomponents (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.useLayoutEffectafter 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.useRovingModelListalso exposes its focus and key handlers through such a holder, plusgetOptionId, so a memoized row builds the same option props (id,tabIndex,data-model-picker-active-option,aria-current, arrow / Home / End handling) from data.getOptionPropsis unchanged for the other rows and shares the key handling.loadedQuantsForreturns one shared empty list when nothing is loaded, so a row with no loaded quant keeps equal props.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.tsxis mostly the row JSX moving into the components.The quant expander under the memoized On Device GGUF rows gets the page's
resolveDownloadFootprintas 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.tsguards 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.
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):
ModelRowre-renders while the tab settlesModelRowre-renders while typing "model-01"Tests
tests/studio/playwright_model_picker_renders.py, wired intostudio-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.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 typecheckandnpm run buildpass. eslint and biome report the same findings as base onpickers.tsx. On the touched tests the only new findings are more of the existing inline-regexuseTopLevelRegexnotes.Not covered