Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

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

Daniel Hanc802f93c0877
diff --git a/.github/workflows/studio-frontend-ci.yml b/.github/workflows/studio-frontend-ci.yml
index b9341480464..42dc4097e3e 100644
--- a/.github/workflows/studio-frontend-ci.yml
+++ b/.github/workflows/studio-frontend-ci.yml
@@ -40,6 +40,7 @@ on:
- 'tests/studio/playwright_link_definition_probe.py'
- 'tests/studio/playwright_user_message_time.py'
- 'tests/studio/playwright_progressive_rows.py'
+ - 'tests/studio/playwright_model_picker_renders.py'
- 'tests/studio/playwright_recipe_drag_renders.py'
- 'tests/studio/_code_block_flicker_analysis.py'
- 'tests/studio/test_code_block_flicker_contract.py'
@@ -86,6 +87,7 @@ on:
- 'tests/studio/playwright_link_definition_probe.py'
- 'tests/studio/playwright_user_message_time.py'
- 'tests/studio/playwright_progressive_rows.py'
+ - 'tests/studio/playwright_model_picker_renders.py'
- 'tests/studio/playwright_recipe_drag_renders.py'
- 'tests/studio/_code_block_flicker_analysis.py'
- 'tests/studio/test_code_block_flicker_contract.py'
@@ -525,6 +527,13 @@ jobs:
timeout-minutes: 5
run: python3 tests/studio/playwright_progressive_rows.py
+ # Render counts, not timings: a search keystroke or a quant probe answer in the model
+ # picker's On Device tab must not re-render every row, and the rows must still navigate.
+ - name: Browser check for model picker re-renders
+ working-directory: ${{ github.workspace }}
+ timeout-minutes: 8
+ run: python3 tests/studio/playwright_model_picker_renders.py
+
# A drag step moves one node; the other nodes of the graph must not re-render.
- name: Browser check for Recipe Studio drag re-renders
working-directory: ${{ github.workspace }}
diff --git a/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx b/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx
index 80733824a37..30a86c84c1d 100644
--- a/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx
+++ b/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx
@@ -158,10 +158,12 @@ import {
type ReactNode,
type SetStateAction,
createContext,
+ memo,
useCallback,
useContext,
useEffect,
useId,
+ useLayoutEffect,
useMemo,
useRef,
useState,
@@ -368,6 +370,64 @@ type ModelRowOptionProps = {
"aria-current"?: "true";
};
+/** Set after commit, read only from handlers, so memoized rows reach the latest callbacks. */
+class LatestBox<T> {
+ private value: T | null = null;
+ set(value: T) {
+ this.value = value;
+ }
+ get(): T {
+ return this.value as T;
+ }
+}
+
+type RovingMoveDirection = "next" | "previous" | "first" | "last";
+
+interface RovingOptionEvents {
+ setRovingOptionKey: (optionKey: string) => void;
+ moveFocus: (fromOptionKey: string, direction: RovingMoveDirection) => void;
+}
+
+function moveFocusForKey(
+ event: KeyboardEvent<HTMLButtonElement>,
+ optionKey: string,
+ moveFocus: RovingOptionEvents["moveFocus"],
+) {
+ if (event.key === "ArrowDown") {
+ event.preventDefault();
+ moveFocus(optionKey, "next");
+ } else if (event.key === "ArrowUp") {
+ event.preventDefault();
+ moveFocus(optionKey, "previous");
+ } else if (event.key === "Home") {
+ event.preventDefault();
+ moveFocus(optionKey, "first");
+ } else if (event.key === "End") {
+ event.preventDefault();
+ moveFocus(optionKey, "last");
+ }
+}
+
+/** The same props as `getOptionProps`, built from row data so a memoized row can hold them. */
+function rovingOptionProps(
+ events: LatestBox<RovingOptionEvents>,
+ optionKey: string,
+ optionId: string,
+ active: boolean,
+ selected: boolean,
+): ModelRowOptionProps {
+ return {
+ id: optionId,
+ tabIndex: 0,
+ onFocus: () => events.get().setRovingOptionKey(optionKey),
+ onKeyDown: (event) =>
+ moveFocusForKey(event, optionKey, events.get().moveFocus),
+ "data-model-picker-option": true,
+ "data-model-picker-active-option": active ? "true" : undefined,
+ "aria-current": selected ? "true" : undefined,
+ };
+}
+
function useRovingModelList({
label,
optionKeys,
@@ -418,7 +478,7 @@ function useRovingModelList({
const moveFocus = useCallback(
(
fromOptionKey: string,
- direction: "next" | "previous" | "first" | "last",
+ direction: RovingMoveDirection,
) => {
if (optionKeys.length === 0) {
return;
@@ -458,21 +518,7 @@ function useRovingModelList({
onFocus: () => {
setRovingOptionKey(optionKey);
},
- onKeyDown: (event) => {
- if (event.key === "ArrowDown") {
- event.preventDefault();
- moveFocus(optionKey, "next");
- } else if (event.key === "ArrowUp") {
- event.preventDefault();
- moveFocus(optionKey, "previous");
- } else if (event.key === "Home") {
- event.preventDefault();
- moveFocus(optionKey, "first");
- } else if (event.key === "End") {
- event.preventDefault();
- moveFocus(optionKey, "last");
- }
- },
+ onKeyDown: (event) => moveFocusForKey(event, optionKey, moveFocus),
"data-model-picker-option": true,
"data-model-picker-active-option":
optionKey === activeOptionKey ? "true" : undefined,
@@ -481,10 +527,22 @@ function useRovingModelList({
[activeOptionKey, getOptionDomId, listboxId, moveFocus],
);
+ const [optionEvents] = useState(() => new LatestBox<RovingOptionEvents>());
+ useLayoutEffect(() => {
+ optionEvents.set({ setRovingOptionKey, moveFocus });
+ }, [optionEvents, moveFocus]);
+ const getOptionId = useCallback(
+ (optionKey: string) =>
+ getOptionDomId(optionKey) ?? `${listboxId}-option-missing`,
+ [getOptionDomId, listboxId],
+ );
+
return {
activeOptionKey,
focusOption,
getOptionProps,
+ getOptionId,
+ optionEvents,
moveFocus,
listboxProps: {
id: listboxId,
@@ -1599,6 +1657,691 @@ function ModelRow({
return content;
}
+interface DeviceRowActions {
+ hfToken: string | undefined;
+ select: (id: string, meta: ModelSelectorChangeMeta) => void;
+ configure: (id: string, meta: ModelSelectorChangeMeta) => void;
+ toggleGgufExpanded: (id: string, showing?: boolean) => void;
+ togglePinned: (repoId: string, quant?: string) => void;
+ unpinRepo: (repoId: string) => void;
+ eject: (modelId: string) => void;
+ refreshCachedLists: () => void;
+ refreshLocalModelsList: () => void;
+ prunePinnedQuantValidation: (repoId: string, quant: string) => void;
+ updateGgufVariant: (
+ repoId: string,
+ quant: string,
+ expectedBytes: number,
+ ) => Promise<void> | void;
+ reportVision: (repoId: string, hasVision: boolean) => void;
+ focusOption: (optionKey: string) => void;
+ moveFocus: (optionKey: string, direction: RovingMoveDirection) => void;
+}
+
+type DeviceRowActionsBox = LatestBox<DeviceRowActions>;
+
+interface DeviceRowListProps {
+ actions: DeviceRowActionsBox;
+ optionEvents: LatestBox<RovingOptionEvents>;
+ optionId: string;
+ optionActive: boolean;
+ canConfigure: boolean;
+ deleteDisabled: boolean;
+}
+
+interface DeviceRowExpanderProps {
+ diffusionLoad: boolean;
+ hostPooledMemory: boolean;
+ gpuCount: number | undefined;
+ gpuGb: number | undefined;
+ systemRamGb: number | undefined;
+ budgetKnown: boolean;
+ /** Never wrap: the expander refetches companion sizes when this changes identity. */
+ resolveDownloadFootprint: ModelDownloadFootprintResolver | undefined;
+ hfToken: string | undefined;
+}
+
+const EMPTY_LOADED_QUANTS: readonly string[] = [];
+
+function ejectMenuItemsFor(
+ actions: DeviceRowActionsBox,
+ modelId: string,
+ ejectable: boolean,
+) {
+ return ejectable
+ ? [
+ {
+ key: "eject",
+ label: "Eject",
+ icon: (
+ <HugeiconsIcon
+ icon={RemoveCircleIcon}
+ strokeWidth={1.75}
+ className="size-icon"
+ />
+ ),
+ onSelect: () => actions.get().eject(modelId),
+ },
+ ]
+ : undefined;
+}
+
+/** Stable forwarders for the quant expander callbacks that only run from events. */
+function useDeviceExpanderCallbacks(
+ actions: DeviceRowActionsBox,
+ optionKey: string,
+) {
+ const onSelect = useCallback(
+ (id: string, meta: ModelSelectorChangeMeta) =>
+ actions.get().select(id, meta),
+ [actions],
+ );
+ const onConfigure = useCallback(
+ (id: string, meta: ModelSelectorChangeMeta) =>
+ actions.get().configure(id, meta),
+ [actions],
+ );
+ const onNavigatePastStart = useCallback(
+ () => actions.get().focusOption(optionKey),
+ [actions, optionKey],
+ );
+ const onNavigatePastEnd = useCallback(
+ () => actions.get().moveFocus(optionKey, "next"),
+ [actions, optionKey],
+ );
+ return {
+ onSelect,
+ onConfigure,
+ onNavigatePastStart,
+ onNavigatePastEnd,
+ };
+}
+
+const DownloadedModelDeviceRow = memo(function DownloadedModelDeviceRow({
+ model: c,
+ optionKey,
+ selected: isSelected,
+ loaded,
+ pinned,
+ ejectable,
+ actions,
+ optionEvents,
+ optionId,
+ optionActive,
+ canConfigure,
+ deleteDisabled,
+}: DeviceRowListProps & {
+ model: CachedModelRepo;
+ optionKey: string;
+ selected: boolean;
+ loaded: boolean;
+ pinned: boolean;
+ ejectable: boolean;
+}) {
+ // A partial pick must not claim downloaded, or the load fails on missing shards.
+ const isPartial = c.partial === true;
+ return (
+ <div className={downloadedRowShellClassName(isSelected)}>
+ <div className="min-w-0 flex-1">
+ <ModelRow
+ label={c.repo_id}
+ hubUrl={hubRepoUrl(c.repo_id)}
+ meta={`${isMlxId(c.repo_id) ? "MLX" : "Safetensors"} · ${formatBytes(
+ c.size_bytes,
+ )}`}
+ selected={isSelected}
+ alignMeta="device"
+ partial={isPartial}
+ partialResumable={c.partial_resumable}
+ loaded={loaded}
+ optionProps={rovingOptionProps(
+ optionEvents,
+ optionKey,
+ optionId,
+ optionActive,
+ isSelected,
+ )}
+ onClick={() =>
+ actions.get().select(c.repo_id, {
+ source: "hub",
+ isLora: false,
+ // The Audio route reads a forwarded loadId as proof the weights are there.
+ loadId: isPartial ? undefined : c.load_id,
+ isDownloaded: !isPartial,
+ pipelineTag: c.task ?? null,
+ audioType: c.audio_type ?? null,
+ familyOverrideRequired: c.opaque === true,
+ })
+ }
+ vramStatus={null}
+ className={downloadedRowButtonClassName}
+ />
+ </div>
+ <span className={isPartial ? ROW_ACTIONS_PINNED_CLASS : ROW_ACTIONS_CLASS}>
+ {canConfigure && (
+ <ModelLoadSettingsAction
+ ariaLabel={`Inference settings for ${c.repo_id}`}
+ onConfigure={() =>
+ actions.get().configure(c.repo_id, {
+ source: "hub",
+ isLora: false,
+ // No load identity for an incomplete snapshot.
+ loadId: isPartial ? undefined : c.load_id,
+ isDownloaded: !isPartial,
+ isGguf: false,
+ pipelineTag: c.task ?? null,
+ audioType: c.audio_type ?? null,
+ familyOverrideRequired: c.opaque === true,
+ })
+ }
+ />
+ )}
+ <ModelRowMenu
+ ariaLabel={`More options for ${c.repo_id}`}
+ cachePath={{ repoId: c.repo_id }}
+ items={ejectMenuItemsFor(actions, c.repo_id, ejectable)}
+ pin={{
+ pinned,
+ pinLabel: "Pin",
+ unpinLabel: "Unpin",
+ onToggle: () => actions.get().togglePinned(c.repo_id),
+ }}
+ del={{
+ title: "Delete cached model?",
+ impact: { repoId: c.repo_id },
+ description: (
+ <>
+ This will remove{" "}
+ <span className="font-medium text-foreground">{c.repo_id}</span>{" "}
+ from disk. You can re-download it later.
+ </>
+ ),
+ successMessage: `Deleted ${c.repo_id}`,
+ disabled: deleteDisabled,
+ onConfirm: async () => {
+ const a = actions.get();
+ await deleteCachedModel(
+ c.repo_id,
+ undefined,
+ a.hfToken || undefined,
+ c.cache_path || undefined,
+ );
+ // Repo-wide, so quant pins go too.
+ actions.get().unpinRepo(c.repo_id);
+ },
+ onDeleted: () => actions.get().refreshCachedLists(),
+ }}
+ />
+ </span>
+ </div>
+ );
+});
+
+// One quant on disk with "All quantizations" off: the row carries it as a chip.
+const SoleQuantGgufDeviceRow = memo(function SoleQuantGgufDeviceRow({
+ repo: c,
+ sole,
+ optionKey,
+ selected: isSelected,
+ loaded,
+ pinned: isPinned,
+ ejectable,
+ gpuGb,
+ actions,
+ optionEvents,
+ optionId,
+ optionActive,
+ canConfigure,
+ deleteDisabled,
+}: DeviceRowListProps & {
+ repo: CachedGgufRepo;
+ sole: SoleDownloadedQuant;
+ optionKey: string;
+ selected: boolean;
+ loaded: boolean;
+ pinned: boolean;
+ ejectable: boolean;
+ gpuGb: number | undefined;
+}) {
+ const variant = sole.variant;
+ const expectedBytes = ggufVariantExpectedBytes(variant);
+ // Should never be partial, but if it is, state what is on disk rather than load a torn file.
+ const isPartial = c.partial === true;
+ const isDownloaded = variant.downloaded === true && !isPartial;
+ const selectMeta: ModelSelectorChangeMeta = {
+ source: "hub",
+ isLora: false,
+ // Only for complete snapshots: the Audio route reads a loadId as proof the weights are present.
+ loadId: isDownloaded ? c.load_id : undefined,
+ ggufVariant: variant.quant,
+ ggufFilename: variant.filename,
+ isDownloaded,
+ expectedBytes,
+ isGguf: true,
+ // Forward the mmproj verdict conservatively so a known text-only quant still warns.
+ isVision: sole.hasVision === false ? false : undefined,
+ pipelineTag: c.task ?? null,
+ };
+ return (
+ <div className={downloadedRowShellClassName(isSelected, true)}>
+ <div className="min-w-0 flex-1">
+ <ModelRow
+ label={onDeviceRepoLabel(c.repo_id)}
+ tooltipText={localPathTooltip(
+ c.repo_id,
+ c.cache_path,
+ ggufQuantDetailLabel(variant.quant),
+ )}
+ meta={`GGUF · ${formatBytes(variant.size_bytes)}`}
+ quantChip={ggufQuantChipLabel(variant.quant)}
+ partial={isPartial}
+ // Only for llama.cpp loads: diffusion GGUFs run on a different planner and the estimate would be wrong.
+ memory={
+ mediaPageForTask(c.task)
+ ? undefined
+ : {
+ repoId: c.repo_id,
+ quant: variant.quant,
+ sizeBytes: variant.size_bytes,
+ lookupTableBytes: ggufVariantLookupTableBytes(variant),
+ loadId: c.load_id,
+ }
+ }
+ gpuGb={gpuGb}
+ showVision={c.has_vision || sole.hasVision}
+ selected={isSelected}
+ loaded={loaded}
+ alignMeta="device"
+ optionProps={rovingOptionProps(
+ optionEvents,
+ optionKey,
+ optionId,
+ optionActive,
+ isSelected,
+ )}
+ onClick={() => actions.get().select(c.repo_id, selectMeta)}
+ vramStatus={null}
+ className={downloadedRowButtonClassName}
+ />
+ </div>
+ <span className={ROW_ACTIONS_CLASS}>
+ {canConfigure && (
+ <ModelLoadSettingsAction
+ ariaLabel={`Inference settings for ${onDeviceRepoLabel(c.repo_id)} ${variant.quant}`}
+ onConfigure={() => actions.get().configure(c.repo_id, selectMeta)}
+ />
+ )}
+ <ModelRowMenu
+ ariaLabel={`More options for ${onDeviceRepoLabel(c.repo_id)} ${variant.quant}`}
+ cachePath={{ repoId: c.repo_id, variant: variant.quant }}
+ items={ejectMenuItemsFor(actions, c.repo_id, ejectable)}
+ pin={{
+ pinned: isPinned,
+ pinLabel: "Pin",
+ unpinLabel: "Unpin",
+ onToggle: () => actions.get().togglePinned(c.repo_id, variant.quant),
+ }}
+ del={{
+ title: "Delete cached model?",
+ impact: {
+ repoId: c.repo_id,
+ variant: variant.quant,
+ cachePath:
+ variant.cache_ref ??
+ variant.cache_path ??
+ (mediaPageForTask(c.task) ? c.cache_path : null),
+ },
+ description: (
+ <>
+ This will remove{" "}
+ <span className="font-medium text-foreground">
+ {onDeviceRepoLabel(c.repo_id)} ({variant.quant})
+ </span>{" "}
+ from disk. You can re-download it later.
+ </>
+ ),
+ successMessage: `Deleted ${onDeviceRepoLabel(c.repo_id)} ${variant.quant}`,
+ disabled: deleteDisabled,
+ onConfirm: async () => {
+ const hfToken = actions.get().hfToken;
+ await deleteCachedModel(
+ c.repo_id,
+ variant.quant,
+ hfToken || undefined,
+ variant.cache_ref ??
+ variant.cache_path ??
+ (mediaPageForTask(c.task) ? c.cache_path : undefined) ??
+ undefined,
+ );
+ if (isChatGgufTask(c.task)) {
+ await reconcileGgufPinsAfterDelete(c.repo_id, hfToken || undefined);
+ } else if (isPinned) {
+ actions.get().togglePinned(c.repo_id, variant.quant);
+ }
+ actions.get().prunePinnedQuantValidation(c.repo_id, variant.quant);
+ actions.get().refreshCachedLists();
+ },
+ }}
+ />
+ </span>
+ </div>
+ );
+});
+
+const DownloadedGgufDeviceRow = memo(function DownloadedGgufDeviceRow({
+ repo: c,
+ optionKey,
+ selected: isSelected,
+ loaded,
+ loadedQuants,
+ showVision,
+ expanderOpen,
+ soleQuantPending,
+ updateDisabled,
+ expander,
+ actions,
+ optionEvents,
+ optionId,
+ optionActive,
+ canConfigure,
+ deleteDisabled,
+}: DeviceRowListProps & {
+ repo: CachedGgufRepo;
+ optionKey: string;
+ selected: boolean;
+ loaded: boolean;
+ loadedQuants: readonly string[];
+ showVision: boolean | undefined;
+ expanderOpen: boolean;
+ soleQuantPending: boolean;
+ updateDisabled: boolean;
+ expander: DeviceRowExpanderProps;
+}) {
+ const callbacks = useDeviceExpanderCallbacks(actions, optionKey);
+ // No clean quant, so nothing in the expander can carry the row's actions.
+ const isPartialRepo = c.partial === true;
+ return (
+ <div>
+ <div className={downloadedRowShellClassName(isSelected)}>
+ <div className="min-w-0 flex-1">
+ <ModelRow
+ label={onDeviceRepoLabel(c.repo_id)}
+ tooltipText={localPathTooltip(c.repo_id, c.cache_path)}
+ meta="GGUF"
+ quantChip={loadedQuants.map(ggufQuantChipLabel).join(", ") || undefined}
+ showVision={showVision}
+ alignMeta="device"
+ partial={isPartialRepo}
+ partialResumable={c.partial_resumable}
+ selected={isSelected}
+ loaded={loaded}
+ optionProps={rovingOptionProps(
+ optionEvents,
+ optionKey,
+ optionId,
+ optionActive,
+ isSelected,
+ )}
+ onClick={() => actions.get().toggleGgufExpanded(c.repo_id, expanderOpen)}
+ onArrowDownIntoChildren={
+ expanderOpen ? () => focusFirstChildOption(optionKey) : undefined
+ }
+ vramStatus={null}
+ className={downloadedRowButtonClassName}
+ />
+ </div>
+ {isPartialRepo ? (
+ <span className={ROW_ACTIONS_PINNED_CLASS}>
+ <ModelRowMenu
+ ariaLabel={`More options for ${onDeviceRepoLabel(c.repo_id)}`}
+ cachePath={{ repoId: c.repo_id }}
+ del={{
+ title: "Delete cached model?",
+ impact: { repoId: c.repo_id },
+ // Repo-wide delete, which may include a complete copy in another format.
+ description: (
+ <>
+ This will remove{" "}
+ <span className="font-medium text-foreground">
+ {onDeviceRepoLabel(c.repo_id)}
+ </span>{" "}
+ and everything downloaded under it from disk. You can
+ download it again later.
+ </>
+ ),
+ successMessage: `Deleted ${onDeviceRepoLabel(c.repo_id)}`,
+ disabled: deleteDisabled,
+ onConfirm: async () => {
+ const hfToken = actions.get().hfToken;
+ await deleteCachedModel(
+ c.repo_id,
+ undefined,
+ hfToken || undefined,
+ c.cache_path || undefined,
+ );
+ if (isChatGgufTask(c.task)) {
+ // Another remembered folder may still hold a pinned quant.
+ await reconcileGgufPinsAfterDelete(c.repo_id, hfToken || undefined);
+ } else {
+ actions.get().unpinRepo(c.repo_id);
+ }
+ },
+ onDeleted: () => actions.get().refreshCachedLists(),
+ }}
+ />
+ </span>
+ ) : (
+ // No chevron until the probe rules out a sole quant. The gutter is a mouse target (the row
+ // has the keyboard); pr-2.5 is the heading chevron's column.
+ <span className={cn(ROW_ACTIONS_PINNED_CLASS, "h-6")}>
+ {soleQuantPending ? null : (
+ <button
+ type="button"
+ tabIndex={-1}
+ aria-hidden="true"
+ onClick={() =>
+ actions.get().toggleGgufExpanded(c.repo_id, expanderOpen)
+ }
+ className="flex h-full w-full cursor-pointer items-center justify-end pr-2.5 text-muted-foreground/80 hover:text-foreground"
+ >
+ <HugeiconsIcon
+ icon={
+ expanderOpen
+ ? ChevronDownStandardIcon
+ : ChevronRightStandardIcon
+ }
+ className="size-3"
+ />
+ </button>
+ )}
+ </span>
+ )}
+ </div>
+ {expanderOpen && (
+ <GgufVariantExpander
+ diffusionLoad={expander.diffusionLoad}
+ hostPooledMemory={expander.hostPooledMemory}
+ gpuCount={expander.gpuCount}
+ repoId={c.repo_id}
+ loadedQuants={loadedQuants}
+ pipelineTag={c.task ?? null}
+ loadId={c.load_id}
+ cachePath={c.cache_path}
+ onDevice={true}
+ allowPin={true}
+ onHasVision={(v) => actions.get().reportVision(c.repo_id, v)}
+ onSelect={callbacks.onSelect}
+ resolveDownloadFootprint={expander.resolveDownloadFootprint}
+ onConfigure={canConfigure ? callbacks.onConfigure : undefined}
+ hfToken={expander.hfToken}
+ parentOptionKey={optionKey}
+ onNavigatePastStart={callbacks.onNavigatePastStart}
+ onNavigatePastEnd={callbacks.onNavigatePastEnd}
+ gpuGb={expander.gpuGb}
+ systemRamGb={expander.systemRamGb}
+ budgetKnown={expander.budgetKnown}
+ variantActions={{
+ onUpdate: (quant, expectedBytes) =>
+ actions.get().updateGgufVariant(c.repo_id, quant, expectedBytes),
+ updateDisabled,
+ onDelete: async (quant, cachePath) => {
+ const a = actions.get();
+ await deleteCachedModel(
+ c.repo_id,
+ quant,
+ a.hfToken || undefined,
+ cachePath ??
+ (mediaPageForTask(c.task) ? c.cache_path || undefined : undefined),
+ );
+ actions.get().prunePinnedQuantValidation(c.repo_id, quant);
+ actions.get().refreshCachedLists();
+ },
+ }}
+ />
+ )}
+ </div>
+ );
+});
+
+const LocalModelDeviceRow = memo(function LocalModelDeviceRow({
+ model: m,
+ optionKey,
+ directGguf: isDirectGguf,
+ selected: isSelected,
+ loaded,
+ expanded,
+ loadedQuants,
+ expander,
+ actions,
+ optionEvents,
+ optionId,
+ optionActive,
+ canConfigure,
+ deleteDisabled,
+}: DeviceRowListProps & {
+ model: LocalModelInfo;
+ optionKey: string;
+ /** Loads as one file, so it has no quant expander. */
+ directGguf: boolean;
+ selected: boolean;
+ loaded: boolean;
+ expanded: boolean;
+ loadedQuants: readonly string[];
+ expander: DeviceRowExpanderProps;
+}) {
+ const callbacks = useDeviceExpanderCallbacks(actions, optionKey);
+ // Honor the backend model_format hint (suffixless GGUF folders).
+ const isGguf = localModelIsGguf(m);
+ const name = m.model_id ?? m.display_name;
+ const showExpander = isGguf && !isDirectGguf && expanded;
+ return (
+ <div>
+ <div className={downloadedRowShellClassName(isSelected)}>
+ <div className="min-w-0 flex-1">
+ <ModelRow
+ label={name}
+ meta={isGguf ? "GGUF" : "Local"}
+ tooltipText={localPathTooltip(name, m.path)}
+ selected={isSelected}
+ loaded={loaded}
+ optionProps={rovingOptionProps(
+ optionEvents,
+ optionKey,
+ optionId,
+ optionActive,
+ isSelected,
+ )}
+ onClick={() => {
+ const a = actions.get();
+ if (isDirectGguf) {
+ a.select(m.id, localDirectGgufMeta(m.task));
+ } else if (isGguf) {
+ a.toggleGgufExpanded(m.id);
+ } else {
+ a.select(
+ m.id,
+ localModelMeta(false, m.task, m.audio_type, m.opaque === true),
+ );
+ }
+ }}
+ onArrowDownIntoChildren={
+ showExpander ? () => focusFirstChildOption(optionKey) : undefined
+ }
+ alignMeta="device"
+ vramStatus={null}
+ className={downloadedRowButtonClassName}
+ />
+ </div>
+ <span className={ROW_ACTIONS_CLASS}>
+ {isDirectGguf && canConfigure && (
+ <ModelLoadSettingsAction
+ ariaLabel={`Inference settings for ${name}`}
+ onConfigure={() =>
+ actions.get().configure(m.id, localDirectGgufMeta(m.task))
+ }
+ />
+ )}
+ {!isGguf && canConfigure && (
+ <ModelLoadSettingsAction
+ ariaLabel={`Inference settings for ${name}`}
+ onConfigure={() =>
+ actions
+ .get()
+ .configure(
+ m.id,
+ localModelMeta(false, m.task, m.audio_type, m.opaque === true),
+ )
+ }
+ />
+ )}
+ <ModelRowMenu
+ ariaLabel={`More options for ${name}`}
+ onReveal={() => revealLocalModel(m.path, m.id)}
+ del={
+ DELETABLE_LOCAL_SOURCES.has(m.source)
+ ? {
+ title: "Delete local model?",
+ description: (
+ <>
+ This will permanently remove{" "}
+ <span className="font-medium text-foreground">{name}</span>{" "}
+ from{" "}
+ <span className="break-all font-mono text-xs">{m.path}</span>.
+ </>
+ ),
+ successMessage: `Deleted ${name}`,
+ disabled: deleteDisabled,
+ onConfirm: () => deleteLocalModel(m.path, m.id),
+ onDeleted: () => actions.get().refreshLocalModelsList(),
+ }
+ : undefined
+ }
+ />
+ </span>
+ </div>
+ {showExpander && (
+ <GgufVariantExpander
+ diffusionLoad={expander.diffusionLoad}
+ hostPooledMemory={expander.hostPooledMemory}
+ gpuCount={expander.gpuCount}
+ repoId={m.id}
+ loadedQuants={loadedQuants}
+ onDevice={true}
+ onSelect={callbacks.onSelect}
+ resolveDownloadFootprint={expander.resolveDownloadFootprint}
+ onConfigure={canConfigure ? callbacks.onConfigure : undefined}
+ parentOptionKey={optionKey}
+ onNavigatePastStart={callbacks.onNavigatePastStart}
+ onNavigatePastEnd={callbacks.onNavigatePastEnd}
+ gpuGb={expander.gpuGb}
+ systemRamGb={expander.systemRamGb}
+ budgetKnown={expander.budgetKnown}
+ />
+ )}
+ </div>
+ );
+});
+
function isValidGgufVariant(variant: unknown): variant is GgufVariantDetail {
if (!variant || typeof variant !== "object") return false;
@@ -3080,7 +3823,7 @@ export function HubModelPicker({
);
const isKeptLoaded = (repoId: string) =>
loadedIdSet.has(repoId.toLowerCase());
- const loadedQuantsFor = (repoId: string): string[] => {
+ const loadedQuantsFor = (repoId: string): readonly string[] => {
const quants = isChatPicker
? loadedModels
.filter((m) => m.quant && modelIdsMatchForPicker(m.id, repoId))
@@ -3089,7 +3832,8 @@ export function HubModelPicker({
if (activeGgufVariant && modelIdsMatchForPicker(loadedModelId, repoId)) {
quants.push(activeGgufVariant);
}
- return [...new Set(quants)];
+ // One shared empty list, so a memoized row with nothing loaded keeps equal props.
+ return quants.length === 0 ? EMPTY_LOADED_QUANTS : [...new Set(quants)];
};
const loadedRows = useMemo(() => {
if (!isChatPicker || section !== "recommended") return [];
@@ -6111,23 +6855,58 @@ export function HubModelPicker({
);
};
- const ejectMenuItems = (modelId: string) =>
- ejectsKept && isKeptLoaded(modelId)
- ? [
- {
- key: "eject",
- label: "Eject",
- icon: (
- <HugeiconsIcon
- icon={RemoveCircleIcon}
- strokeWidth={1.75}
- className="size-icon"
- />
- ),
- onSelect: () => onEject?.(modelId),
- },
- ]
- : undefined;
+ const [deviceRowActions] = useState(() => new LatestBox<DeviceRowActions>());
+ useLayoutEffect(() => {
+ deviceRowActions.set({
+ hfToken: hfToken || undefined,
+ select: onSelect,
+ configure: (id, meta) => onConfigure?.(id, meta),
+ toggleGgufExpanded,
+ togglePinned,
+ unpinRepo,
+ eject: (modelId) => onEject?.(modelId),
+ refreshCachedLists,
+ refreshLocalModelsList,
+ prunePinnedQuantValidation,
+ updateGgufVariant,
+ reportVision,
+ focusOption: hubModelList.focusOption,
+ moveFocus: hubModelList.moveFocus,
+ });
+ });
+ const expanderBudgetKnown = expanderBudgetGpu.budgetKnown;
+ const hostPooledMemory = gpu.loadDeviceSharesHostMemory;
+ const deviceExpanderProps = useMemo<DeviceRowExpanderProps>(
+ () => ({
+ diffusionLoad,
+ hostPooledMemory,
+ gpuCount: expanderGpuCount,
+ gpuGb: expanderGpuGb,
+ systemRamGb: expanderRamGb || undefined,
+ budgetKnown: expanderBudgetKnown,
+ resolveDownloadFootprint,
+ hfToken: hfToken || undefined,
+ }),
+ [
+ diffusionLoad,
+ hostPooledMemory,
+ expanderGpuCount,
+ expanderGpuGb,
+ expanderRamGb,
+ expanderBudgetKnown,
+ resolveDownloadFootprint,
+ hfToken,
+ ],
+ );
+ const deviceRowListProps = (optionKey: string): DeviceRowListProps => ({
+ actions: deviceRowActions,
+ optionEvents: hubModelList.optionEvents,
+ optionId: hubModelList.getOptionId(optionKey),
+ optionActive: optionKey === hubModelList.activeOptionKey,
+ canConfigure: Boolean(onConfigure),
+ deleteDisabled,
+ });
+
const renderLoadedRow = (entry: (typeof loadedModels)[number]) => {
// Key by checkpoint: local models load by path and two files can share a name.
@@ -6556,427 +7335,119 @@ export function HubModelPicker({
c: (typeof visibleCachedGguf)[number],
sole: SoleDownloadedQuant,
) => {
- const variant = sole.variant;
const optionKey = makeModelOptionKey("downloaded-gguf", c.repo_id);
const rowState = soleQuantRowState({
pickerValue: value,
repoId: c.repo_id,
- quant: variant.quant,
+ quant: sole.variant.quant,
loadedModelId,
activeGgufVariant,
});
- const isSelected = rowState.selected;
- const expectedBytes = ggufVariantExpectedBytes(variant);
- const isPinned = pinnedSet.has(pinKey(c.repo_id, variant.quant));
- // Should never be partial, but if it is, state what is on disk rather than load a torn file.
- const isPartial = c.partial === true;
- const isDownloaded = variant.downloaded === true && !isPartial;
- const selectMeta: ModelSelectorChangeMeta = {
- source: "hub",
- isLora: false,
- // Only for complete snapshots: the Audio route reads a loadId as proof the weights are present.
- loadId: isDownloaded ? c.load_id : undefined,
- ggufVariant: variant.quant,
- ggufFilename: variant.filename,
- isDownloaded,
- expectedBytes,
- isGguf: true,
- // Forward the mmproj verdict conservatively so a known text-only quant still warns.
- isVision: sole.hasVision === false ? false : undefined,
- pipelineTag: c.task ?? null,
- };
return (
- <div
+ <SoleQuantGgufDeviceRow
key={c.repo_id}
- className={downloadedRowShellClassName(isSelected, true)}
- >
- <div className="min-w-0 flex-1">
- <ModelRow
- label={onDeviceRepoLabel(c.repo_id)}
- tooltipText={localPathTooltip(
- c.repo_id,
- c.cache_path,
- ggufQuantDetailLabel(variant.quant),
- )}
- meta={`GGUF · ${formatBytes(variant.size_bytes)}`}
- quantChip={ggufQuantChipLabel(variant.quant)}
- partial={isPartial}
- // Only for llama.cpp loads: diffusion GGUFs run on a different planner and the estimate would be wrong.
- memory={
- mediaPageForTask(c.task)
- ? undefined
- : {
- repoId: c.repo_id,
- quant: variant.quant,
- sizeBytes: variant.size_bytes,
- lookupTableBytes: ggufVariantLookupTableBytes(variant),
- loadId: c.load_id,
- }
- }
- gpuGb={expanderGpuGb}
- showVision={c.has_vision || sole.hasVision}
- selected={isSelected}
- loaded={rowState.loaded || isKeptLoaded(c.repo_id)}
- alignMeta="device"
- optionProps={hubModelList.getOptionProps(optionKey, isSelected)}
- onClick={() => onSelect(c.repo_id, selectMeta)}
- vramStatus={null}
- className={downloadedRowButtonClassName}
- />
- </div>
- <span className={ROW_ACTIONS_CLASS}>
- {onConfigure && (
- <ModelLoadSettingsAction
- ariaLabel={`Inference settings for ${onDeviceRepoLabel(c.repo_id)} ${variant.quant}`}
- onConfigure={() => onConfigure(c.repo_id, selectMeta)}
- />
- )}
- <ModelRowMenu
- ariaLabel={`More options for ${onDeviceRepoLabel(c.repo_id)} ${variant.quant}`}
- cachePath={{ repoId: c.repo_id, variant: variant.quant }}
- items={ejectMenuItems(c.repo_id)}
- pin={{
- pinned: isPinned,
- pinLabel: "Pin",
- unpinLabel: "Unpin",
- onToggle: () => togglePinned(c.repo_id, variant.quant),
- }}
- del={{
- title: "Delete cached model?",
- impact: {
- repoId: c.repo_id,
- variant: variant.quant,
- cachePath:
- variant.cache_ref ??
- variant.cache_path ??
- (mediaPageForTask(c.task) ? c.cache_path : null),
- },
- description: (
- <>
- This will remove{" "}
- <span className="font-medium text-foreground">
- {onDeviceRepoLabel(c.repo_id)} ({variant.quant})
- </span>{" "}
- from disk. You can re-download it later.
- </>
- ),
- successMessage: `Deleted ${onDeviceRepoLabel(c.repo_id)} ${variant.quant}`,
- disabled: deleteDisabled,
- onConfirm: async () => {
- await deleteCachedModel(
- c.repo_id,
- variant.quant,
- hfToken || undefined,
- variant.cache_ref ??
- variant.cache_path ??
- (mediaPageForTask(c.task) ? c.cache_path : undefined) ??
- undefined,
- );
- if (isChatGgufTask(c.task)) {
- await reconcileGgufPinsAfterDelete(c.repo_id, hfToken || undefined);
- } else if (isPinned) {
- togglePinned(c.repo_id, variant.quant);
- }
- prunePinnedQuantValidation(c.repo_id, variant.quant);
- refreshCachedLists();
- },
- }}
- />
- </span>
- </div>
+ repo={c}
+ sole={sole}
+ optionKey={optionKey}
+ selected={rowState.selected}
+ loaded={rowState.loaded || isKeptLoaded(c.repo_id)}
+ pinned={pinnedSet.has(pinKey(c.repo_id, sole.variant.quant))}
+ ejectable={ejectsKept && isKeptLoaded(c.repo_id)}
+ gpuGb={expanderGpuGb}
+ {...deviceRowListProps(optionKey)}
+ />
);
};
const renderDownloadedGgufRow = (c: (typeof visibleCachedGguf)[number]) => {
const optionKey = makeModelOptionKey("downloaded-gguf", c.repo_id);
- const isSelected = value === c.repo_id;
const soleQuant = soleQuants.quants.get(c.repo_id);
if (soleQuant) return renderSoleQuantGgufRow(c, soleQuant);
- const loadedQuants = loadedQuantsFor(c.repo_id);
// Auto-expansion waits for the probe, or every row mounts an expander and a remote listing.
const expanderOpen = shouldMountVariantExpander({
expanded: isGgufExpanded(c.repo_id),
autoExpand: expandQuantizations && !reopenedGguf.has(c.repo_id),
soleQuantsPending: soleQuants.pending.has(c.repo_id),
});
- // No clean quant, so nothing in the expander can carry the row's actions.
- const isPartialRepo = c.partial === true;
return (
- <div key={c.repo_id}>
- <div className={downloadedRowShellClassName(isSelected)}>
- <div className="min-w-0 flex-1">
- <ModelRow
- label={onDeviceRepoLabel(c.repo_id)}
- tooltipText={localPathTooltip(c.repo_id, c.cache_path)}
- meta="GGUF"
- quantChip={loadedQuants.map(ggufQuantChipLabel).join(", ") || undefined}
- showVision={c.has_vision ?? visionByRepo[c.repo_id]}
- alignMeta="device"
- partial={isPartialRepo}
- partialResumable={c.partial_resumable}
- selected={isSelected}
- loaded={
- isKeptLoaded(c.repo_id) ||
- isRuntimeLoadedModel(
- loadedModelId,
- activeGgufVariant,
- c.repo_id,
- "required",
- )
- }
- optionProps={hubModelList.getOptionProps(optionKey, isSelected)}
- onClick={() => toggleGgufExpanded(c.repo_id, expanderOpen)}
- onArrowDownIntoChildren={
- expanderOpen
- ? () => focusFirstChildOption(optionKey)
- : undefined
- }
- vramStatus={null}
- className={downloadedRowButtonClassName}
- />
- </div>
- {isPartialRepo ? (
- <span className={ROW_ACTIONS_PINNED_CLASS}>
- <ModelRowMenu
- ariaLabel={`More options for ${onDeviceRepoLabel(c.repo_id)}`}
- cachePath={{ repoId: c.repo_id }}
- del={{
- title: "Delete cached model?",
- impact: { repoId: c.repo_id },
- // Repo-wide delete, which may include a complete copy in another format.
- description: (
- <>
- This will remove{" "}
- <span className="font-medium text-foreground">
- {onDeviceRepoLabel(c.repo_id)}
- </span>{" "}
- and everything downloaded under it from disk. You can
- download it again later.
- </>
- ),
- successMessage: `Deleted ${onDeviceRepoLabel(c.repo_id)}`,
- disabled: deleteDisabled,
- onConfirm: async () => {
- await deleteCachedModel(
- c.repo_id,
- undefined,
- hfToken || undefined,
- c.cache_path || undefined,
- );
- if (isChatGgufTask(c.task)) {
- // Another remembered folder may still hold a pinned quant.
- await reconcileGgufPinsAfterDelete(c.repo_id, hfToken || undefined);
- } else {
- unpinRepo(c.repo_id);
- }
- },
- onDeleted: refreshCachedLists,
- }}
- />
- </span>
- ) : (
- // No chevron until the probe rules out a sole quant. The gutter is a mouse target (the row
- // has the keyboard); pr-2.5 is the heading chevron's column.
- <span className={cn(ROW_ACTIONS_PINNED_CLASS, "h-6")}>
- {soleQuants.pending.has(c.repo_id) ? null : (
- <button
- type="button"
- tabIndex={-1}
- aria-hidden="true"
- onClick={() => toggleGgufExpanded(c.repo_id, expanderOpen)}
- className="flex h-full w-full cursor-pointer items-center justify-end pr-2.5 text-muted-foreground/80 hover:text-foreground"
- >
- <HugeiconsIcon
- icon={
- expanderOpen
- ? ChevronDownStandardIcon
- : ChevronRightStandardIcon
- }
- className="size-3"
- />
- </button>
- )}
- </span>
- )}
- </div>
- {expanderOpen && (
- <GgufVariantExpander
- diffusionLoad={diffusionLoad}
- hostPooledMemory={gpu.loadDeviceSharesHostMemory}
- gpuCount={expanderGpuCount}
- repoId={c.repo_id}
- loadedQuants={loadedQuants}
- pipelineTag={c.task ?? null}
- loadId={c.load_id}
- cachePath={c.cache_path}
- onDevice={true}
- allowPin={true}
- onHasVision={(v) => reportVision(c.repo_id, v)}
- onSelect={onSelect}
- resolveDownloadFootprint={resolveDownloadFootprint}
- onConfigure={onConfigure}
- hfToken={hfToken || undefined}
- parentOptionKey={optionKey}
- onNavigatePastStart={() => hubModelList.focusOption(optionKey)}
- onNavigatePastEnd={() => hubModelList.moveFocus(optionKey, "next")}
- gpuGb={expanderGpuGb}
- systemRamGb={expanderRamGb || undefined}
- budgetKnown={expanderBudgetGpu.budgetKnown}
- variantActions={{
- onUpdate: (quant, expectedBytes) =>
- updateGgufVariant(c.repo_id, quant, expectedBytes),
- updateDisabled: loadedModelId === c.repo_id,
- onDelete: async (quant, cachePath) => {
- await deleteCachedModel(
- c.repo_id,
- quant,
- hfToken || undefined,
- cachePath ??
- (mediaPageForTask(c.task) ? c.cache_path || undefined : undefined),
- );
- prunePinnedQuantValidation(c.repo_id, quant);
- refreshCachedLists();
- },
- }}
- />
- )}
- </div>
+ <DownloadedGgufDeviceRow
+ key={c.repo_id}
+ repo={c}
+ optionKey={optionKey}
+ selected={value === c.repo_id}
+ loaded={
+ isKeptLoaded(c.repo_id) ||
+ isRuntimeLoadedModel(
+ loadedModelId,
+ activeGgufVariant,
+ c.repo_id,
+ "required",
+ )
+ }
+ loadedQuants={loadedQuantsFor(c.repo_id)}
+ showVision={c.has_vision ?? visionByRepo[c.repo_id]}
+ expanderOpen={expanderOpen}
+ soleQuantPending={soleQuants.pending.has(c.repo_id)}
+ updateDisabled={loadedModelId === c.repo_id}
+ expander={deviceExpanderProps}
+ {...deviceRowListProps(optionKey)}
+ />
);
};
const renderDownloadedModelRow = (
c: (typeof visibleCachedModelRows)[number],
) => {
const optionKey = makeModelOptionKey("downloaded-model", c.repo_id);
- const isSelected = value === c.repo_id;
- // A partial pick must not claim downloaded, or the load fails on missing shards.
- const isPartial = c.partial === true;
return (
- <div key={c.repo_id} className={downloadedRowShellClassName(isSelected)}>
- <div className="min-w-0 flex-1">
- <ModelRow
- label={c.repo_id}
- hubUrl={hubRepoUrl(c.repo_id)}
- meta={`${isMlxId(c.repo_id) ? "MLX" : "Safetensors"} · ${formatBytes(
- c.size_bytes,
- )}`}
- selected={isSelected}
- alignMeta="device"
- partial={isPartial}
- partialResumable={c.partial_resumable}
- loaded={
- isKeptLoaded(c.repo_id) ||
- isRuntimeLoadedModel(
- loadedModelId,
- activeGgufVariant,
- c.repo_id,
- "none",
- )
- }
- optionProps={hubModelList.getOptionProps(optionKey, isSelected)}
- onClick={() =>
- onSelect(c.repo_id, {
- source: "hub",
- isLora: false,
- // The Audio route reads a forwarded loadId as proof the weights are there.
- loadId: isPartial ? undefined : c.load_id,
- isDownloaded: !isPartial,
- pipelineTag: c.task ?? null,
- audioType: c.audio_type ?? null,
- familyOverrideRequired: c.opaque === true,
- })
- }
- vramStatus={null}
- className={downloadedRowButtonClassName}
- />
- </div>
- <span
- className={isPartial ? ROW_ACTIONS_PINNED_CLASS : ROW_ACTIONS_CLASS}
- >
- {onConfigure && (
- <ModelLoadSettingsAction
- ariaLabel={`Inference settings for ${c.repo_id}`}
- onConfigure={() =>
- onConfigure(c.repo_id, {
- source: "hub",
- isLora: false,
- // No load identity for an incomplete snapshot.
- loadId: isPartial ? undefined : c.load_id,
- isDownloaded: !isPartial,
- isGguf: false,
- pipelineTag: c.task ?? null,
- audioType: c.audio_type ?? null,
- familyOverrideRequired: c.opaque === true,
- })
- }
- />
- )}
- <ModelRowMenu
- ariaLabel={`More options for ${c.repo_id}`}
- cachePath={{ repoId: c.repo_id }}
- items={ejectMenuItems(c.repo_id)}
- pin={{
- pinned: pinnedSet.has(pinKey(c.repo_id)),
- pinLabel: "Pin",
- unpinLabel: "Unpin",
- onToggle: () => togglePinned(c.repo_id),
- }}
- del={{
- title: "Delete cached model?",
- impact: { repoId: c.repo_id },
- description: (
- <>
- This will remove{" "}
- <span className="font-medium text-foreground">
- {c.repo_id}
- </span>{" "}
- from disk. You can re-download it later.
- </>
- ),
- successMessage: `Deleted ${c.repo_id}`,
- disabled: deleteDisabled,
- onConfirm: async () => {
- await deleteCachedModel(
- c.repo_id,
- undefined,
- hfToken || undefined,
- c.cache_path || undefined,
- );
- // Repo-wide, so quant pins go too.
- unpinRepo(c.repo_id);
- },
- onDeleted: refreshCachedLists,
- }}
- />
- </span>
- </div>
+ <DownloadedModelDeviceRow
+ key={c.repo_id}
+ model={c}
+ optionKey={optionKey}
+ selected={value === c.repo_id}
+ loaded={
+ isKeptLoaded(c.repo_id) ||
+ isRuntimeLoadedModel(
+ loadedModelId,
+ activeGgufVariant,
+ c.repo_id,
+ "none",
+ )
+ }
+ pinned={pinnedSet.has(pinKey(c.repo_id))}
+ ejectable={ejectsKept && isKeptLoaded(c.repo_id)}
+ {...deviceRowListProps(optionKey)}
+ />
);
};
- const renderLocalRowMenu = (m: LocalModelInfo) => {
- const name = m.model_id ?? m.display_name;
+ /** Custom folder, LM Studio and models-directory rows. `directGguf` loads as one file. */
+ const renderLocalDeviceRow = (
+ m: LocalModelInfo,
+ section: string,
+ directGguf: boolean,
+ ) => {
+ const optionKey = makeModelOptionKey(section, m.id);
+ const isGguf = localModelIsGguf(m);
return (
- <ModelRowMenu
- ariaLabel={`More options for ${name}`}
- onReveal={() => revealLocalModel(m.path, m.id)}
- del={
- DELETABLE_LOCAL_SOURCES.has(m.source)
- ? {
- title: "Delete local model?",
- description: (
- <>
- This will permanently remove{" "}
- <span className="font-medium text-foreground">{name}</span>{" "}
- from{" "}
- <span className="break-all font-mono text-xs">{m.path}</span>.
- </>
- ),
- successMessage: `Deleted ${name}`,
- disabled: deleteDisabled,
- onConfirm: () => deleteLocalModel(m.path, m.id),
- onDeleted: refreshLocalModelsList,
- }
- : undefined
+ <LocalModelDeviceRow
+ key={m.id}
+ model={m}
+ optionKey={optionKey}
+ directGguf={directGguf}
+ selected={value === m.id}
+ loaded={isRuntimeLoadedModel(
+ loadedModelId,
+ activeGgufVariant,
+ m.id,
+ // Direct loads set no active variant.
+ directGguf ? "ignore" : isGguf ? "required" : "none",
+ )}
+ expanded={isGgufExpanded(m.id)}
+ loadedQuants={
+ isGguf && !directGguf ? loadedQuantsFor(m.id) : EMPTY_LOADED_QUANTS
}
+ expander={deviceExpanderProps}
+ {...deviceRowListProps(optionKey)}
/>
);
};
@@ -7854,139 +8325,15 @@ export function HubModelPicker({
/>
{!customFoldersCollapsed &&
- sortedCustomFolderModels.map((m) => {
- const isGgufFile = m.path
- .toLowerCase()
- .endsWith(".gguf");
- // Honor the backend model_format hint (suffixless GGUF folders).
- const isGguf = localModelIsGguf(m);
- // An Ollama manifest names one blob, so it loads directly.
- const isDirectGguf =
- isGgufFile || m.source === "ollama";
- const optionKey = makeModelOptionKey(
+ sortedCustomFolderModels.map((m) =>
+ renderLocalDeviceRow(
+ m,
"custom-folder",
- m.id,
- );
- return (
- <div key={m.id}>
- <div
- className={downloadedRowShellClassName(
- value === m.id,
- )}
- >
- <div className="min-w-0 flex-1">
- <ModelRow
- label={m.model_id ?? m.display_name}
- meta={isGguf ? "GGUF" : "Local"}
- tooltipText={localPathTooltip(
- m.model_id ?? m.display_name,
- m.path,
- )}
- selected={value === m.id}
- loaded={isRuntimeLoadedModel(
- loadedModelId,
- activeGgufVariant,
- m.id,
- // Direct loads set no active variant.
- isDirectGguf
- ? "ignore"
- : isGguf
- ? "required"
- : "none",
- )}
- optionProps={hubModelList.getOptionProps(
- optionKey,
- value === m.id,
- )}
- onClick={() => {
- if (isDirectGguf) {
- onSelect(
- m.id,
- localDirectGgufMeta(m.task),
- );
- } else if (isGguf) {
- toggleGgufExpanded(m.id);
- } else {
- onSelect(
- m.id,
- localModelMeta(false, m.task, m.audio_type, m.opaque === true),
- );
- }
- }}
- onArrowDownIntoChildren={
- isGguf &&
- !isDirectGguf &&
- isGgufExpanded(m.id)
- ? () => {
- const focused =
- focusFirstChildOption(optionKey);
- return focused;
- }
- : undefined
- }
- alignMeta="device"
- vramStatus={null}
- className={downloadedRowButtonClassName}
- />
- </div>
- <span className={ROW_ACTIONS_CLASS}>
- {isDirectGguf && onConfigure && (
- <ModelLoadSettingsAction
- ariaLabel={`Inference settings for ${
- m.model_id ?? m.display_name
- }`}
- onConfigure={() =>
- onConfigure(
- m.id,
- localDirectGgufMeta(m.task),
- )
- }
- />
- )}
- {!isGguf && onConfigure && (
- <ModelLoadSettingsAction
- ariaLabel={`Inference settings for ${
- m.model_id ?? m.display_name
- }`}
- onConfigure={() =>
- onConfigure(
- m.id,
- localModelMeta(false, m.task, m.audio_type, m.opaque === true),
- )
- }
- />
- )}
- {renderLocalRowMenu(m)}
- </span>
- </div>
- {isGguf &&
- !isDirectGguf &&
- isGgufExpanded(m.id) && (
- <GgufVariantExpander
- diffusionLoad={diffusionLoad}
- hostPooledMemory={gpu.loadDeviceSharesHostMemory}
- gpuCount={expanderGpuCount}
- repoId={m.id}
- loadedQuants={loadedQuantsFor(m.id)}
- onDevice={true}
- onSelect={onSelect}
- resolveDownloadFootprint={resolveDownloadFootprint}
- onConfigure={onConfigure}
- parentOptionKey={optionKey}
- onNavigatePastStart={() =>
- hubModelList.focusOption(optionKey)
- }
- onNavigatePastEnd={() =>
- hubModelList.moveFocus(optionKey, "next")
- }
- gpuGb={expanderGpuGb}
- systemRamGb={expanderRamGb || undefined}
- budgetKnown={expanderBudgetGpu.budgetKnown}
- />
- )}
- </div>
- );
- })}
+ // An Ollama manifest names one blob, so it loads directly.
+ m.path.toLowerCase().endsWith(".gguf") ||
+ m.source === "ollama",
+ ),
+ )}
{!customFoldersCollapsed &&
showHfSection &&
sortedCustomFolderModels.length === 0 ? (
@@ -8007,130 +8354,13 @@ export function HubModelPicker({
LM Studio
</ListLabel>
{!lmStudioCollapsed &&
- sortedLmStudio.map((m) => {
- const isGgufFile = m.path
- .toLowerCase()
- .endsWith(".gguf");
- // LM Studio dirs rarely carry a -GGUF suffix, so use the shared helper.
- const isGguf = localModelIsGguf(m);
- const optionKey = makeModelOptionKey("lm-studio", m.id);
- return (
- <div key={m.id}>
- <div
- className={downloadedRowShellClassName(
- value === m.id,
- )}
- >
- <div className="min-w-0 flex-1">
- <ModelRow
- label={m.model_id ?? m.display_name}
- meta={isGguf ? "GGUF" : "Local"}
- tooltipText={localPathTooltip(
- m.model_id ?? m.display_name,
- m.path,
- )}
- selected={value === m.id}
- loaded={isRuntimeLoadedModel(
- loadedModelId,
- activeGgufVariant,
- m.id,
- isGgufFile
- ? "ignore"
- : isGguf
- ? "required"
- : "none",
- )}
- optionProps={hubModelList.getOptionProps(
- optionKey,
- value === m.id,
- )}
- onClick={() => {
- if (isGgufFile) {
- onSelect(
- m.id,
- localDirectGgufMeta(m.task),
- );
- } else if (isGguf) {
- toggleGgufExpanded(m.id);
- } else {
- onSelect(
- m.id,
- localModelMeta(false, m.task, m.audio_type, m.opaque === true),
- );
- }
- }}
- onArrowDownIntoChildren={
- isGguf &&
- !isGgufFile &&
- isGgufExpanded(m.id)
- ? () => {
- const focused =
- focusFirstChildOption(optionKey);
- return focused;
- }
- : undefined
- }
- alignMeta="device"
- vramStatus={null}
- className={downloadedRowButtonClassName}
- />
- </div>
- <span className={ROW_ACTIONS_CLASS}>
- {isGgufFile && onConfigure && (
- <ModelLoadSettingsAction
- ariaLabel={`Inference settings for ${
- m.model_id ?? m.display_name
- }`}
- onConfigure={() =>
- onConfigure(
- m.id,
- localDirectGgufMeta(m.task),
- )
- }
- />
- )}
- {!isGguf && onConfigure && (
- <ModelLoadSettingsAction
- ariaLabel={`Inference settings for ${
- m.model_id ?? m.display_name
- }`}
- onConfigure={() =>
- onConfigure(
- m.id,
- localModelMeta(false, m.task, m.audio_type, m.opaque === true),
- )
- }
- />
- )}
- {renderLocalRowMenu(m)}
- </span>
- </div>
- {isGguf && !isGgufFile && isGgufExpanded(m.id) && (
- <GgufVariantExpander
- diffusionLoad={diffusionLoad}
- hostPooledMemory={gpu.loadDeviceSharesHostMemory}
- gpuCount={expanderGpuCount}
- repoId={m.id}
- loadedQuants={loadedQuantsFor(m.id)}
- onDevice={true}
- onSelect={onSelect}
- resolveDownloadFootprint={resolveDownloadFootprint}
- onConfigure={onConfigure}
- parentOptionKey={optionKey}
- onNavigatePastStart={() =>
- hubModelList.focusOption(optionKey)
- }
- onNavigatePastEnd={() =>
- hubModelList.moveFocus(optionKey, "next")
- }
- gpuGb={expanderGpuGb}
- systemRamGb={expanderRamGb || undefined}
- budgetKnown={expanderBudgetGpu.budgetKnown}
- />
- )}
- </div>
- );
- })}
+ sortedLmStudio.map((m) =>
+ renderLocalDeviceRow(
+ m,
+ "lm-studio",
+ m.path.toLowerCase().endsWith(".gguf"),
+ ),
+ )}
</>
) : null}
@@ -8144,126 +8374,14 @@ export function HubModelPicker({
Local models
</ListLabel>
{!localDirCollapsed &&
- sortedLocalDir.map((m) => {
+ sortedLocalDir.map((m) =>
// The variant scanner returns nothing for a config-less loose file, so expanding would dead-end.
- const isGgufFile = m.path
- .toLowerCase()
- .endsWith(".gguf");
- const isGguf = localModelIsGguf(m);
- const optionKey = makeModelOptionKey("local-dir", m.id);
- return (
- <div key={m.id}>
- <div
- className={downloadedRowShellClassName(
- value === m.id,
- )}
- >
- <div className="min-w-0 flex-1">
- <ModelRow
- label={m.model_id ?? m.display_name}
- meta={isGguf ? "GGUF" : "Local"}
- tooltipText={localPathTooltip(
- m.model_id ?? m.display_name,
- m.path,
- )}
- selected={value === m.id}
- loaded={isRuntimeLoadedModel(
- loadedModelId,
- activeGgufVariant,
- m.id,
- isGgufFile
- ? "ignore"
- : isGguf
- ? "required"
- : "none",
- )}
- optionProps={hubModelList.getOptionProps(
- optionKey,
- value === m.id,
- )}
- onClick={() => {
- if (isGgufFile) {
- onSelect(
- m.id,
- localDirectGgufMeta(m.task),
- );
- } else if (isGguf) {
- toggleGgufExpanded(m.id);
- } else {
- onSelect(
- m.id,
- localModelMeta(false, m.task, m.audio_type, m.opaque === true),
- );
- }
- }}
- onArrowDownIntoChildren={
- isGguf &&
- !isGgufFile &&
- isGgufExpanded(m.id)
- ? () => focusFirstChildOption(optionKey)
- : undefined
- }
- alignMeta="device"
- vramStatus={null}
- className={downloadedRowButtonClassName}
- />
- </div>
- <span className={ROW_ACTIONS_CLASS}>
- {isGgufFile && onConfigure && (
- <ModelLoadSettingsAction
- ariaLabel={`Inference settings for ${
- m.model_id ?? m.display_name
- }`}
- onConfigure={() =>
- onConfigure(
- m.id,
- localDirectGgufMeta(m.task),
- )
- }
- />
- )}
- {!isGguf && onConfigure && (
- <ModelLoadSettingsAction
- ariaLabel={`Inference settings for ${
- m.model_id ?? m.display_name
- }`}
- onConfigure={() =>
- onConfigure(
- m.id,
- localModelMeta(false, m.task, m.audio_type, m.opaque === true),
- )
- }
- />
- )}
- {renderLocalRowMenu(m)}
- </span>
- </div>
- {isGguf && !isGgufFile && isGgufExpanded(m.id) && (
- <GgufVariantExpander
- diffusionLoad={diffusionLoad}
- hostPooledMemory={gpu.loadDeviceSharesHostMemory}
- gpuCount={expanderGpuCount}
- repoId={m.id}
- loadedQuants={loadedQuantsFor(m.id)}
- onDevice={true}
- onSelect={onSelect}
- resolveDownloadFootprint={resolveDownloadFootprint}
- onConfigure={onConfigure}
- parentOptionKey={optionKey}
- onNavigatePastStart={() =>
- hubModelList.focusOption(optionKey)
- }
- onNavigatePastEnd={() =>
- hubModelList.moveFocus(optionKey, "next")
- }
- gpuGb={expanderGpuGb}
- systemRamGb={expanderRamGb || undefined}
- budgetKnown={expanderBudgetGpu.budgetKnown}
- />
- )}
- </div>
- );
- })}
+ renderLocalDeviceRow(
+ m,
+ "local-dir",
+ m.path.toLowerCase().endsWith(".gguf"),
+ ),
+ )}
</>
) : null}
diff --git a/studio/frontend/tests/audio-umbrella-on-device-rows.test.ts b/studio/frontend/tests/audio-umbrella-on-device-rows.test.ts
index e2a25551427..b7597c0b233 100644
--- a/studio/frontend/tests/audio-umbrella-on-device-rows.test.ts
+++ b/studio/frontend/tests/audio-umbrella-on-device-rows.test.ts
@@ -140,14 +140,15 @@ test("pickers render folder rows through the label, group, link and menu helpers
PICKERS,
/huggingface\.co\/\$\{audioCppHubPath\(trimmed\) \?\? trimmed\}/,
);
- for (const fn of [
- "const renderSoleQuantGgufRow",
- "const renderDownloadedGgufRow",
- "const renderAdditionalOnDeviceModelRow",
+ // The cached GGUF rows are memoized components; the others are render functions.
+ for (const [fn, end] of [
+ ["const SoleQuantGgufDeviceRow", "\n});\n"],
+ ["const DownloadedGgufDeviceRow", "\n});\n"],
+ ["const renderAdditionalOnDeviceModelRow", "\n };\n"],
]) {
const start = PICKERS.indexOf(fn);
assert.ok(start > 0, fn);
- const body = PICKERS.slice(start, PICKERS.indexOf("\n };\n", start));
+ const body = PICKERS.slice(start, PICKERS.indexOf(end, start));
assert.match(body, /label=\{[^}]*onDeviceRepoLabel\(/, fn);
}
const start = PICKERS.indexOf("const renderAdditionalOnDeviceModelRow");
diff --git a/studio/frontend/tests/gguf-delete-pin-scope.test.ts b/studio/frontend/tests/gguf-delete-pin-scope.test.ts
index e50ae837afd..ebf459f36b5 100644
--- a/studio/frontend/tests/gguf-delete-pin-scope.test.ts
+++ b/studio/frontend/tests/gguf-delete-pin-scope.test.ts
@@ -87,6 +87,13 @@ for (const task of [null, "text-generation", "image-text-to-text", "text-to-imag
reconcileGgufPinsAfterDelete: async (...args: unknown[]) => { reconciliations++; assert.equal(args[1], "hf_fixture_token"); await reconcile(...args); },
onDeleteVariant: async () => {}, deleteCachedModel: async () => {}, deleteCachedDataset: async () => {},
refreshCachedLists: () => {}, prunePinnedQuantValidation: () => {}, setRefreshKey: () => {},
+ // Memoized On Device rows reach the picker's callbacks through its actions holder.
+ actions: {
+ get: () => ({
+ hfToken: "hf_fixture_token", togglePinned, unpinRepo,
+ refreshCachedLists: () => undefined, prunePinnedQuantValidation: () => undefined,
+ }),
+ },
});
await callback();
assert.deepEqual(pinned, !chat && wholeRepo ? [] : [repoId, pinKey(repoId, surviving)]);
diff --git a/studio/frontend/tests/loaded-gguf-quant-marker.test.ts b/studio/frontend/tests/loaded-gguf-quant-marker.test.ts
index 2b355258855..76f668aba0d 100644
--- a/studio/frontend/tests/loaded-gguf-quant-marker.test.ts
+++ b/studio/frontend/tests/loaded-gguf-quant-marker.test.ts
@@ -12,7 +12,10 @@ const picker = readSrc(
test("every quant list and cached GGUF row marks the quant each loaded model runs", () => {
const expanders = picker.match(/<GgufVariantExpander\b/g)?.length ?? 0;
- assert.equal(picker.match(/loadedQuants=\{/g)?.length ?? 0, expanders);
+ // Plus the two memoized On Device rows, which take the list for their expander.
+ assert.equal(picker.match(/loadedQuants=\{/g)?.length ?? 0, expanders + 2);
+ assert.match(picker, /<DownloadedGgufDeviceRow[\s\S]*?loadedQuants=\{loadedQuantsFor\(c\.repo_id\)\}/);
+ assert.match(picker, /<LocalModelDeviceRow[\s\S]*?loadedQuants=\{\s*isGguf && !directGguf \? loadedQuantsFor\(m\.id\) : EMPTY_LOADED_QUANTS\s*\}/);
assert.match(
picker,
/loadedQuants\?\.some\(\(q\) => ggufVariantsMatchForPicker\(q, v\.quant\)\) \? \(\s*<span[^>]*>\s*loaded\s*<\/span>/,
@@ -77,12 +80,14 @@ test("a loaded LoRA adapter keeps its classification in the row's metadata", ()
});
test("an On Device GGUF row with several quants shows a right/down chevron its gutter toggles", () => {
- const start = picker.indexOf("const renderDownloadedGgufRow = (");
+ const render = picker.slice(picker.indexOf("const renderDownloadedGgufRow = ("));
+ assert.match(render, /if \(soleQuant\) return renderSoleQuantGgufRow\(c, soleQuant\);/);
+ assert.match(render, /soleQuantPending=\{soleQuants\.pending\.has\(c\.repo_id\)\}/);
+ const start = picker.indexOf("const DownloadedGgufDeviceRow = memo(");
const row = picker.slice(start, picker.indexOf("<GgufVariantExpander", start));
- assert.match(row, /if \(soleQuant\) return renderSoleQuantGgufRow\(c, soleQuant\);/);
assert.match(
row,
- /\{soleQuants\.pending\.has\(c\.repo_id\) \? null : \(\s*<button[\s\S]*?onClick=\{\(\) => toggleGgufExpanded\(c\.repo_id, expanderOpen\)\}/,
+ /\{soleQuantPending \? null : \(\s*<button[\s\S]*?onClick=\{\(\) =>\s*actions\.get\(\)\.toggleGgufExpanded\(c\.repo_id, expanderOpen\)\s*\}/,
);
assert.match(row, /expanderOpen\s*\?\s*ChevronDownStandardIcon\s*:\s*ChevronRightStandardIcon/);
assert.match(row, /<span className=\{cn\(ROW_ACTIONS_PINNED_CLASS, "h-6"\)\}>/);
diff --git a/studio/frontend/tests/model-picker-device-footprint-identity.test.ts b/studio/frontend/tests/model-picker-device-footprint-identity.test.ts
new file mode 100644
index 00000000000..ff8d6f76bd8
--- /dev/null
+++ b/studio/frontend/tests/model-picker-device-footprint-identity.test.ts
@@ -0,0 +1,65 @@
+// 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 assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import test from "node:test";
+import ts from "@typescript/typescript6";
+
+// The expander refetches companion sizes when the resolver changes identity: a stable forwarder hides that.
+const path = "../src/features/model-picker/components/model-selector/pickers.tsx";
+const source = ts.createSourceFile(
+ path,
+ readFileSync(new URL(path, import.meta.url), "utf8"),
+ ts.ScriptTarget.Latest,
+ true,
+ ts.ScriptKind.TSX,
+);
+
+function visit(node: ts.Node, fn: (node: ts.Node) => void) {
+ fn(node);
+ node.forEachChild((child) => visit(child, fn));
+}
+
+test("every GgufVariantExpander gets the resolver itself, not a stable forwarder", () => {
+ const passed: string[] = [];
+ visit(source, (node) => {
+ if (
+ (ts.isJsxSelfClosingElement(node) || ts.isJsxOpeningElement(node)) &&
+ node.tagName.getText(source) === "GgufVariantExpander"
+ ) {
+ for (const attr of node.attributes.properties) {
+ if (ts.isJsxAttribute(attr) && attr.name.getText(source) === "resolveDownloadFootprint") {
+ const init = attr.initializer;
+ assert.ok(init && ts.isJsxExpression(init) && init.expression);
+ passed.push(init.expression.getText(source));
+ }
+ }
+ }
+ });
+ assert.ok(passed.length >= 3, `expected the expander call sites, found ${passed.length}`);
+ for (const expression of passed) {
+ assert.match(expression, /^(expander\.)?resolveDownloadFootprint$/, expression);
+ }
+});
+
+test("the On Device expander props memo re-keys on the resolver", () => {
+ let found = false;
+ visit(source, (node) => {
+ if (
+ ts.isVariableDeclaration(node) &&
+ node.name.getText(source) === "deviceExpanderProps" &&
+ node.initializer &&
+ ts.isCallExpression(node.initializer)
+ ) {
+ found = true;
+ const deps = node.initializer.arguments[1];
+ assert.ok(deps && ts.isArrayLiteralExpression(deps));
+ assert.ok(
+ deps.elements.some((e) => e.getText(source) === "resolveDownloadFootprint"),
+ deps.getText(source),
+ );
+ }
+ });
+ assert.ok(found, "deviceExpanderProps");
+});
diff --git a/studio/frontend/tests/model-picker-partial-downloads.test.ts b/studio/frontend/tests/model-picker-partial-downloads.test.ts
index 4fb12da4d47..c7cf0d638e6 100644
--- a/studio/frontend/tests/model-picker-partial-downloads.test.ts
+++ b/studio/frontend/tests/model-picker-partial-downloads.test.ts
@@ -368,8 +368,8 @@ test("listing a partial never makes it auto-loadable", () => {
test("a partial GGUF repo carries its own menu, not an empty gutter", () => {
// A partial repo has no complete quant row, so its own row must offer delete and reveal.
- const start = PICKERS.indexOf("const renderDownloadedGgufRow");
- const row = PICKERS.slice(start, PICKERS.indexOf("\n };", start));
+ const start = PICKERS.indexOf("const DownloadedGgufDeviceRow");
+ const row = PICKERS.slice(start, PICKERS.indexOf("\n});", start));
assert.ok(row.includes("const isPartialRepo = c.partial === true;"));
assert.match(
row,
@@ -378,7 +378,7 @@ test("a partial GGUF repo carries its own menu, not an empty gutter", () => {
);
assert.match(
row,
- /\) : \([\s\S]*?<span className=\{cn\(ROW_ACTIONS_PINNED_CLASS, "h-6"\)\}>\s*\{soleQuants\.pending\.has\(c\.repo_id\) \? null : \(/,
+ /\) : \([\s\S]*?<span className=\{cn\(ROW_ACTIONS_PINNED_CLASS, "h-6"\)\}>\s*\{soleQuantPending \? null : \(/,
"and a complete repo's gutter holds only the expand chevron",
);
assert.ok(row.includes("cachePath={{ repoId: c.repo_id }}"), "reveal");
@@ -387,8 +387,8 @@ test("a partial GGUF repo carries its own menu, not an empty gutter", () => {
test("the partial repo delete says it removes the repo, because it does", () => {
// No variant means a whole-repo delete, which may remove other formats too.
- const start = PICKERS.indexOf("const renderDownloadedGgufRow");
- const row = PICKERS.slice(start, PICKERS.indexOf("\n };", start));
+ const start = PICKERS.indexOf("const DownloadedGgufDeviceRow");
+ const row = PICKERS.slice(start, PICKERS.indexOf("\n});", start));
assert.ok(
row.includes("and everything downloaded under it from disk"),
"the copy states the real scope",
@@ -437,7 +437,7 @@ test("a partial pick carries no load identity", () => {
test("configure carries the same rule, because Run replays its metadata", () => {
// onRun spreads this meta back into a select, so a stray loadId would reach the load path.
assert.equal(
- PICKERS.split("onConfigure(c.repo_id, selectMeta)").length - 1,
+ PICKERS.split("actions.get().configure(c.repo_id, selectMeta)").length - 1,
1,
);
const selector = read(
@@ -457,10 +457,10 @@ test("a partial row keeps its buttons on screen instead of hiding them behind ho
),
"the pinned variant exists and is built from the shared one",
);
- const gguf = PICKERS.slice(PICKERS.indexOf("const renderDownloadedGgufRow"));
+ const gguf = PICKERS.slice(PICKERS.indexOf("const DownloadedGgufDeviceRow"));
assert.ok(
gguf
- .slice(0, gguf.indexOf("\n };"))
+ .slice(0, gguf.indexOf("\n});"))
.includes("<span className={ROW_ACTIONS_PINNED_CLASS}>"),
"GGUF partial repo row",
);
diff --git a/studio/frontend/tests/on-device-dot-and-header-alignment.test.ts b/studio/frontend/tests/on-device-dot-and-header-alignment.test.ts
index 6ecb77dc510..d316953967d 100644
--- a/studio/frontend/tests/on-device-dot-and-header-alignment.test.ts
+++ b/studio/frontend/tests/on-device-dot-and-header-alignment.test.ts
@@ -57,10 +57,11 @@ test("the unscoped badge column is sized per list, not to the union of both", ()
assert.ok(PICKERS.includes('badgeDevice: "min-w-min min-[560px]:w-[26px]"'));
assert.ok(PICKERS.includes('badgeWide: "min-w-min min-[560px]:w-[44px]"'));
// The partial mark sits with the name so it does not widen one row's badge slot.
- const gguf = PICKERS.slice(PICKERS.indexOf("const renderDownloadedGgufRow"));
- const row = gguf.slice(0, gguf.indexOf("\n };"));
+ const gguf = PICKERS.slice(PICKERS.indexOf("const DownloadedGgufDeviceRow"));
+ const row = gguf.slice(0, gguf.indexOf("\n});"));
assert.ok(row.includes('alignMeta="device"'));
- assert.ok(row.includes("showVision={c.has_vision"));
+ assert.ok(row.includes("showVision={showVision}"));
+ assert.ok(PICKERS.includes("showVision={c.has_vision ?? visionByRepo[c.repo_id]}"));
assert.ok(row.includes("partial={isPartialRepo}"));
assert.match(
PICKERS,
@@ -113,7 +114,13 @@ test("the parameter chip leads its column, so the modality gap is the cluster's
// Local rows share the downloaded rows' button and shell: same inset, full-width hover.
assert.match(PICKERS, /downloadedRowButtonClassName =\s*"bg-transparent pr-1/);
assert.equal(PICKERS.split('className="pr-1"').length - 1, 0);
- assert.equal(PICKERS.split("{renderLocalRowMenu(m)}").length - 1, 3);
+ // Custom folder, LM Studio and models-directory rows share one row component and its menu.
+ assert.equal(PICKERS.match(/renderLocalDeviceRow\(\s*m,/g)?.length ?? 0, 3);
+ const local = PICKERS.slice(PICKERS.indexOf("const LocalModelDeviceRow = memo("));
+ assert.match(
+ local.slice(0, local.indexOf("\n});")),
+ /<span className=\{ROW_ACTIONS_CLASS\}>[\s\S]*?<ModelRowMenu/,
+ );
});
@@ -251,9 +258,12 @@ test("chat and the Hub answer the fit question with one formula", () => {
);
assert.equal(
PICKERS.split("gpuGb={expanderGpuGb}").length - 1,
- 10,
- "eight expanders and the two quant rows beside them",
+ 6,
+ "four expanders and the two quant rows beside them",
);
+ // The memoized On Device rows' two expanders take the same figure through one props object.
+ assert.ok(PICKERS.includes("gpuGb: expanderGpuGb,"));
+ assert.equal(PICKERS.split("gpuGb={expander.gpuGb}").length - 1, 2);
assert.ok(
HUB_CARD.includes(
"const showFitInfo = !mediaRuntime && (Boolean(gpuGb) || Boolean(systemRamGb));",
@@ -267,9 +277,12 @@ test("chat and the Hub answer the fit question with one formula", () => {
assert.ok(PICKERS.includes("mediaLoad: diffusionLoad,"));
assert.equal(
PICKERS.split("diffusionLoad={diffusionLoad}").length - 1,
- 8,
+ 4,
"every task-scoped expander",
);
+ // And the memoized On Device rows' expanders, through their shared props object.
+ assert.equal(PICKERS.split("diffusionLoad={expander.diffusionLoad}").length - 1, 2);
+ assert.match(PICKERS, /useMemo<DeviceRowExpanderProps>\(\s*\(\) => \(\{\s*diffusionLoad,/);
// On a host pool drop the RAM tier, or the APU window is counted with the RAM it maps.
assert.ok(PICKERS.includes("function mediaRamBudgetGb("));
assert.ok(
@@ -311,9 +324,11 @@ test("chat and the Hub answer the fit question with one formula", () => {
);
assert.equal(
PICKERS.split("gpuCount={expanderGpuCount}").length - 1,
- 8,
+ 4,
"every task-scoped expander counts the scoped inventory",
);
+ assert.ok(PICKERS.includes("gpuCount: expanderGpuCount,"));
+ assert.equal(PICKERS.split("gpuCount={expander.gpuCount}").length - 1, 2);
assert.equal(
PICKERS.split("gpuCount={gpu.deviceCount}").length - 1,
1,
@@ -321,7 +336,7 @@ test("chat and the Hub answer the fit question with one formula", () => {
);
assert.equal(
PICKERS.split("<GgufVariantExpander").length - 1,
- 9,
+ 7,
"and that is every expander there is",
);
// Pass raw devices to gpuSharedHostMemoryGb; pre-folding undercounted multi-socket hosts.
@@ -437,9 +452,11 @@ test("a diffusion model uses its load device's shared-pool verdict", () => {
assert.ok(PICKERS.includes("diffusionLoad ? mediaGgufPickerStatus(fit) : fit"));
assert.equal(
PICKERS.split("hostPooledMemory={gpu.loadDeviceSharesHostMemory}").length - 1,
- 8,
+ 4,
"every task-scoped expander learns the pool kind",
);
+ assert.ok(PICKERS.includes("const hostPooledMemory = gpu.loadDeviceSharesHostMemory;"));
+ assert.equal(PICKERS.split("hostPooledMemory={expander.hostPooledMemory}").length - 1, 2);
});
test("the row tooltip reports the figure the verdict was reached with", () => {
diff --git a/tests/studio/playwright_model_picker_renders.py b/tests/studio/playwright_model_picker_renders.py
new file mode 100644
index 00000000000..597bd268293
--- /dev/null
+++ b/tests/studio/playwright_model_picker_renders.py
@@ -0,0 +1,378 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""Render counts in the chat model picker's On Device tab with 600 models.
+
+Each quant probe answer must re-render only the row it describes, and a search keystroke must not
+re-render every row it leaves in place. Then the rows still work: arrow keys move focus between
+them, a row's menu opens, and a click picks the model. Counts come from a React DevTools hook
+installed before the page loads, using DevTools' rule for which fibers rendered (mounts are not
+counted, only re-renders).
+"""
+
+from __future__ import annotations
+
+import contextlib
+import json
+import os
+import re
+import sys
+from pathlib import Path
+from urllib.parse import parse_qs, urlparse
+
+from playwright.sync_api import (
+ Error as PlaywrightError,
+ TimeoutError as PlaywrightTimeoutError,
+ sync_playwright,
+)
+
+sys.path.insert(0, str(Path(__file__).resolve().parent))
+from _playwright_robust import ( # noqa: E402
+ chromium_launch_args,
+ start_vite,
+ stop_process,
+ wait_for_smoke_page,
+)
+
+PORT = int(os.environ.get("SMOKE_PORT", "5237"))
+_EXTERNAL = os.environ.get("SMOKE_BASE_URL", "").strip().rstrip("/")
+BASE = _EXTERNAL or f"http://127.0.0.1:{PORT}"
+LOCAL = 300
+CACHED = 150
+QUERY = "model-01"
+
+RENDER_COUNTER = r"""
+(() => {
+ window.__renders = null;
+ const nameOf = (fiber) => {
+ const type = fiber.type;
+ if (!type) return null;
+ if (fiber.tag === 0 || fiber.tag === 1 || fiber.tag === 15) return type.displayName || type.name || null;
+ if (fiber.tag === 11) return type.displayName || type.render?.displayName || type.render?.name || null;
+ if (fiber.tag === 14) return type.displayName || type.type?.displayName || type.type?.name || null;
+ return null;
+ };
+ const walk = (fiber, counts) => {
+ // Children that were not cloned this commit were not visited by React.
+ if (fiber.alternate && fiber.alternate.child === fiber.child) return;
+ for (let child = fiber.child; child; child = child.sibling) {
+ const name = nameOf(child);
+ // PerformedWork (1) is set only on fibers whose component function ran this commit.
+ if (name && child.alternate && (child.flags & 1)) counts[name] = (counts[name] || 0) + 1;
+ walk(child, counts);
+ }
+ };
+ window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = {
+ supportsFiber: true,
+ isDisabled: false,
+ renderers: new Map(),
+ inject(renderer) { const id = this.renderers.size + 1; this.renderers.set(id, renderer); return id; },
+ checkDCE() {},
+ onScheduleFiberRoot() {},
+ onCommitFiberUnmount() {},
+ onPostCommitFiberRoot() {},
+ onCommitFiberRoot(_id, root) {
+ if (window.__renders) walk(root.current, window.__renders);
+ },
+ };
+})();
+"""
+
+
+def info(message: str) -> None:
+ print(f"[model-picker-renders] {message}", flush = True)
+
+
+def _local_models() -> dict:
+ models = []
+ for i in range(LOCAL):
+ gguf = i % 2 == 0
+ source = ["models_dir", "lmstudio", "ollama", "custom"][i % 4]
+ models.append(
+ {
+ "id": f"/models/{source}/org{i % 17}/model-{i:04d}" + ("-GGUF" if gguf else ""),
+ "display_name": f"Model {i:04d} {'Q4_K_M' if gguf else 'bf16'}",
+ "path": f"/models/{source}/org{i % 17}/model-{i:04d}",
+ "size_bytes": 1_000_000_000 + i,
+ "model_format": "gguf" if gguf else "safetensors",
+ "runtime": "llama_cpp" if gguf else "transformers",
+ "capabilities": {"can_train": not gguf, "can_chat": True, "can_delete": True},
+ "source": source,
+ "model_id": f"org{i % 17}/model-{i:04d}",
+ "updated_at": 1_760_000_000 + i,
+ "pipeline_tag": "text-generation",
+ }
+ )
+ return {
+ "models_dir": "/models",
+ "hf_cache_dir": "/hf",
+ "lmstudio_dirs": ["/models/lmstudio"],
+ "ollama_dirs": [],
+ "models": models,
+ }
+
+
+def _cached(fmt: str) -> dict:
+ rows = []
+ for i in range(CACHED):
+ repo = f"unsloth/cached-{fmt}-{i:04d}" + ("-GGUF" if fmt == "gguf" else "")
+ rows.append(
+ {
+ "repo_id": repo,
+ "load_id": repo,
+ "model_format": fmt,
+ "size_bytes": 2_000_000_000 + i,
+ "cache_path": f"/hf/models--{repo.replace('/', '--')}",
+ "last_modified": 1_760_000_000 + i,
+ "pipeline_tag": "text-generation",
+ }
+ )
+ return {"cached": rows, "scan_confirmed": True}
+
+
+class MockApi:
+ def __init__(self) -> None:
+ self.bodies = {
+ "/api/auth/status": {
+ "initialized": True,
+ "requires_password_change": False,
+ "login_mode": "single",
+ "full_access": True,
+ },
+ "/api/hub/local": _local_models(),
+ "/api/models/local": _local_models(),
+ "/api/hub/cached-gguf": _cached("gguf"),
+ "/api/hub/cached-models": _cached("safetensors"),
+ "/api/models/list": {"models": [], "default_models": []},
+ "/api/models/loras": {"loras": [], "outputs_dir": "/out"},
+ "/api/hub/hidden-models": {"hidden": []},
+ "/api/chat/threads": {"threads": [], "has_more": False},
+ "/api/chat/projects": {"projects": []},
+ "/api/settings/pinned-models": {"pinned": []},
+ }
+ self.variant_probes = 0
+
+ def handle(self, route) -> None:
+ parsed = urlparse(route.request.url)
+ path = parsed.path
+ if path == "/api/hub/gguf-variants":
+ # One downloaded quant per repo, so every GGUF row turns into a sole-quant row.
+ self.variant_probes += 1
+ repo = parse_qs(parsed.query).get("repo_id", ["x"])[0]
+ return self._json(
+ route,
+ {
+ "repo_id": repo,
+ "variants": [
+ {
+ "filename": "m-Q4_K_M.gguf",
+ "quant": "Q4_K_M",
+ "size_bytes": 4_000_000_000,
+ "downloaded": True,
+ "cache_path": "/hf/x/m-Q4_K_M.gguf",
+ }
+ ],
+ "has_vision": False,
+ "default_variant": "Q4_K_M",
+ "dependencies_resolved": True,
+ },
+ )
+ if path in self.bodies and route.request.method == "GET":
+ return self._json(route, self.bodies[path])
+ route.fulfill(status = 404, content_type = "application/json", body = "{}")
+
+ @staticmethod
+ def _json(route, payload: dict) -> None:
+ route.fulfill(status = 200, content_type = "application/json", body = json.dumps(payload))
+
+
+# Head 750; re-rendering every row per probe answer is tens of thousands.
+SETTLE_BOUND = 3000
+# Rows that move must re-render (their option id carries the position): at most ~400 here.
+TYPING_BOUND = 1500
+
+
+def take_counts(page) -> dict:
+ counts = page.evaluate(
+ "() => { const c = window.__renders; window.__renders = null; return c; }"
+ )
+ # A reload mid-measure (vite re-optimizing dependencies) resets the counter to null.
+ assert counts is not None, "the page reloaded while it was being measured"
+ return counts
+
+
+def wait_quiet(
+ page,
+ *,
+ quiet_ms: int = 1500,
+ limit_ms: int = 60_000,
+) -> None:
+ """Waits until no React commit has rendered a ModelRow for `quiet_ms`."""
+ page.evaluate(
+ """([quiet, limit]) => new Promise((resolve) => {
+ const start = performance.now();
+ let last = -1, since = performance.now();
+ const tick = () => {
+ const now = performance.now();
+ const seen = window.__renders ? (window.__renders.ModelRow || 0) : 0;
+ if (seen !== last) { last = seen; since = now; }
+ if (now - since >= quiet || now - start >= limit) return resolve();
+ setTimeout(tick, 100);
+ };
+ tick();
+ })""",
+ [quiet_ms, limit_ms],
+ )
+
+
+def reload(page) -> None:
+ # Vite's own dependency reload can abort ours; the page still ends up loaded.
+ try:
+ page.reload(timeout = 120_000)
+ except PlaywrightError as error:
+ if "ERR_ABORTED" not in str(error):
+ raise
+ page.wait_for_load_state("load", timeout = 120_000)
+
+
+def open_on_device(page) -> None:
+ page.get_by_text("Select model").first.click()
+ page.get_by_text("On Device").first.click()
+ page.wait_for_function("() => /cached-gguf-0000/.test(document.body.innerText)", timeout = 60_000)
+
+
+def main() -> int:
+ proc = None
+ try:
+ if not _EXTERNAL:
+ proc = start_vite(PORT)
+ wait_for_smoke_page(f"{BASE}/chat", "/src/main.tsx", proc = proc, info = info)
+ with sync_playwright() as playwright:
+ browser = playwright.chromium.launch(headless = True, args = chromium_launch_args())
+ try:
+ api = MockApi()
+ context = browser.new_context(viewport = {"width": 1280, "height": 900})
+ context.add_init_script(
+ "localStorage.setItem('unsloth_auth_token','x.eyJleHAiOjk5OTk5OTk5OTl9.y');"
+ "localStorage.setItem('unsloth_auth_refresh_token','r');"
+ )
+ context.add_init_script(RENDER_COUNTER)
+ context.route(lambda url: urlparse(url).path.startswith("/api/"), api.handle)
+ context.route(
+ "https://huggingface.co/**",
+ lambda route: route.fulfill(
+ status = 200, content_type = "application/json", body = "[]"
+ ),
+ )
+ page = context.new_page()
+ errors: list[str] = []
+ page.on("pageerror", lambda error: errors.append(str(error)))
+
+ # Warm-up, so vite's dependency-optimizing reload cannot land mid-measurement.
+ page.goto(f"{BASE}/chat", timeout = 120_000)
+ for attempt in range(4):
+ try:
+ page.get_by_text("Select model").first.wait_for(timeout = 30_000)
+ break
+ except Exception:
+ # A first load can lose a lazy section to that reload; load it again.
+ if attempt == 3:
+ raise
+ reload(page)
+ open_on_device(page)
+ page.wait_for_timeout(3000)
+ reload(page)
+ page.get_by_text("Select model").first.wait_for(timeout = 120_000)
+ page.wait_for_timeout(2000)
+ api.variant_probes = 0
+
+ page.evaluate("() => { window.__renders = {}; }")
+ open_on_device(page)
+ wait_quiet(page)
+ settle = take_counts(page)
+ rows = page.evaluate(
+ "() => document.querySelectorAll('[data-model-picker-option]').length"
+ )
+
+ # A loaded runner can paint the last quant chips after the render counts go quiet.
+ chip_count = "() => (document.body.innerText.match(/\\bQ4_K_M\\b/g) || []).length"
+ with contextlib.suppress(PlaywrightTimeoutError):
+ page.wait_for_function(f"({chip_count})() >= {CACHED}", timeout = 30_000)
+ chips = page.evaluate(chip_count)
+ search = page.get_by_placeholder("Search").first
+ search.focus()
+ page.evaluate("() => { window.__renders = {}; }")
+ for char in QUERY:
+ page.keyboard.type(char)
+ page.wait_for_timeout(150)
+ wait_quiet(page, quiet_ms = 1000)
+ typing = take_counts(page)
+ matches = page.evaluate(
+ "() => document.querySelectorAll('[data-model-picker-option]').length"
+ )
+ info(
+ json.dumps(
+ {
+ "rows": rows,
+ "variant_probes": api.variant_probes,
+ "settle_ModelRow": settle.get("ModelRow", 0),
+ "settle_ModelRowMenu": settle.get("ModelRowMenu", 0),
+ "typing_ModelRow": typing.get("ModelRow", 0),
+ "typing_ModelRowMenu": typing.get("ModelRowMenu", 0),
+ "matches": matches,
+ "quant_chips": chips,
+ }
+ )
+ )
+ # Fails the run, not the bound, when nothing was there to measure.
+ assert rows >= 2 * LOCAL, f"only {rows} On Device rows rendered"
+ assert (
+ api.variant_probes >= CACHED
+ ), f"only {api.variant_probes} quant probes ran, so the settle measured little"
+ assert chips >= CACHED, f"only {chips} GGUF rows show their sole quant"
+ assert 0 < matches < rows, f"the search left {matches} of {rows} rows"
+
+ # The rows still work: arrows move focus and the active marker, a menu opens.
+ options = page.locator("[data-model-picker-option]")
+ options.nth(0).focus()
+ page.keyboard.press("ArrowDown")
+ page.wait_for_timeout(200)
+ second_id = options.nth(1).get_attribute("id")
+ focused = page.evaluate("() => document.activeElement && document.activeElement.id")
+ assert focused == second_id, f"ArrowDown focused {focused}, not {second_id}"
+ assert options.nth(1).get_attribute("data-model-picker-active-option") == "true"
+ page.keyboard.press("ArrowUp")
+ page.wait_for_timeout(200)
+ first_id = options.nth(0).get_attribute("id")
+ focused = page.evaluate("() => document.activeElement && document.activeElement.id")
+ assert focused == first_id, f"ArrowUp focused {focused}, not {first_id}"
+ page.get_by_role("button", name = re.compile(r"^More options for ")).first.click()
+ page.get_by_role("menuitem").first.wait_for(timeout = 10_000)
+ page.keyboard.press("Escape")
+ page.wait_for_timeout(300)
+ finally:
+ browser.close()
+ # Endpoints this check does not mock answer 404, which the app reports and moves past.
+ unexpected = [error for error in errors if "404" not in error]
+ assert not unexpected, unexpected
+ problems = []
+ if settle.get("ModelRow", 0) > SETTLE_BOUND:
+ problems.append(
+ f"ModelRow re-rendered {settle['ModelRow']} times while {api.variant_probes} "
+ f"quant probes settled (bound {SETTLE_BOUND}): each answer re-renders every row"
+ )
+ if typing.get("ModelRow", 0) > TYPING_BOUND:
+ problems.append(
+ f"ModelRow re-rendered {typing['ModelRow']} times while typing {QUERY!r} "
+ f"(bound {TYPING_BOUND}): each keystroke re-renders every row"
+ )
+ assert not problems, "; ".join(problems)
+ info("ok")
+ return 0
+ finally:
+ if proc is not None:
+ stop_process(proc)
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())
diff --git a/tests/studio/test_model_picker_contracts.py b/tests/studio/test_model_picker_contracts.py
index ed22bc71890..f057cc5cf54 100644
--- a/tests/studio/test_model_picker_contracts.py
+++ b/tests/studio/test_model_picker_contracts.py
@@ -1973,9 +1973,14 @@ def test_chat_picker_routes_diffusion_picks_to_their_page():
assert (
'task === "image-diffusion-unsupported"' in caps
), "the never-loadable tag must stay hidden"
- wrapper = re.search(r"const onSelect = useCallback\(.*?\n \);", src, re.S)
- assert wrapper, "the routing wrapper around onSelect is missing"
- body = wrapper.group(0)
+ # Memoized rows forward onSelect too; the routing wrapper is the one that maps the task.
+ wrappers = [
+ m.group(0)
+ for m in re.finditer(r"const onSelect = useCallback\(.*?\n \);", src, re.S)
+ if "mediaPageForTask" in m.group(0)
+ ]
+ assert wrappers, "the routing wrapper around onSelect is missing"
+ body = wrappers[0]
assert "mediaPageForTask" in body and "navigateToPage" in body
assert "if (!task)" in body
@@ -3171,8 +3176,9 @@ def test_a_multi_quant_parent_row_still_has_no_gear():
Give the parent row a gear and that inference silently inverts."""
pickers = _read("features/model-picker/components/model-selector/pickers.tsx")
# Inside the parent row: a gear added beside the spacer would invert the driver's inference.
- start = pickers.index("const renderDownloadedGgufRow")
- parent = pickers[start : pickers.index("const renderDownloadedModelRow", start)]
+ # The parent row is the memoized DownloadedGgufDeviceRow that renderDownloadedGgufRow mounts.
+ start = pickers.index("const DownloadedGgufDeviceRow = memo(")
+ parent = pickers[start : pickers.index("\n});", start)]
parent_row = parent[: parent.index("{expanderOpen && (")]
# A partial repo puts a row menu in the gutter instead; the gear invariant is about the
# branch that expands, so read that one when the row splits on it.