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: pin fine-tuned models in the model picker (#11984)

Michael Han1aa3421bdd36
diff --git a/studio/backend/models/models.py b/studio/backend/models/models.py
index 8fe54b8952e..0ad298e82b2 100644
--- a/studio/backend/models/models.py
+++ b/studio/backend/models/models.py
@@ -123,6 +123,7 @@ class LoRAInfo(BaseModel):
export_type: Optional[str] = Field(
None, description = "'lora', 'merged', or 'gguf' (for exports)"
)
+ size_bytes: Optional[int] = Field(None, description = "Bytes the model takes on disk")
audio_type: Optional[str] = Field(
None,
description = (
diff --git a/studio/backend/routes/models.py b/studio/backend/routes/models.py
index 073cfbb4cc1..1d4dd57818a 100644
--- a/studio/backend/routes/models.py
+++ b/studio/backend/routes/models.py
@@ -2882,6 +2882,26 @@ async def scan_loras(
)
+def _disk_bytes(model_path: str, export_type: Optional[str]) -> Optional[int]:
+ """Bytes a fine-tune takes on disk. A GGUF export counts its whole folder."""
+ path = Path(model_path)
+ if export_type == "gguf" and path.is_file():
+ path = path.parent
+ try:
+ if path.is_file():
+ return path.stat().st_size
+ total = 0
+ for root, _dirs, files in os.walk(path):
+ for name in files:
+ try:
+ total += os.lstat(os.path.join(root, name)).st_size
+ except OSError:
+ continue
+ return total
+ except OSError:
+ return None
+
+
def _scan_loras_sync(
resolved_outputs_dir: str, resolved_exports_dir: str, hf_token: Optional[str]
) -> List[LoRAInfo]:
@@ -2897,6 +2917,7 @@ def _scan_loras_sync(
base_model = base_model,
source = "training",
export_type = model_type,
+ size_bytes = _disk_bytes(model_path, model_type),
audio_type = _audio_type_of_checkpoint(model_path, base_model, hf_token),
)
)
@@ -2910,6 +2931,7 @@ def _scan_loras_sync(
base_model = base_model,
source = "exported",
export_type = export_type,
+ size_bytes = _disk_bytes(model_path, export_type),
audio_type = _audio_type_of_checkpoint(model_path, base_model, hf_token),
)
)
diff --git a/studio/backend/tests/test_scan_exported_gguf_companions.py b/studio/backend/tests/test_scan_exported_gguf_companions.py
new file mode 100644
index 00000000000..343b9706baa
--- /dev/null
+++ b/studio/backend/tests/test_scan_exported_gguf_companions.py
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""A {run}/{checkpoint}/ GGUF export is keyed by a main GGUF, never by an mmproj or imatrix beside it."""
+
+from pathlib import Path
+
+import pytest
+
+from utils.account_context import OWNER, run_as
+from utils.models import model_config
+from utils.paths import storage_roots
+
+
[email protected](autouse = True)
+def studio(tmp_path, monkeypatch):
+ monkeypatch.setenv("UNSLOTH_STUDIO_HOME", str(tmp_path / "studio"))
+
+
+def _checkpoint(run: str, *files: str) -> Path:
+ checkpoint = run_as(OWNER, storage_roots.exports_root) / run / "checkpoint-1"
+ checkpoint.mkdir(parents = True)
+ for name in files:
+ (checkpoint / name).write_bytes(b"GGUF")
+ return checkpoint
+
+
+def test_two_level_gguf_export_skips_companions():
+ kept = _checkpoint("with-main", "mmproj-F16.gguf", "imatrix.gguf", "model.Q4_K_M.gguf")
+ _checkpoint("companions-only", "mmproj-F16.gguf", "imatrix_unsloth.gguf")
+
+ exported = run_as(OWNER, model_config.scan_exported_models)
+
+ assert [(name, path, kind) for name, path, kind, _base in exported] == [
+ ("with-main / checkpoint-1", str(kept / "model.Q4_K_M.gguf"), "gguf"),
+ ]
diff --git a/studio/backend/utils/models/model_config.py b/studio/backend/utils/models/model_config.py
index 9f4f1bef1fe..8b0179ddc07 100644
--- a/studio/backend/utils/models/model_config.py
+++ b/studio/backend/utils/models/model_config.py
@@ -3654,7 +3654,13 @@ def scan_exported_models(
not is_appledouble_metadata(f)
for f in (*checkpoint_dir.glob("*.safetensors"), *checkpoint_dir.glob("*.bin"))
)
- has_gguf = any(_iter_gguf_files(checkpoint_dir))
+ # Same filter as the flat layout: mmproj and imatrix files are not main models.
+ gguf_list = [
+ f
+ for f in _iter_gguf_files(checkpoint_dir)
+ if not _is_mmproj(f.name) and not _is_imatrix_path(f.name)
+ ]
+ has_gguf = bool(gguf_list)
base_model = None
export_type = None
@@ -3677,7 +3683,6 @@ def scan_exported_models(
pass
elif has_gguf:
export_type = "gguf"
- gguf_list = list(_iter_gguf_files(checkpoint_dir))
# checkpoint_dir first, then run_dir (export.py writes metadata to the top-level dir)
for meta_dir in (checkpoint_dir, run_dir):
export_meta = meta_dir / "export_metadata.json"
@@ -3691,7 +3696,7 @@ def scan_exported_models(
pass
display_name = f"{run_dir.name} / {checkpoint_dir.name}"
- model_path = str(gguf_list[0]) if gguf_list else str(checkpoint_dir)
+ model_path = str(gguf_list[0])
results.append((display_name, model_path, export_type, base_model))
logger.debug(f"Found GGUF export: {display_name}")
continue
diff --git a/studio/frontend/src/features/chat/api/chat-api.ts b/studio/frontend/src/features/chat/api/chat-api.ts
index b487228e8ca..66794c55e4b 100644
--- a/studio/frontend/src/features/chat/api/chat-api.ts
+++ b/studio/frontend/src/features/chat/api/chat-api.ts
@@ -730,6 +730,19 @@ export async function revealCachedModel(
await parseJsonOrThrow<unknown>(response);
}
+/** Reveal a training or exported fine-tune in the OS file manager. */
+export async function revealFineTunedModel(
+ modelPath: string,
+ source: "training" | "exported",
+): Promise<void> {
+ const response = await authFetch("/api/library/items/reveal", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ id: `model:${source}:${modelPath}` }),
+ });
+ await parseJsonOrThrow<unknown>(response);
+}
+
export async function deleteFineTunedModel(args: {
modelPath: string;
source: "training" | "exported";
diff --git a/studio/frontend/src/features/chat/chat-page.tsx b/studio/frontend/src/features/chat/chat-page.tsx
index eac74961702..1898efefc3b 100644
--- a/studio/frontend/src/features/chat/chat-page.tsx
+++ b/studio/frontend/src/features/chat/chat-page.tsx
@@ -3869,6 +3869,7 @@ export function ChatPage({
updatedAt: lora.updatedAt,
source: lora.source,
exportType: lora.exportType,
+ sizeBytes: lora.sizeBytes,
audioType: lora.audioType,
}));
return [...fromLoras, ...localModels];
diff --git a/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts b/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts
index 9b0a3f3baab..d279b6d3381 100644
--- a/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts
+++ b/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts
@@ -526,6 +526,7 @@ function toLoraSummary(lora: {
base_model?: string | null;
source?: "training" | "exported" | null;
export_type?: "lora" | "merged" | "gguf" | null;
+ size_bytes?: number | null;
audio_type?: string | null;
}): ChatLoraSummary {
const idTail = lora.adapter_path.split("/").filter(Boolean).at(-1) ?? "";
@@ -539,6 +540,7 @@ function toLoraSummary(lora: {
updatedAt,
source: lora.source ?? undefined,
exportType: lora.export_type ?? undefined,
+ sizeBytes: lora.size_bytes ?? null,
audioType: lora.audio_type ?? null,
};
}
diff --git a/studio/frontend/src/features/chat/index.ts b/studio/frontend/src/features/chat/index.ts
index d6a54b991f7..9caaa1b508b 100644
--- a/studio/frontend/src/features/chat/index.ts
+++ b/studio/frontend/src/features/chat/index.ts
@@ -27,6 +27,7 @@ export {
notifyChatHistoryUpdated,
removeScanFolder,
revealCachedModel,
+ revealFineTunedModel,
validateModel,
type BrowseFoldersResponse,
type CachedGgufRepo,
diff --git a/studio/frontend/src/features/chat/types/api.ts b/studio/frontend/src/features/chat/types/api.ts
index 65a80227a2e..54886c5a4e8 100644
--- a/studio/frontend/src/features/chat/types/api.ts
+++ b/studio/frontend/src/features/chat/types/api.ts
@@ -34,6 +34,7 @@ export interface BackendLoraInfo {
base_model?: string | null;
source?: "training" | "exported" | null;
export_type?: "lora" | "merged" | "gguf" | null;
+ size_bytes?: number | null;
/** Codec of the checkpoint's base model when it fine-tunes an audio model, else null. */
audio_type?: string | null;
}
diff --git a/studio/frontend/src/features/chat/types/runtime.ts b/studio/frontend/src/features/chat/types/runtime.ts
index 0cdc58f3e83..cf1a3b0ac9b 100644
--- a/studio/frontend/src/features/chat/types/runtime.ts
+++ b/studio/frontend/src/features/chat/types/runtime.ts
@@ -100,6 +100,7 @@ export interface ChatLoraSummary {
updatedAt?: number;
source?: "training" | "exported";
exportType?: "lora" | "merged" | "gguf";
+ sizeBytes?: number | null;
/** Codec when the checkpoint fine-tunes an audio model, else null. */
audioType?: string | null;
}
diff --git a/studio/frontend/src/features/library/store.ts b/studio/frontend/src/features/library/store.ts
index 2cc2b28755c..6ce2bfc86b6 100644
--- a/studio/frontend/src/features/library/store.ts
+++ b/studio/frontend/src/features/library/store.ts
@@ -4,6 +4,7 @@
import { create } from "zustand";
import { AUTH_SESSION_CLEARED_EVENT, getAuthSessionEpoch } from "@/features/auth";
import { deleteFineTunedModel, emitChatAttachmentDeleted } from "@/features/chat";
+import { usePinnedModelsStore } from "@/features/model-picker";
import { translate } from "@/i18n";
import { type GalleryKind, notifyGalleryChanged } from "@/lib/gallery-flags";
import {
@@ -195,6 +196,8 @@ export const useLibraryStore = create<LibraryState>((set, get) => {
source: model.origin,
exportType: model.exportType,
});
+ // The model picker may have it pinned.
+ usePinnedModelsStore.getState().unpinRepo(model.path);
return;
}
await deleteLibraryItem(id, fingerprint);
diff --git a/studio/frontend/src/features/model-picker/components/model-selector/model-row-menu.tsx b/studio/frontend/src/features/model-picker/components/model-selector/model-row-menu.tsx
index 09bed305a6e..1965cb0a6d3 100644
--- a/studio/frontend/src/features/model-picker/components/model-selector/model-row-menu.tsx
+++ b/studio/frontend/src/features/model-picker/components/model-selector/model-row-menu.tsx
@@ -11,7 +11,6 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
-import { usePlatformStore } from "@/config/env";
import { revealCachedModel } from "@/features/chat";
import {
DeleteConfirmDialog,
@@ -21,6 +20,7 @@ import {
subscribeJobListeners,
useDeleteImpact,
} from "@/features/hub";
+import { useRevealLabel } from "@/features/library";
import { toast } from "@/lib/toast";
import { cn } from "@/lib/utils";
import {
@@ -91,6 +91,7 @@ export function ModelRowMenu({
buttonClassName,
iconClassName,
cachePath,
+ onReveal,
pin,
items,
update,
@@ -101,15 +102,16 @@ export function ModelRowMenu({
iconClassName?: string;
/** Enables "Reveal in Finder" for cached repos. */
cachePath?: ModelRowMenuCachePath;
+ /** Enables "Reveal in Finder" for paths outside the cache. */
+ onReveal?: () => Promise<void>;
pin?: ModelRowMenuPin;
/** Extra entries for actions this menu has no shape of its own for. */
items?: readonly ModelRowMenuItem[];
update?: ModelRowMenuUpdate;
del?: ModelRowMenuDelete;
}) {
- const deviceType = usePlatformStore((s) => s.deviceType);
- const revealLabel =
- deviceType === "mac" ? "Reveal in Finder" : "Reveal in Folder";
+ // Null unless this is the owner on the backend's own machine with a file manager.
+ const revealLabel = useRevealLabel();
const [deleteOpen, setDeleteOpen] = useState(false);
const [deleting, setDeleting] = useState(false);
const deleteImpact = useDeleteImpact(
@@ -176,15 +178,20 @@ export function ModelRowMenu({
const cachePathRepoId = cachePath?.repoId;
const cachePathVariant = cachePath?.variant;
const handleReveal = useCallback(() => {
- if (!cachePathRepoId) return;
- revealCachedModel(cachePathRepoId, cachePathVariant).catch((err) => {
+ const reveal = onReveal
+ ? onReveal()
+ : cachePathRepoId
+ ? revealCachedModel(cachePathRepoId, cachePathVariant)
+ : null;
+ reveal?.catch((err) => {
toast.error(
err instanceof Error ? err.message : "Failed to open file manager",
);
});
- }, [cachePathRepoId, cachePathVariant]);
+ }, [onReveal, cachePathRepoId, cachePathVariant]);
- if (!pin && !update && !del && !cachePath && !items?.length) return null;
+ const canReveal = Boolean(revealLabel && (cachePath || onReveal));
+ if (!pin && !update && !del && !canReveal && !items?.length) return null;
return (
<>
@@ -241,7 +248,7 @@ export function ModelRowMenu({
<span>{item.label}</span>
</DropdownMenuItem>
))}
- {cachePath && (
+ {canReveal && (
<DropdownMenuItem
onSelect={(e) => {
e.stopPropagation();
@@ -270,7 +277,7 @@ export function ModelRowMenu({
)}
{del && (
<>
- {(cachePath || pin || update || items?.length) && (
+ {(canReveal || pin || update || items?.length) && (
<DropdownMenuSeparator />
)}
<DropdownMenuItem
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 084e95900ab..08a85039075 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
@@ -25,7 +25,9 @@ import {
listGgufVariants,
listRecommendedFolders,
listScanFolders,
+ listLoras,
removeScanFolder,
+ revealFineTunedModel,
} from "@/features/chat";
import {
chatModelLoaded,
@@ -973,6 +975,21 @@ const META_COLUMN = {
format: "min-[560px]:w-[calc(14px*var(--ui-space-scale,1))]",
} as const;
+const downloadedRowButtonClassName =
+ "bg-transparent pr-1 hover:bg-transparent focus-visible:bg-transparent dark:bg-transparent dark:hover:bg-transparent dark:focus-visible:bg-transparent";
+// Not focus-within: the dots menu returns focus to its trigger on close, so the row stayed lit
+// after the pointer left. A row carrying a memory bar is two lines tall and the shell paints
+// the background, so the radius relaxes with it or the row renders as a stadium.
+const downloadedRowShellClassName = (
+ selected: boolean,
+ hasMemoryBar = false,
+) =>
+ cn(
+ "group flex items-center transition-colors hover:bg-sidebar-accent has-[:focus-visible]:bg-sidebar-accent has-[[data-state=open]]:bg-sidebar-accent",
+ hasMemoryBar ? "rounded-2xl" : "rounded-full",
+ selected && "bg-sidebar-accent",
+ );
+
// One gutter for every row, gear or no gear, so the columns never shift by a button; the
// buttons show on hover or while their menu is open.
const ROW_ACTIONS_CLASS =
@@ -4784,6 +4801,16 @@ export function HubModelPicker({
[visibleCachedModelRows, pinnedSet],
);
+ // Pinned fine-tunes leave the Fine-tuned section; both hide under a task filter.
+ const pinnedFineTunedRows = useMemo(
+ () => (task ? [] : fineTunedRows.filter((m) => pinnedSet.has(pinKey(m.id)))),
+ [task, fineTunedRows, pinnedSet],
+ );
+ const unpinnedFineTunedRows = useMemo(
+ () => fineTunedRows.filter((m) => !pinnedSet.has(pinKey(m.id))),
+ [fineTunedRows, pinnedSet],
+ );
+
const pinnedRows = useMemo(() => {
const rank = makePinRank(pinnedIds);
const rows = [
@@ -4791,16 +4818,24 @@ export function HubModelPicker({
key: pinKey(entry.repoId, entry.quant),
entry,
model: null,
+ fineTuned: null,
})),
...pinnedCachedModelRows.map((model) => ({
key: pinKey(model.repo_id),
entry: null,
model,
+ fineTuned: null,
+ })),
+ ...pinnedFineTunedRows.map((fineTuned) => ({
+ key: pinKey(fineTuned.id),
+ entry: null,
+ model: null,
+ fineTuned,
})),
];
rows.sort((a, b) => rank(a.key) - rank(b.key));
return rows;
- }, [pinnedIds, pinnedQuants, pinnedCachedModelRows]);
+ }, [pinnedIds, pinnedQuants, pinnedCachedModelRows, pinnedFineTunedRows]);
// A repo whose only quant is pinned moves its sole-quant row into Pinned instead of showing
// twice. Multi-quant repos stay, since their row picks the other quants.
@@ -5185,20 +5220,18 @@ export function HubModelPicker({
return keys;
}
- // Pinned rows sit above the Unsloth heading on the On Device tab.
- if (
- section === "downloaded" &&
- cachedReady &&
- !pinnedCollapsed &&
- pinnedRows.length > 0
- ) {
+ // Pinned rows sit above the Unsloth heading on the On Device tab. They render before the
+ // cache scan settles, so their keys do not wait for it either.
+ if (section === "downloaded" && !pinnedCollapsed && pinnedRows.length > 0) {
keys.push(
...pinnedRows.map((row) =>
row.entry
? pinnedSoleQuantRows.has(row.key)
? makeModelOptionKey("downloaded-gguf", row.entry.repoId)
: makeModelOptionKey("pinned-quant", row.key)
- : makeModelOptionKey("downloaded-model", row.model.repo_id),
+ : row.model
+ ? makeModelOptionKey("downloaded-model", row.model.repo_id)
+ : makeModelOptionKey("lora", row.fineTuned.id),
),
);
}
@@ -5270,7 +5303,9 @@ export function HubModelPicker({
// Fine-tuned models sit below downloaded, above custom folders.
if (section === "downloaded" && !fineTunedCollapsed) {
- keys.push(...fineTunedRows.map((m) => makeModelOptionKey("lora", m.id)));
+ keys.push(
+ ...unpinnedFineTunedRows.map((m) => makeModelOptionKey("lora", m.id)),
+ );
}
// Custom folders sit right below the downloaded models on On Device.
@@ -5318,7 +5353,7 @@ export function HubModelPicker({
pinnedCollapsed,
pinnedSoleQuantRows,
downloadedCollapsed,
- fineTunedRows,
+ unpinnedFineTunedRows,
fineTunedCollapsed,
filteredRecommendedIds,
searchRowIds,
@@ -5566,7 +5601,7 @@ export function HubModelPicker({
sortedLmStudio.length === 0 &&
sortedLocalDir.length === 0 &&
// Fine-tuned models are on-device too: do not show the empty state above a non-empty Fine-tuned section.
- fineTunedRows.length === 0;
+ unpinnedFineTunedRows.length === 0;
// Sort dropdown inline right of the section toggle; options depend on the tab and stay visible
// while searching. Fixed width matches the Search Hub button.
@@ -5670,21 +5705,6 @@ export function HubModelPicker({
otherCachedModelRows.length > 0 ||
otherAdditionalOnDeviceModels.length > 0;
- const downloadedRowButtonClassName =
- "bg-transparent pr-1 hover:bg-transparent focus-visible:bg-transparent dark:bg-transparent dark:hover:bg-transparent dark:focus-visible:bg-transparent";
- // Not focus-within: the dots menu returns focus to its trigger on close, so the row stayed lit
- // after the pointer left. A row carrying a memory bar is two lines tall and the shell paints
- // the background, so the radius relaxes with it or the row renders as a stadium.
- const downloadedRowShellClassName = (
- selected: boolean,
- hasMemoryBar = false,
- ) =>
- cn(
- "group flex items-center transition-colors hover:bg-sidebar-accent has-[:focus-visible]:bg-sidebar-accent has-[[data-state=open]]:bg-sidebar-accent",
- hasMemoryBar ? "rounded-2xl" : "rounded-full",
- selected && "bg-sidebar-accent",
- );
-
// A draggable Pinned row: faded while carried, lined where it would land.
const renderPinnedDragRow = (
drag: ReturnType<typeof usePinnedRowDrag>,
@@ -6757,9 +6777,26 @@ export function HubModelPicker({
renderPinnedDragRow(
pinnedDrag,
row.key,
- row.entry
- ? renderPinnedQuantRow(row.entry)
- : renderDownloadedModelRow(row.model),
+ row.entry ? (
+ renderPinnedQuantRow(row.entry)
+ ) : row.model ? (
+ renderDownloadedModelRow(row.model)
+ ) : (
+ <FineTunedRows
+ adapters={[row.fineTuned]}
+ value={value}
+ loadedModelId={loadedModelId}
+ activeGgufVariant={activeGgufVariant}
+ onSelect={onSelect}
+ onConfigure={onConfigure}
+ onModelsChange={onModelsChange}
+ deleteDisabled={deleteDisabled}
+ loraModelList={hubModelList}
+ expandedGguf={expandedGguf}
+ setExpandedGguf={setExpandedGguf}
+ gpu={inferenceGpu}
+ />
+ ),
),
)}
</>
@@ -6937,9 +6974,9 @@ export function HubModelPicker({
</button>
</div>
</div>
- {!fineTunedCollapsed && fineTunedRows.length > 0 && (
+ {!fineTunedCollapsed && unpinnedFineTunedRows.length > 0 && (
<FineTunedRows
- adapters={fineTunedRows}
+ adapters={unpinnedFineTunedRows}
value={value}
loadedModelId={loadedModelId}
activeGgufVariant={activeGgufVariant}
@@ -8083,6 +8120,24 @@ function FineTunedRows({
systemRamAvailableGb: number;
};
}) {
+ const pinnedKeys = usePinnedModelsStore((s) => s.pinned);
+ const togglePinned = usePinnedModelsStore((s) => s.togglePinned);
+ const unpinRepo = usePinnedModelsStore((s) => s.unpinRepo);
+ const replacePinned = usePinnedModelsStore((s) => s.replacePinned);
+ // A GGUF export's id is its first file, so deleting a variant can change or end it.
+ const repinExportedGguf = async (oldId: string) => {
+ const folder = oldId.slice(0, Math.max(oldId.lastIndexOf("/"), oldId.lastIndexOf("\\")));
+ const { loras } = await listLoras();
+ const next = loras.find(
+ (lora) =>
+ lora.source === "exported" &&
+ lora.export_type === "gguf" &&
+ (lora.adapter_path.startsWith(`${folder}/`) ||
+ lora.adapter_path.startsWith(`${folder}\\`)),
+ );
+ if (!next) unpinRepo(oldId);
+ else replacePinned(pinKey(oldId), pinKey(next.adapter_path));
+ };
return (
<>
{adapters.map((adapter) => {
@@ -8138,11 +8193,15 @@ function FineTunedRows({
: tag;
return (
<div key={adapter.id}>
- <div className="group flex items-center">
+ <div className={downloadedRowShellClassName(value === adapter.id)}>
<div className="min-w-0 flex-1">
<ModelRow
label={adapter.name}
- meta={meta}
+ meta={
+ adapter.sizeBytes
+ ? `${meta} · ${formatBytes(adapter.sizeBytes)}`
+ : meta
+ }
selected={value === adapter.id}
loaded={isRuntimeLoadedModel(
loadedModelId,
@@ -8184,6 +8243,7 @@ function FineTunedRows({
: undefined
}
alignMeta="device"
+ className={downloadedRowButtonClassName}
/>
</div>
<span className={ROW_ACTIONS_CLASS}>
@@ -8193,31 +8253,51 @@ function FineTunedRows({
onConfigure={() => onConfigure(adapter.id, selectionMeta)}
/>
)}
- {canDelete && (
- <ModelDeleteAction
- ariaLabel={`Delete ${adapter.name}`}
- title="Delete fine-tuned model?"
- description={
- <>
- This will remove{" "}
- <span className="font-medium text-foreground">
- {adapter.name}
- </span>{" "}
- from disk. This cannot be undone.
- </>
- }
- successMessage={`Deleted ${adapter.name}`}
- disabled={deleteDisabled}
- onConfirm={() =>
- deleteFineTunedModel({
- modelPath: adapter.id,
- source: isExported ? "exported" : "training",
- exportType: adapter.exportType,
- })
- }
- onDeleted={() => onModelsChange?.({ id: adapter.id })}
- />
- )}
+ <ModelRowMenu
+ ariaLabel={`More options for ${adapter.name}`}
+ pin={{
+ pinned: pinnedKeys.includes(pinKey(adapter.id)),
+ pinLabel: "Pin to top",
+ unpinLabel: "Unpin",
+ onToggle: () => togglePinned(adapter.id),
+ }}
+ onReveal={
+ isLocal
+ ? undefined
+ : () =>
+ revealFineTunedModel(
+ adapter.id,
+ isExported ? "exported" : "training",
+ )
+ }
+ del={
+ canDelete
+ ? {
+ title: "Delete fine-tuned model?",
+ description: (
+ <>
+ This will remove{" "}
+ <span className="font-medium text-foreground">
+ {adapter.name}
+ </span>{" "}
+ from disk. This cannot be undone.
+ </>
+ ),
+ successMessage: `Deleted ${adapter.name}`,
+ disabled: deleteDisabled,
+ onConfirm: async () => {
+ await deleteFineTunedModel({
+ modelPath: adapter.id,
+ source: isExported ? "exported" : "training",
+ exportType: adapter.exportType,
+ });
+ unpinRepo(adapter.id);
+ },
+ onDeleted: () => onModelsChange?.({ id: adapter.id }),
+ }
+ : undefined
+ }
+ />
</span>
</div>
{expandedGguf === adapter.id && (
@@ -8257,6 +8337,10 @@ function FineTunedRows({
exportType: "gguf",
ggufVariant: quant,
});
+ if (pinnedKeys.includes(pinKey(adapter.id))) {
+ // If the rescan fails, drop the pin rather than leave it pointing at a gone file.
+ await repinExportedGguf(adapter.id).catch(() => unpinRepo(adapter.id));
+ }
onModelsChange?.({
id: adapter.id,
ggufVariant: quant,
diff --git a/studio/frontend/src/features/model-picker/components/model-selector/pinned-models.ts b/studio/frontend/src/features/model-picker/components/model-selector/pinned-models.ts
index 13e389c7579..0c667d24841 100644
--- a/studio/frontend/src/features/model-picker/components/model-selector/pinned-models.ts
+++ b/studio/frontend/src/features/model-picker/components/model-selector/pinned-models.ts
@@ -108,6 +108,8 @@ interface PinnedModelsState {
* with it, and a `repoId::quant` pin outlives the row that showed it: nothing lists it, so
* nothing can unpin it, and it reappears the day that quant is downloaded again. */
unpinRepo: (repoId: string) => void;
+ /** Move a pin to a new key in the same slot, or drop it if the new key is already pinned. */
+ replacePinned: (fromKey: string, toKey: string) => void;
/**
* Move `fromKey` into `toKey`'s slot. Both keys must already be pinned;
* anything else is a no-op. Outside a drag session the new order is
@@ -144,6 +146,15 @@ export const usePinnedModelsStore = create<PinnedModelsState>((set) => ({
writePinned(next);
return { pinned: next };
}),
+ replacePinned: (fromKey, toKey) =>
+ set((state) => {
+ if (!state.pinned.includes(fromKey) || fromKey === toKey) return state;
+ const next = state.pinned.includes(toKey)
+ ? state.pinned.filter((key) => key !== fromKey)
+ : state.pinned.map((key) => (key === fromKey ? toKey : key));
+ writePinned(next);
+ return { pinned: next };
+ }),
movePinned: (fromKey, toKey) =>
set((state) => {
const from = state.pinned.indexOf(fromKey);
diff --git a/studio/frontend/src/features/model-picker/components/model-selector/types.ts b/studio/frontend/src/features/model-picker/components/model-selector/types.ts
index 8cdadfb2579..e5e4ad33013 100644
--- a/studio/frontend/src/features/model-picker/components/model-selector/types.ts
+++ b/studio/frontend/src/features/model-picker/components/model-selector/types.ts
@@ -32,6 +32,7 @@ export interface LoraModelOption extends ModelOption {
/** This local GGUF is one directly loadable artifact, not a repo whose quant variants must be listed first. */
isDirectGguf?: boolean;
exportType?: "lora" | "merged" | "gguf";
+ sizeBytes?: number | null;
/** Codec when the checkpoint fine-tunes an audio model, else null. */
audioType?: string | null;
}
diff --git a/studio/frontend/tests/library-state.test.ts b/studio/frontend/tests/library-state.test.ts
index 0de1d10070b..05d760f8d61 100644
--- a/studio/frontend/tests/library-state.test.ts
+++ b/studio/frontend/tests/library-state.test.ts
@@ -180,6 +180,8 @@ test("the next account's edit does not wait behind one the account that left nev
type Item = { id: string; name: string; favorite: boolean; folderId: string | null };
+const unpinned: string[] = [];
+
function loadStore(
api: Record<string, unknown>,
emitted: unknown[] = [],
@@ -206,6 +208,11 @@ function loadStore(
deleteFineTunedModel: async () => {},
emitChatAttachmentDeleted: (event: unknown) => emitted.push(event),
},
+ "@/features/model-picker": {
+ usePinnedModelsStore: {
+ getState: () => ({ unpinRepo: (repoId: string) => unpinned.push(repoId) }),
+ },
+ },
"@/i18n": { translate: (key: string) => key },
"@/lib/gallery-flags": { notifyGalleryChanged: () => {} },
"./api": { errorMessage: String, ...api },
@@ -349,6 +356,20 @@ test("a sandbox file is deleted as the file it was listed as", async () => {
assert.deepEqual(deleted, [["sandbox:t:a.png", "7:1.5"]]);
});
+test("deleting a fine-tune also drops its model picker pin", async () => {
+ const path = "/exports/run/checkpoint-1";
+ const store = loadStore({
+ getLibrary: async () => ({
+ items: [{ ...item(`model:exported:${path}`), model: { path, origin: "exported", exportType: "merged" } }],
+ folders: [],
+ }),
+ });
+ await store.getState().refresh();
+ unpinned.length = 0;
+ await store.getState().removeItem(`model:exported:${path}`);
+ assert.deepEqual(unpinned, [path]);
+});
+
test("deleting a chat attachment tells an open chat to drop it", async () => {
const emitted: unknown[] = [];
const store = loadStore(
diff --git a/studio/frontend/tests/pinned-models-reorder.test.ts b/studio/frontend/tests/pinned-models-reorder.test.ts
index b6392d9f660..eac6ff8b2fe 100644
--- a/studio/frontend/tests/pinned-models-reorder.test.ts
+++ b/studio/frontend/tests/pinned-models-reorder.test.ts
@@ -561,3 +561,26 @@ test("both repo-level deletes clear pins through that one action", async () => {
),
);
});
+
+// A GGUF export's id is its first file, so a variant delete can move it: the pin follows in place.
+test("replacePinned moves a pin to its new key in the same slot", () => {
+ setPinned(["a", "/exports/run-gguf/x.Q4_K_M.gguf", "b"]);
+ usePinnedModelsStore
+ .getState()
+ .replacePinned("/exports/run-gguf/x.Q4_K_M.gguf", "/exports/run-gguf/x.Q8_0.gguf");
+ assert.deepEqual(usePinnedModelsStore.getState().pinned, [
+ "a",
+ "/exports/run-gguf/x.Q8_0.gguf",
+ "b",
+ ]);
+ assert.deepEqual(storedPinned(), usePinnedModelsStore.getState().pinned);
+ // Already pinned under the new key: the old one just goes.
+ setPinned(["a", "b", "c"]);
+ usePinnedModelsStore.getState().replacePinned("a", "c");
+ assert.deepEqual(usePinnedModelsStore.getState().pinned, ["b", "c"]);
+ // Not pinned: nothing changes.
+ setPinned(["a"]);
+ usePinnedModelsStore.getState().replacePinned("z", "y");
+ assert.deepEqual(usePinnedModelsStore.getState().pinned, ["a"]);
+ assert.equal(storedPinned(), null);
+});