Skip to content

Add a fits-on-device filter to the model selects - #6802

Merged
shimmyshimmer merged 8 commits into
mainfrom
model-picker-fit-filter
Jul 2, 2026
Merged

shimmyshimmer merged 8 commits into
mainfrom
model-picker-fit-filter

Conversation

@shimmyshimmer

Copy link
Copy Markdown
Member

What this does

Adds a "fits on device" toggle to the two model listings so users can hide models their machine cannot run:

  • Chat model selector: a checkbox under the sort controls, "Only show models that fit on this device". Hidden on the Connected tab since remote models always fit.
  • Hub page: a "Fits device" pill next to the sort menu on the discover view, with an active indicator dot.

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 hfModelFitsDevice helper in recommended-fit.ts reuses 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

  • Frontend only, no backend or API changes.
  • Filter defaults to off, so behavior is unchanged until a user enables it.

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +2584 to +2597
{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>
)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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>
      )}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +124 to +128
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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
  1. Ensure appropriate null/nil/None checks or other language-idiomatic guards exist before object property accesses.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed. filteredDiscoverRows now exempts row.isAvailableOnDevice before the fit check, matching the chat picker. Fixed in 78fd6ca.

Comment on lines +2008 to +2010
!fitOnDeviceOnly ||
downloadedSet.has(r.id.toLowerCase()) ||
hfModelFitsDevice(r, gpu),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +130 to +131
const sizeBytes =
model.estimatedSizeBytes ?? (params ? estimateQuantBytes(params) : undefined);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

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.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@shimmyshimmer
shimmyshimmer force-pushed the model-picker-fit-filter branch from e02f9a6 to 78fd6ca Compare July 2, 2026 08:58

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +2025 to +2030
.filter(
(r) =>
!fitOnDeviceOnly ||
downloadedSet.has(r.id.toLowerCase()) ||
hfModelFitsDevice(r, gpu),
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +1725 to 1728
// 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) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@shimmyshimmer
shimmyshimmer merged commit ac6ba96 into main Jul 2, 2026
40 checks passed
@shimmyshimmer
shimmyshimmer deleted the model-picker-fit-filter branch July 2, 2026 09:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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 ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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