Repository navigation
Add a fits-on-device filter to the model selects - #6802
Conversation
The chat model selector gains an Only show models that fit on this device tick under its filter row, and the Hub page gains a matching Fits device pill next to the sort menu. Both read one persisted preference (unsloth_models_fit_on_device_only), so toggling either applies to both. The filter reuses the Recommended sort's existing fit math, extracted into hfModelFitsDevice: size from safetensors metadata, GGUF param count, or the repo name, against the 0.7 GPU + 0.7 RAM budget, with unsizable models hidden. In the chat selector it extends the fit filtering to the Trending and Recent sorts and to search results; downloaded models stay visible regardless. An unknown device budget keeps everything. The preference is cleared by Reset all local preferences like the other picker toggles.
There was a problem hiding this comment.
Code Review
This pull request introduces a shared "Fits on device" filter option across the model selector and the Hub page, allowing users to hide models that exceed their device's memory budget. The changes include adding the fitOnDeviceOnly state to the chat runtime store, creating a shared hfModelFitsDevice helper function, and updating the UI components to support toggling this filter. The review feedback suggests wrapping the new checkbox label in a custom Tooltip component instead of using a native title attribute for better consistency and accessibility, and adding a defensive check for the gpu object in hfModelFitsDevice to prevent potential runtime errors.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| {showConnected ? null : ( | ||
| <label | ||
| className="flex w-fit cursor-pointer select-none items-center gap-1.5 px-1 text-xs text-muted-foreground hover:text-foreground" | ||
| title="Hides models larger than this device's memory budget. Downloaded models stay visible." | ||
| > | ||
| <Checkbox | ||
| checked={fitOnDeviceOnly} | ||
| onCheckedChange={(v) => setFitOnDeviceOnly(v === true)} | ||
| className="size-3.5" | ||
| aria-label="Only show models that fit on this device" | ||
| /> | ||
| Only show models that fit on this device | ||
| </label> | ||
| )} |
There was a problem hiding this comment.
Using a native title attribute on the <label> is inconsistent with the rest of the application, which uses the custom Tooltip component. It is also less accessible for keyboard-only and mobile users. Wrapping the label in a Tooltip component maintains consistency and improves accessibility.
{showConnected ? null : (
<Tooltip>
<TooltipTrigger asChild>
<label
className="flex w-fit cursor-pointer select-none items-center gap-1.5 px-1 text-xs text-muted-foreground hover:text-foreground"
>
<Checkbox
checked={fitOnDeviceOnly}
onCheckedChange={(v) => setFitOnDeviceOnly(v === true)}
className="size-3.5"
aria-label="Only show models that fit on this device"
/>
Only show models that fit on this device
</label>
</TooltipTrigger>
<TooltipContent side="top" className="tooltip-compact">
Hides models larger than this device's memory budget. Downloaded models stay visible.
</TooltipContent>
</Tooltip>
)}
There was a problem hiding this comment.
Good call on consistency. The toggle has since moved into the sort dropdown footer, and the label there now uses the shared Tooltip component instead of a native title, in both the chat selector and the Hub toolbar. Fixed in 78fd6ca.
| export function hfModelFitsDevice( | ||
| model: { id: string; totalParams?: number; estimatedSizeBytes?: number }, | ||
| gpu: { memoryTotalGb: number; systemRamAvailableGb: number }, | ||
| ): boolean { | ||
| if (gpu.memoryTotalGb <= 0 && gpu.systemRamAvailableGb <= 0) return true; |
There was a problem hiding this comment.
Add a defensive check to ensure gpu is defined before accessing its properties. If gpu is null or undefined (e.g., during initialization or in certain test environments), accessing gpu.memoryTotalGb directly will throw a runtime error.
| export function hfModelFitsDevice( | |
| model: { id: string; totalParams?: number; estimatedSizeBytes?: number }, | |
| gpu: { memoryTotalGb: number; systemRamAvailableGb: number }, | |
| ): boolean { | |
| if (gpu.memoryTotalGb <= 0 && gpu.systemRamAvailableGb <= 0) return true; | |
| export function hfModelFitsDevice( | |
| model: { id: string; totalParams?: number; estimatedSizeBytes?: number }, | |
| gpu?: { memoryTotalGb: number; systemRamAvailableGb: number } | null, | |
| ): boolean { | |
| if (!gpu || (gpu.memoryTotalGb <= 0 && gpu.systemRamAvailableGb <= 0)) return true; |
References
- Ensure appropriate null/nil/None checks or other language-idiomatic guards exist before object property accesses.
There was a problem hiding this comment.
useGpuInfo always returns a non null GpuInfo (it starts from a zeroed DEFAULT_GPU while /api/system loads, and the zeros make hfModelFitsDevice keep everything), and both call sites pass that hook value, so the guard cannot fire at runtime and the parameter type stays honest without it. Leaving as is.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 169bda64f0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| matchesCapability(row.capabilities, deferredCapabilityFilter) && | ||
| (!activeChannel?.finetunableOnly || isUnslothFinetunable(row.result)), | ||
| (!activeChannel?.finetunableOnly || isUnslothFinetunable(row.result)) && | ||
| (!fitOnDeviceOnly || hfModelFitsDevice(row.result, gpu)), |
There was a problem hiding this comment.
Keep downloaded Discover rows visible under the fit filter
When the Discover list contains a model that is already fully on disk (row.isAvailableOnDevice && !row.isPartialOnDevice, set by buildDiscoverRows), this predicate still hides it if the Hub metadata is missing or estimates over the memory budget. That makes locally available models disappear from Discover as soon as the shared fit filter is enabled, unlike the chat picker path which explicitly exempts downloaded models; include the row availability check before calling hfModelFitsDevice.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed. filteredDiscoverRows now exempts row.isAvailableOnDevice before the fit check, matching the chat picker. Fixed in 78fd6ca.
| !fitOnDeviceOnly || | ||
| downloadedSet.has(r.id.toLowerCase()) || | ||
| hfModelFitsDevice(r, gpu), |
There was a problem hiding this comment.
Apply the fit filter to curated search hits too
In search mode the picker renders filteredRecommendedIds before these hfIds, but this new predicate only filters the live HF results; the curated IDs come from /api/models/list defaults, which include large 27B/31B/35B GGUF entries, and they are added to recommendedSet so the filtered HF row cannot replace them. As a result, searching for one of those default large models still shows it even with “Only show models that fit on this device” enabled; apply the same ID-based fit check to filteredRecommendedIds as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed. filteredRecommendedIds now applies the same fit check as the live HF rows, with the downloaded exemption, using param counts pooled from the loaded listings. Fixed in 78fd6ca.
| const sizeBytes = | ||
| model.estimatedSizeBytes ?? (params ? estimateQuantBytes(params) : undefined); |
There was a problem hiding this comment.
Estimate safetensors fit from params, not full checkpoint bytes
When a safetensors Hub row has dtype metadata, estimatedSizeBytes is the full checkpoint size, so this branch ignores totalParams and compares FP16/BF16 bytes against the fit budget. With the new filter enabled this can hide models that would fit via the default 4-bit load path (for example an 8B BF16 repo on a machine where the ~3.2GB quantized estimate fits but the ~16GB checkpoint does not), contrary to the “smallest practical quant” heuristic; use the quant estimate for unquantized safetensors or distinguish already-quantized sizes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed. This also matched the existing VRAM badge, which sizes safetensors rows with the quantized load estimate. hfModelFitsDevice now uses the params based smallest quant estimate for non GGUF rows and only falls back to estimatedSizeBytes when no param count is available; GGUF rows keep metadata size first. Fixed in 78fd6ca.
| matchesCapability(row.capabilities, deferredCapabilityFilter) && | ||
| (!activeChannel?.finetunableOnly || isUnslothFinetunable(row.result)), | ||
| (!activeChannel?.finetunableOnly || isUnslothFinetunable(row.result)) && | ||
| (!fitOnDeviceOnly || hfModelFitsDevice(row.result, gpu)), |
There was a problem hiding this comment.
Filter feed rows when the Fits device pill is active
The new pill is shown on the Discover home/feed view, but this predicate only filters filteredDiscoverRows; feedRows later prepends feedTrendingRows, which is built without checking fitOnDeviceOnly, so oversized trending models can still appear in both the carousel and the merged feed list while the pill is active. Apply the same fit predicate to the feed/trending rows or hide the control where it cannot affect all visible Discover results.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed. feedTrendingRows now applies the same fit predicate (with the on disk exemption) so the carousel and merged feed honor the toggle. Fixed in 78fd6ca.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Exempt on-disk models from the Hub fit filter, apply it to the feed trending rows and curated search results, size safetensors and MLX rows by the quantized load estimate instead of checkpoint bytes, and replace the native title hint with the app Tooltip.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
e02f9a6 to
78fd6ca
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 78fd6cad02
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| .filter( | ||
| (r) => | ||
| !fitOnDeviceOnly || | ||
| downloadedSet.has(r.id.toLowerCase()) || | ||
| hfModelFitsDevice(r, gpu), | ||
| ) |
There was a problem hiding this comment.
Reset search paging when fit filter changes
When a user enables “Only show models that fit” after a Hub search has already loaded over-budget rows, this new filter can shrink hfIds to zero while the picker’s infinite-scroll hook is still keyed off the unfiltered results.length and debouncedQuery (see the useHubInfiniteScroll call later in this file). Because those values do not change, the auto-fill fallback is not reset and the sentinel path ignores non-overflowing lists, so the picker can remain on “No matching Unsloth models” without fetching later pages that may contain fitting models; include fitOnDeviceOnly or the filtered count in the scroll reset/result signal.
Useful? React with 👍 / 👎.
| // The "recommended" sort always applies the device-fit filter; the shared | ||
| // "Fits on device" tick extends it to the other sorts too. | ||
| if (recommendedSort !== "recommended" && !fitOnDeviceOnly) return rows; | ||
| return rows.filter((r) => { |
There was a problem hiding this comment.
Keep paginating filtered recommendations
In the empty Recommended view, enabling this fit filter can make the first fetched recommendedSearch.results page produce recommendedRows.length === 0 while recommendedSearch.hasMore is still true. The render path for that case takes the “No models found” branch and never mounts the recommended sentinel, so later pages are never fetched and fitting models beyond the first page stay unreachable; keep the sentinel/load-more state visible when rows are filtered out.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1fd413169b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // Models already on disk stay visible regardless of device fit, | ||
| // matching the chat model selector. | ||
| (!fitOnDeviceOnly || | ||
| row.isAvailableOnDevice || |
There was a problem hiding this comment.
Don't exempt partial downloads from the fit filter
Fresh evidence: buildDiscoverRows sets isAvailableOnDevice for partial cache/local rows too, and only distinguishes them via isPartialOnDevice. With the fit pill enabled, an interrupted partial download of an oversized repo satisfies this branch (and the identical feed/trending predicate below), so a model that is not fully on disk and does not fit still bypasses hfModelFitsDevice; only fully downloaded rows should skip the fit check.
Useful? React with 👍 / 👎.
What this does
Adds a "fits on device" toggle to the two model listings so users can hide models their machine cannot run:
Both controls share one persisted setting (localStorage key
unsloth_models_fit_on_device_only) through the chat runtime store, so toggling it in one place updates the other. The key is included in Settings > Reset all local preferences.How fit is decided
A new
hfModelFitsDevicehelper inrecommended-fit.tsreuses the existing fit logic from the Recommended list: device budget is 0.7x GPU VRAM plus 0.7x system RAM (covers unified memory Macs), model size comes from listing metadata or a param count parsed from the repo id, estimated at the smallest practical quant (~0.4 bytes per param). Models with no size information are hidden while the filter is on rather than wrongly shown. If the device budget is unknown, the filter keeps everything. Downloaded models are always shown since they are already on disk.Notes