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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Ask one formula whether a GGUF fits (#10029)
Michael Hanfe76559950a5
diff --git a/studio/frontend/src/features/hub/catalog/download-section.tsx b/studio/frontend/src/features/hub/catalog/download-section.tsxindex 3c914415a8b..31b32646ea0 100644--- a/studio/frontend/src/features/hub/catalog/download-section.tsx+++ b/studio/frontend/src/features/hub/catalog/download-section.tsx@@ -21,6 +21,7 @@ export function DownloadSection({preferredGgufFileIntent = 0,isLoadingThisModel,gpuGb,+ gpuCount,systemRamGb,cachePath,knownBytes,@@ -30,6 +31,7 @@ export function DownloadSection({onTrain,onChange,showMemoryBar = true,+ mediaRuntime = false,}: {repoId: string;isGguf: boolean;@@ -46,6 +48,7 @@ export function DownloadSection({preferredGgufFileIntent?: number;isLoadingThisModel: boolean;gpuGb?: number;+ gpuCount?: number;systemRamGb?: number;cachePath?: string | null;knownBytes?: number | null;@@ -57,6 +60,7 @@ export function DownloadSection({/** False for diffusion / audio / video GGUFs, which do not load through* llama.cpp and so have nothing the KV estimator can say about them. */showMemoryBar?: boolean;+ mediaRuntime?: boolean;}) {if (isGguf || preferredGgufFile) {return (@@ -69,6 +73,7 @@ export function DownloadSection({preferredFileIntent={preferredGgufFileIntent}isLoadingThisModel={isLoadingThisModel}gpuGb={gpuGb}+ gpuCount={gpuCount}systemRamGb={systemRamGb}cachePath={cachePath}isPartial={isPartial}@@ -77,6 +82,7 @@ export function DownloadSection({onEject={onEject}onChange={onChange}showMemoryBar={showMemoryBar}+ mediaRuntime={mediaRuntime}/>);}diff --git a/studio/frontend/src/features/hub/catalog/gguf-download-card.tsx b/studio/frontend/src/features/hub/catalog/gguf-download-card.tsxindex 3f1ce494424..d73cfdaac42 100644--- a/studio/frontend/src/features/hub/catalog/gguf-download-card.tsx+++ b/studio/frontend/src/features/hub/catalog/gguf-download-card.tsx@@ -110,15 +110,18 @@ const FIT_BADGE: Record<GgufFitClass, FitBadgeMeta> = {iconClassName: "text-emerald-600 dark:text-emerald-400",},marginal: {- label: "Might fit",+ label: "Over budget",+ // Not conditional on other apps: _vram_usable_mib gives free - reserve, which on an idle card+ // is exactly the budget this tier has already passed, so the load takes --fit every time.+ // Same words the chat picker uses.tooltip:- "Might fit. Within the last GB of VRAM headroom, so loading can fail if other apps are using GPU memory.",+ "Larger than your VRAM Budget allows, so part of it offloads even on an idle GPU. It is still smaller than the card, so raising the budget can keep it resident.",iconClassName: "text-amber-600 dark:text-amber-400",},partial: {label: "Partial offload",tooltip:- "Partial offload possible. Exceeds VRAM but fits with system RAM offload. Inference will be slower.",+ "Model may not fit but still works with offloading. Expect slower inference.",iconClassName: "text-sky-600 dark:text-sky-400",},ram: {@@ -128,8 +131,11 @@ const FIT_BADGE: Record<GgufFitClass, FitBadgeMeta> = {iconClassName: "text-sky-600 dark:text-sky-400",},oom: {- label: "Won't fit",- tooltip: "Exceeds combined VRAM and system RAM budget.",+ label: "Does not fit",+ // Not "won't fit": llama-server never refuses a GGUF on size, it hands it to --fit. Same words+ // the chat picker uses, where this class and `partial` share one mark.+ tooltip:+ "Model may not fit but still works with offloading. Expect slower inference.",iconClassName: "text-rose-600 dark:text-rose-400",},};@@ -250,7 +256,12 @@ interface GgufVariantMenuItem {function createGgufVariantMenuItems(variants: readonly GgufVariantDetail[] | null,- resources: { gpuGb?: number; systemRamGb?: number; budgetFraction?: number },+ resources: {+ gpuGb?: number;+ gpuCount?: number;+ systemRamGb?: number;+ budgetFraction?: number;+ },): GgufVariantMenuItem[] {if (!variants) return [];return variants.map((variant) => ({@@ -551,6 +562,7 @@ export function GgufDownloadCard({preferredFileIntent = 0,isLoadingThisModel,gpuGb,+ gpuCount,systemRamGb,cachePath,preferLocalCache = false,@@ -559,6 +571,7 @@ export function GgufDownloadCard({onEject,onChange,showMemoryBar = true,+ mediaRuntime = false,}: {repoId: string;isActive: boolean;@@ -568,6 +581,8 @@ export function GgufDownloadCard({preferredFileIntent?: number;isLoadingThisModel: boolean;gpuGb?: number;+ /** GPUs gpuGb sums, for the loader's per-card VRAM reserve. */+ gpuCount?: number;systemRamGb?: number;cachePath?: string | null;preferLocalCache?: boolean;@@ -584,6 +599,11 @@ export function GgufDownloadCard({* weights-only verdict anyway, which is a confident number about the wrong* runtime. The picker suppresses these rows for the same reason. */showMemoryBar?: boolean;+ /** This repo is placed by the diffusion planner, not llama-server. Suppresses the fit badges+ * for the same reason it suppresses the memory bar: the budget and the offload rules here are+ * llama.cpp's, and an oversized diffusion model gets told it "still works with offloading"+ * when on a host pool the planner refuses the load outright. */+ mediaRuntime?: boolean;}) {const hfToken = useHfTokenStore((s) => s.token);const online = useOnlineStatus();@@ -635,10 +655,11 @@ export function GgufDownloadCard({if (!variants) return null;return sortDownloadableGgufVariants(variants, {gpuGb,+ gpuCount,systemRamGb,budgetFraction,});- }, [variants, gpuGb, systemRamGb, budgetFraction]);+ }, [variants, gpuGb, gpuCount, systemRamGb, budgetFraction]);const selectLiveGgufVariantStates = useMemo(() => createLiveGgufVariantStatesSelector(repoId),[repoId],@@ -663,10 +684,11 @@ export function GgufDownloadCard({() =>createGgufVariantMenuItems(sortedVariants, {gpuGb,+ gpuCount,systemRamGb,budgetFraction,}),- [gpuGb, sortedVariants, systemRamGb, budgetFraction],+ [gpuGb, gpuCount, sortedVariants, systemRamGb, budgetFraction],);const selectedQuant =@@ -758,17 +780,20 @@ export function GgufDownloadCard({!downloadingThisVariant &&!isLoadingThisModel &&!selectedIsActive;- const showFitInfo = Boolean(gpuGb) || Boolean(systemRamGb);+ // No verdict beats a wrong one: a media repo's fit is the diffusion planner's question, and+ // this card only knows how to answer llama.cpp's. The picker still badges those rows.+ const showFitInfo = !mediaRuntime && (Boolean(gpuGb) || Boolean(systemRamGb));const selectedFit = useMemo(() =>selected? classifyGgufFit(selected.size_bytes, {gpuGb,+ gpuCount,systemRamGb,budgetFraction,}): null,- [gpuGb, selected?.size_bytes, systemRamGb, budgetFraction],+ [gpuGb, gpuCount, selected?.size_bytes, systemRamGb, budgetFraction],);const selectedDownloadSizeLabel = selected? ggufVariantTransferLabel(selected)diff --git a/studio/frontend/src/features/hub/catalog/local-on-device-card.tsx b/studio/frontend/src/features/hub/catalog/local-on-device-card.tsxindex 6e21ed59d90..9a66c9366c5 100644--- a/studio/frontend/src/features/hub/catalog/local-on-device-card.tsx+++ b/studio/frontend/src/features/hub/catalog/local-on-device-card.tsx@@ -105,6 +105,8 @@ interface LocalOnDeviceCardProps {preferredFileIntent?: number;gpuGb?: number;+ /** GPUs gpuGb sums, for the loader's per-card VRAM reserve. */+ gpuCount?: number;systemRamGb?: number;unsupportedReason?: string | null;onLoad: (opts?: LocalLoadOptions) => void;@@ -238,6 +240,7 @@ export function LocalOnDeviceCard({preferredFileIntent = 0,gpuGb,+ gpuCount,systemRamGb,unsupportedReason,onLoad,@@ -356,6 +359,7 @@ export function LocalOnDeviceCard({defaultVariant: currentVariantState.defaultVariant,activeGgufVariant: isActive ? activeGgufVariant : null,gpuGb,+ gpuCount,systemRamGb,budgetFraction,})@@ -366,6 +370,7 @@ export function LocalOnDeviceCard({isActive,activeGgufVariant,gpuGb,+ gpuCount,systemRamGb,budgetFraction,],diff --git a/studio/frontend/src/features/hub/catalog/model-inspector.tsx b/studio/frontend/src/features/hub/catalog/model-inspector.tsxindex 2ce54f7a020..0265ca9765a 100644--- a/studio/frontend/src/features/hub/catalog/model-inspector.tsx+++ b/studio/frontend/src/features/hub/catalog/model-inspector.tsx@@ -396,6 +396,8 @@ export type ModelInspectorRuntime = {status: "fits" | "tight" | "exceeds";} | null;gpuGb?: number;+ /** GPUs gpuGb sums, for the loader's per-card VRAM reserve. */+ gpuCount?: number;systemRamGb?: number;};@@ -443,6 +445,7 @@ export const ModelInspector = memo(function ModelInspector({minMemory,vramInfo,gpuGb,+ gpuCount,systemRamGb,} = runtime;const {@@ -730,6 +733,7 @@ export const ModelInspector = memo(function ModelInspector({isLoading={isLoadingThisModel}loadingPhase={loadingPhase}gpuGb={gpuGb}+ gpuCount={gpuCount}systemRamGb={systemRamGb}preferredFile={preferredGgufFile}@@ -751,6 +755,7 @@ export const ModelInspector = memo(function ModelInspector({) : (<DownloadSectionshowMemoryBar={!runsOnMediaRuntime}+ mediaRuntime={runsOnMediaRuntime}repoId={model.isLocal ? (model.hubRepoId ?? model.id) : model.id}isGguf={model.isGguf}isDownloaded={model.isDownloaded}@@ -766,6 +771,7 @@ export const ModelInspector = memo(function ModelInspector({preferredGgufFileIntent={preferredGgufFileIntent}isLoadingThisModel={isLoadingThisModel}gpuGb={gpuGb}+ gpuCount={gpuCount}systemRamGb={systemRamGb}cachePath={model.path}knownBytes={model.cachedBytes}diff --git a/studio/frontend/src/features/hub/hub-page.tsx b/studio/frontend/src/features/hub/hub-page.tsxindex 010752acd24..286e2fa57cf 100644--- a/studio/frontend/src/features/hub/hub-page.tsx+++ b/studio/frontend/src/features/hub/hub-page.tsx@@ -22,6 +22,7 @@ import {applyPerModelConfigToRuntime,currentRuntimePerModelConfig,hfModelFitsDevice,+ loadScopedGpu,resolveInitialConfig,useActiveModelConfig,} from "@/features/model-picker";@@ -30,6 +31,7 @@ import { taskForMediaPick } from "@/features/model-picker/components/model-selecimport { diffusionRouteSearch } from "@/lib/diffusion-route-search";import { useDebouncedValue } from "@/hooks/use-debounced-value";import { useGpuInfo, useInferenceGpuInfo } from "@/hooks/use-gpu-info";+import { useVramBudgetFraction } from "@/hooks/use-vram-budget-fraction";import { toast } from "@/lib/toast";import { cn } from "@/lib/utils";import { useNavigate, useSearch } from "@tanstack/react-router";@@ -70,6 +72,7 @@ import { useFeedWriteBack } from "./hooks/use-feed-write-back";import { useHiddenEmbeddingModelIds } from "./hooks/use-hidden-embedding-models";import { useHubFeed } from "./hooks/use-hub-feed";import type {+ HfModelResult,HfModelSearchChannel,HfSortDirection,HfSortKey,@@ -373,7 +376,31 @@ function selectedRepoMatchesRuntime(export function ModelsPage() {const navigate = useNavigate();const gpu = useGpuInfo();+ // The saved VRAM Budget the loader admits against. The "Fits on device" filter scored against+ // the 0.97 default without it, so lowering the setting moved the badges and not the filter.+ const budgetFraction = useVramBudgetFraction() ?? undefined;const inferenceGpu = useInferenceGpuInfo();+ // One fit answer for every Hub row, picked the way the task pickers pick it: by the runtime that+ // PLACES the row. An image or video repo goes to the diffusion planner, on one torch device,+ // under the media rule, so judging it by llama.cpp's budget kept a 52 GiB media GGUF that clears+ // 62.1 GiB on a 64 GiB Mac and blows the planner's 44.8. Everything else keeps the GGUF+ // backend's own inventory, which is the one thing llama.cpp rows must be judged against.+ const rowFitsDevice = useCallback(+ (result: HfModelResult) => {+ const mediaRow = studioPageForTask(result.pipelineTag) !== undefined;+ const source = loadScopedGpu(+ mediaRow || !result.isGguf ? gpu : inferenceGpu,+ mediaRow,+ );+ return hfModelFitsDevice(result, source, {+ budgetFraction,+ gpuCount: source.deviceCount,+ mediaLoad: mediaRow,+ hostPooledMemory: gpu.loadDeviceSharesHostMemory,+ });+ },+ [budgetFraction, gpu, inferenceGpu],+ );// Browser reachability, which is what every client here asks about: the// selected model's metadata and the cached feed each issue their own request.// On the discovery phase they would stay blocked at "probing" until a@@ -894,12 +921,10 @@ export function ModelsPage() {// Models already on disk stay visible regardless of device fit, matching the chat selector.(!fitOnDeviceOnly ||row.isAvailableOnDevice ||- hfModelFitsDevice(- row.result,- row.result.isGguf ? inferenceGpu : gpu,- )),+ rowFitsDevice(row.result)),);}, [+ rowFitsDevice,discoverRows,hiddenEmbeddingModelIds,isDatasetMode,@@ -908,8 +933,6 @@ export function ModelsPage() {deferredCapabilityFilter,activeChannel,fitOnDeviceOnly,- gpu,- inferenceGpu,]);const listRows = filteredDiscoverRows;@@ -939,9 +962,11 @@ export function ModelsPage() {(row) =>!fitOnDeviceOnly ||row.isAvailableOnDevice ||- hfModelFitsDevice(row.result, inferenceGpu),+ rowFitsDevice(row.result),),[+ budgetFraction,+ rowFitsDevice,hubFeed.trending.results,hiddenEmbeddingModelIds,modelDiscoveryInventorySignature,@@ -1659,6 +1684,7 @@ export function ModelsPage() {minMemory,vramInfo,gpuGb: inferenceGpu.available ? inferenceGpu.memoryTotalGb : undefined,+ gpuCount: inferenceGpu.deviceCount,systemRamGb:inferenceGpu.systemRamAvailableGb > 0? inferenceGpu.systemRamAvailableGb@@ -1673,6 +1699,7 @@ export function ModelsPage() {vramInfo,inferenceGpu.available,inferenceGpu.memoryTotalGb,+ inferenceGpu.deviceCount,inferenceGpu.systemRamAvailableGb,],);diff --git a/studio/frontend/src/features/hub/lib/gguf-variant-sort.ts b/studio/frontend/src/features/hub/lib/gguf-variant-sort.tsindex c26f0263671..34e9557b56d 100644--- a/studio/frontend/src/features/hub/lib/gguf-variant-sort.ts+++ b/studio/frontend/src/features/hub/lib/gguf-variant-sort.ts@@ -12,6 +12,9 @@ type GgufVariantResources = {/** The saved VRAM Budget, so the sort ranks against the line the loader will* actually admit at rather than against the default. */budgetFraction?: number;+ /** GPUs gpuGb sums, so the sort charges the loader's per-card VRAM reserve as+ * many times as the loader does. */+ gpuCount?: number;};export function ggufVariantDisplayLabel(diff --git a/studio/frontend/src/features/model-picker/components/model-selector/model-catalog.check.ts b/studio/frontend/src/features/model-picker/components/model-selector/model-catalog.check.tsindex e165e3e8e01..8f226c78907 100644--- a/studio/frontend/src/features/model-picker/components/model-selector/model-catalog.check.ts+++ b/studio/frontend/src/features/model-picker/components/model-selector/model-catalog.check.ts@@ -20,9 +20,11 @@ import {catalogGroupFitsDevice,catalogToModelOptions,classifyGgufFit,+ classifyMediaGgufFit,curatedArtifactFitsDevice,curatedDisplayNameFor,curatedRowLabelFor,+ ggufFitRuns,groupForRepoId,groupMatchesQuery,loadSpecFor,@@ -464,14 +466,90 @@ assert.equal(// ── classifyGgufFit ────────────────────────────────────────────────────────────const GB = 1024 ** 3;+// Delegated to lib/gguf-fit, the formula the Hub badge uses: 0.97 of the card (or the saved VRAM+// Budget) against weights + KV, then RAM offload at 0.5. The rule here used to be 0.7 of each+// against the raw file size, which matched neither the Hub nor the loader.assert.equal(classifyGgufFit(10 * GB, { gpuGb: 24, systemRamGb: 64 }), "fits");-assert.equal(classifyGgufFit(20 * GB, { gpuGb: 24, systemRamGb: 64 }), "tight");+// 20 GiB needs 24.0: past the 23.28 budget, still inside the 24 GiB card.+assert.equal(classifyGgufFit(20 * GB, { gpuGb: 24, systemRamGb: 64 }), "marginal");+// 40 GiB needs 47.0: past the card, inside card + RAM offload.+assert.equal(classifyGgufFit(40 * GB, { gpuGb: 24, systemRamGb: 64 }), "partial");assert.equal(classifyGgufFit(100 * GB, { gpuGb: 24, systemRamGb: 64 }), "oom");// Unknown device: never scare with OOM.assert.equal(classifyGgufFit(100 * GB, { gpuGb: 0, systemRamGb: 0 }), "fits");-// Unified-memory host (no GPU budget): fit-or-oom against RAM.-assert.equal(classifyGgufFit(30 * GB, { gpuGb: 0, systemRamGb: 64 }), "fits");+// No GPU at all: RAM alone, at the 0.5 offload share.+assert.equal(classifyGgufFit(20 * GB, { gpuGb: 0, systemRamGb: 64 }), "ram");assert.equal(classifyGgufFit(60 * GB, { gpuGb: 0, systemRamGb: 64 }), "oom");+// The saved VRAM Budget moves the line. The old rule ignored the setting entirely, so lowering it+// changed the Hub's verdict and left the picker's untouched.+assert.equal(+ classifyGgufFit(16 * GB, { gpuGb: 24, systemRamGb: 0, budgetFraction: 0.97 }),+ "fits",+);+assert.equal(+ classifyGgufFit(16 * GB, { gpuGb: 24, systemRamGb: 0, budgetFraction: 0.8 }),+ "marginal",+);+// At the top of the slider the loader still keeps its 512 MiB floor (_VRAM_FLOOR_RESERVE_MIB), so+// a 20 GiB quant needing 24.0 GiB is handed to --fit rather than admitted. `gpuGb * fraction` said+// otherwise, and the whole point of this file is that the badge matches _select_gpus.+assert.equal(+ classifyGgufFit(20 * GB, { gpuGb: 24, systemRamGb: 0, budgetFraction: 1 }),+ "marginal",+);+// The floor never exceeds the default budget's own reserve, so 0.97 is unchanged by it.+assert.equal(+ classifyGgufFit(19 * GB, { gpuGb: 24, systemRamGb: 0, budgetFraction: 0.97 }),+ "fits",+);+// The floor is charged once per CARD: _select_gpus calls _vram_usable_mib for every device and+// sums, so two 24 GiB cards at 1.0 offer 47.0 GiB, not 47.5. A 40.2 GiB file needs 47.23.+assert.equal(+ classifyGgufFit(40.2 * GB, {+ gpuGb: 48,+ systemRamGb: 0,+ budgetFraction: 1,+ gpuCount: 2,+ }),+ "marginal",+);+// Same file, same cards, counted as one box: the verdict this correction exists to remove.+assert.equal(+ classifyGgufFit(40.2 * GB, { gpuGb: 48, systemRamGb: 0, budgetFraction: 1 }),+ "fits",+);+// Below the default the percentage term still wins on either count, so nothing moves.+for (const gpuCount of [1, 2, 4]) {+ assert.equal(+ classifyGgufFit(39 * GB, {+ gpuGb: 48,+ systemRamGb: 0,+ budgetFraction: 0.97,+ gpuCount,+ }),+ "fits",+ );+}++// ── classifyMediaGgufFit ──────────────────────────────────────────────────────+// Images / Video place a GGUF through the diffusion backend, whose budget on a 64 GiB unified host+// is (total - 20% reserve) * 0.85 = 43.5 GiB (diffusion_memory.py). This rule allows 44.8; the+// llama.cpp one allows 62.1 and would promise loads the planner refuses.+assert.equal(classifyMediaGgufFit(40 * GB, 64, 0), "fits"); // 40 <= 44.8+assert.equal(classifyMediaGgufFit(50 * GB, 64, 0), "oom"); // past 44.8, no RAM tier+// The same 50 GiB file reads as fitting under the llama.cpp rule, which is the regression this+// guard exists to prevent: 50 * 1.15 + 1 = 58.5 <= 64 * 0.97.+assert.equal(classifyGgufFit(50 * GB, { gpuGb: 64, systemRamGb: 0 }), "fits");+// A discrete card with RAM keeps the offload tier the rule always had.+assert.equal(classifyMediaGgufFit(20 * GB, 24, 64), "partial");+assert.equal(classifyMediaGgufFit(100 * GB, 24, 64), "oom");+// No GPU: RAM alone, fit or not.+assert.equal(classifyMediaGgufFit(30 * GB, 0, 64), "fits");+assert.equal(classifyMediaGgufFit(60 * GB, 0, 64), "oom");++// Only oom fails to load; marginal and partial both run.+assert.equal(ggufFitRuns("partial"), true);+assert.equal(ggufFitRuns("oom"), false);// ── pickDefaultQuant ───────────────────────────────────────────────────────────diff --git a/studio/frontend/src/features/model-picker/components/model-selector/model-catalog.ts b/studio/frontend/src/features/model-picker/components/model-selector/model-catalog.tsindex c3fe7204fb2..106fa25da75 100644--- a/studio/frontend/src/features/model-picker/components/model-selector/model-catalog.ts+++ b/studio/frontend/src/features/model-picker/components/model-selector/model-catalog.ts@@ -4,6 +4,10 @@// One canonical name per diffusion model, its published artifacts (GGUF quants, prequant FP8 / bnb-4bit repos, official BF16 pipelines), and a deterministic router picking the best artifact for the device.// Pure helpers, no React/DOM deps. See model-catalog.check.ts (`npm run catalog:check`).+import {+ type GgufFitClass,+ classifyGgufFit as classifyGgufFitForDevice,+} from "../../../../lib/gguf-fit.ts";import {type HostClass,curatedArtifactIsOfferable,@@ -944,21 +948,58 @@ export interface DeviceBudget {gpuGb: number;/** Available system RAM in GB (for the GGUF offload tier). */systemRamGb: number;+ /** The user's saved VRAM Budget. Absent falls back to the loader's default. */+ budgetFraction?: number;+ /** GPUs gpuGb sums, for the loader's per-card VRAM reserve. Absent means one. */+ gpuCount?: number;}-/** GGUF fit classification matching llama-server _select_gpus: fits = model <= 0.7 * GPU; tight = fits with 0.7 * RAM offload; oom = neither. */+/** GGUF fit, delegated to the one formula the Hub badge already uses.+ *+ * This used to carry its own rule (0.7 * GPU + 0.7 * RAM, raw file size) whose comment claimed to+ * match `_select_gpus`. It did not: the loader admits against `_active_vram_fraction()`, the saved+ * VRAM Budget or 0.97, over weights PLUS estimated KV cache. 0.7 appeared nowhere in the backend,+ * so chat hid quants the loader would have taken and ignored the budget setting entirely. */export function classifyGgufFit(sizeBytes: number,budget: DeviceBudget,-): "fits" | "tight" | "oom" {- const gpuBudgetGb = (budget.gpuGb || 0) * 0.7;- const totalBudgetGb = gpuBudgetGb + (budget.systemRamGb || 0) * 0.7;- if (totalBudgetGb <= 0) return "fits";+): GgufFitClass {+ // Nothing measured, so a verdict would be invented. Callers that know the budget really is zero+ // (a probed Vulkan device) decide that for themselves.+ if ((budget.gpuGb || 0) <= 0 && (budget.systemRamGb || 0) <= 0) return "fits";+ if (sizeBytes <= 0) return "fits";+ return classifyGgufFitForDevice(sizeBytes, budget);+}++/** Fit rule for a GGUF the IMAGES / VIDEO / AUDIO pickers offer, which is the one case the shared+ * llama.cpp formula must not judge: those loads go through the diffusion backend, whose budget is+ * free memory minus a reserve at a 0.85 margin (`diffusion_memory.py`, `_reserve_mib` is 20% on+ * unified memory), and which explicitly cannot offload there. On a 64 GiB Mac that planner allows+ * about 43.5 GiB where llama.cpp allows 62.1. This rule, the picker's own from before the+ * classifiers were merged, allows 44.8, so it is the closer of the two by 18 GiB.+ *+ * It is not the diffusion planner either. It is here so unifying chat's verdict with the Hub's+ * does not quietly promise media loads that cannot be placed; a real diffusion predicate is its+ * own change. */+export function classifyMediaGgufFit(+ sizeBytes: number,+ gpuGb: number,+ systemRamGb: number,+): GgufFitClass {+ const gpuBudgetGb = gpuGb * 0.7;+ const totalBudgetGb = gpuBudgetGb + systemRamGb * 0.7;const gb = sizeBytes / 1024 ** 3;if (gb <= 0 || gb <= gpuBudgetGb) return "fits";if (gpuBudgetGb <= 0) return gb <= totalBudgetGb ? "fits" : "oom";- if (gb <= totalBudgetGb) return "tight";- return "oom";+ // "partial", where this rule used to say "tight": the state it describes is a spill out of the+ // card, which is what partial means. Tight now means a full GPU load with no room to spare.+ return gb <= totalBudgetGb ? "partial" : "oom";+}++/** Whether a verdict still loads. Only `oom` clears neither budget; `marginal` and `partial` run,+ * the second by offloading to CPU. */+export function ggufFitRuns(fit: GgufFitClass): boolean {+ return fit !== "oom";}export interface QuantVariant {@@ -975,22 +1016,23 @@ export function pickDefaultQuant(budget: DeviceBudget,): QuantVariant | null {if (!variants || variants.length === 0) return null;- const totalBudgetGb =- (budget.gpuGb || 0) * 0.7 + (budget.systemRamGb || 0) * 0.7;+ const anyBudget = (budget.gpuGb || 0) > 0 || (budget.systemRamGb || 0) > 0;+ const runs = (v: QuantVariant) =>+ ggufFitRuns(classifyGgufFit(v.size_bytes, budget));const downloadedFitting = variants- .filter((v) => v.downloaded && classifyGgufFit(v.size_bytes, budget) !== "oom")+ .filter((v) => v.downloaded && runs(v)).sort((a, b) => b.size_bytes - a.size_bytes);if (downloadedFitting.length > 0) return downloadedFitting[0];const byQuant = (quant: string | null) =>quant ? (variants.find((v) => v.quant === quant) ?? null) : null;// No budget knowledge at all: trust the repo default.- if (totalBudgetGb <= 0) return byQuant(defaultVariant) ?? variants[0];+ if (!anyBudget) return byQuant(defaultVariant) ?? variants[0];const defaultV = byQuant(defaultVariant);- if (defaultV && classifyGgufFit(defaultV.size_bytes, budget) !== "oom") {+ if (defaultV && runs(defaultV)) {return defaultV;}const fitting = variants- .filter((v) => classifyGgufFit(v.size_bytes, budget) !== "oom")+ .filter(runs).sort((a, b) => b.size_bytes - a.size_bytes);if (fitting.length > 0) return fitting[0];const smallest = [...variants].sort((a, b) => a.size_bytes - b.size_bytes);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.tsxindex aeb55c88165..008a4ca29c2 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@@ -73,7 +73,9 @@ import {type ModelMemorySource,useModelMemory,} from "@/hooks/use-model-memory";+import { useVramBudgetFraction } from "@/hooks/use-vram-budget-fraction";import { diffusionRouteSearch } from "@/lib/diffusion-route-search";+import { type GgufFitClass, requiredGgufMemoryGb } from "@/lib/gguf-fit";import { extractParamLabel } from "@/lib/model-size";import { toast } from "@/lib/toast";import { cn, formatCompact } from "@/lib/utils";@@ -142,6 +144,8 @@ import {type CatalogGroup,type DeviceBudget,artifactForRepoId,+ classifyGgufFit,+ classifyMediaGgufFit,curatedArtifactFitsDevice,curatedCapabilitiesFor,curatedRowLabelFor,@@ -168,7 +172,6 @@ import {import {type FormatFilter,estimateQuantBytes,- fitsDevice,hfModelFitsDevice,isMlxId,isMobileVariant,@@ -632,67 +635,124 @@ function DownloadedBadge() {);}-/** What each fit verdict marks and says. Tight spills past VRAM into system RAM; oom clears- * neither budget, so it offloads further still. Both still run, so neither reads as an error:- * orange over red, and yellow one step below it. */+interface FitVerdict {+ label: string;+ tone: string;+ hint: string;+}+const AMBER = "!text-yellow-600 dark:!text-yellow-400";const ORANGE = "!text-orange-600 dark:!text-orange-300";-/** Two vocabularies reach this badge and they do not mean the same thing.+/** Over budget but still card-sized. `_select_gpus` scores against FREE VRAM, so whether this+ * lands on the GPU depends on what else is resident; missing it costs speed, not the load. */+/** Over the VRAM Budget, still smaller than the card. Not conditional: `_vram_usable_mib` gives+ * `free - reserve`, which on a completely idle card IS the budget this tier has already passed,+ * so `_select_gpus` hands it to --fit every time. Other apps only shrink `free` further. Raising+ * the budget is the lever that keeps it resident, which is why the card size is worth saying. */+const MIGHT_FIT: FitVerdict = {+ label: "Over budget",+ tone: AMBER,+ hint: "Larger than your VRAM Budget allows, so part of it offloads even on an idle GPU. It is still smaller than the card, so raising the budget can keep it resident.",+};+/** Past the card. Every GGUF over budget lands here, however far over, because llama-server never+ * refuses one on size: `_select_gpus` returns `(None, use_fit=True)` and `--fit` offloads the+ * rest to CPU. Splitting this by how far over only mattered on hosts where the RAM tier exists,+ * and it cost the honest answer on the ones where it does not. */+const OFFLOADS: FitVerdict = {+ label: "Does not fit",+ tone: ORANGE,+ hint: "Model may not fit but still works with offloading. Expect slower inference.",+};+/** checkVramFit's 75-100% band, which is the ONLY source of `tight` here: a torch estimate that+ * still fits on the card entirely. It has no --fit, so it neither spills nor offloads. */+const DEVICE_TIGHT: FitVerdict = {+ label: "Tight fit",+ tone: AMBER,+ hint: "Uses nearly all your VRAM, with little headroom for anything else.",+};+/** A torch load, which has no --fit to fall back on: the pipeline goes wholly on the device. */+const WONT_FIT: FitVerdict = {+ label: "Does not fit",+ tone: ORANGE,+ // "memory", not "VRAM": this also carries a diffusion refusal on a shared pool, where the two+ // are the same bytes and calling it VRAM would read as a different number than the user has.+ hint: "Needs more memory than this device has. This model will not load.",+};++/** What each fit verdict marks and says, keyed by the Hub's classes so one question has one+ * vocabulary. `tight` and `exceeds` are the training estimator's words and reach here ONLY from a+ * torch pipeline or the QLoRA estimate, never from a GGUF, so both describe a load with no --fit+ * to fall back on. That is why neither says anything about offloading. */+const VRAM_VERDICT: Record<GgufFitClass | VramFitStatus, FitVerdict | null> = {+ fits: null,+ marginal: MIGHT_FIT,+ tight: DEVICE_TIGHT,+ partial: OFFLOADS,+ ram: {+ label: "RAM fallback",+ tone: ORANGE,+ hint: "No GPU detected. Runs on system RAM and CPU. Expect much slower inference.",+ },+ oom: OFFLOADS,+ exceeds: WONT_FIT,+};++/** Whether a diffusion `oom` is a REFUSAL rather than an offload.*- * A VARIANT row's verdict comes from the GGUF classifier: `tight` is a spill out of VRAM into- * system RAM, `exceeds` clears neither budget.+ * On discrete VRAM an oversized pipeline still loads: `diffusion_memory.py` degrades it to group+ * or whole-module CPU offload and streams from host RAM. On a shared pool there is nowhere to+ * stream from, so `unified_memory_shortfall_message` refuses up front, and the docstring is blunt+ * about why: without the refusal the load "allocates past physical memory", with no torch OOM to+ * catch because the MPS high-watermark is disabled, so "the failure is the OS killing the process+ * with no Python exception".*- * A MODEL row's comes from `checkVramFit`, where `tight` is 75-100% of VRAM, which still fits on- * the card entirely. Telling that row it spills into system RAM was simply false, and it is the- * common case on a normal GPU. */-const VRAM_VERDICT = {- gguf: {- exceeds: {- label: "Does not fit",- tone: ORANGE,- hint: "Model may not fit but still works with offloading. Expect slower inference.",- },- tight: {- label: "Tight fit",- tone: AMBER,- hint: "Only fits by spilling into system RAM. Expect slower inference.",- },- },- device: {- // A model row's `exceeds` is a GGUF repo whose smallest quant is over budget (llama-server- // offloads it) OR a curated pipeline that cannot offload at all. One string covers both only- // by promising nothing about which happens; the two are separated in the follow-up.- exceeds: {- label: "Does not fit",- tone: ORANGE,- hint: "Needs more memory than this device has.",- },- tight: {- label: "Tight fit",- tone: AMBER,- hint: "Uses nearly all your VRAM, with little headroom for anything else.",- },- },-} as const;+ * Telling that user the model "still works with offloading" is the worst thing this badge could+ * say, so a diffusion oom on a host pool takes the verdict that means it will not load.+ *+ * `hostPooled` is the LOAD DEVICE's answer, and folds unified_memory in: hardware.py sets+ * shared_memory only on Windows, so a Linux ROCm APU arrives as unified true / shared false while+ * `diffusion_memory.py` still classifies it `unified_memory` and refuses. Reading the aggregate+ * shared flag missed that host, and reading a plain some(unified) would refuse on a discrete card+ * that merely sits beside an iGPU. */+function diffusionRefuses(+ fit: GgufFitClass,+ diffusionLoad: boolean,+ hostPooled: boolean,+): boolean {+ return fit === "oom" && diffusionLoad && hostPooled;+}++/** The RAM a DIFFUSION verdict may add to the GPU budget. Zero on a host pool: offload there+ * moves bytes inside the one pool and frees nothing, so `classifyMediaGgufFit` adding a RAM tier+ * promised an offload the planner refuses. llama.cpp is not this case -- a GGUF really does spill+ * into whatever host RAM the GPU window does not already cover, and `systemRamAvailableGb` now+ * has that window subtracted out. */+function mediaRamBudgetGb(systemRamGb: number, hostPooled: boolean): number {+ return hostPooled ? 0 : systemRamGb;+}++/** The verdicts that read as over budget, which is what dims a row. `marginal` does not: it is+ * a full GPU load, just without much room to spare. */+function isOverBudget(status?: GgufFitClass | VramFitStatus | null): boolean {+ return (+ status === "partial" ||+ status === "ram" ||+ status === "oom" ||+ status === "exceeds"+ );+}/** VRAM verdict: an info mark that names itself on hover, rather than a shouted pill. */function VramBadge({status,- /** Which vocabulary `status` is spoken in. See VRAM_VERDICT: the same word means different- * things on a model row and on a quant row. */- source,/** Model rows hold the mark in the layout and paint it on hover; variant rows always show it. */revealOnHover = false,}: {- status?: VramFitStatus | null;- source: "gguf" | "device";+ status?: GgufFitClass | VramFitStatus | null;revealOnHover?: boolean;}) {- const verdict =- status === "exceeds" || status === "tight"- ? VRAM_VERDICT[source][status]- : null;+ const verdict = status ? VRAM_VERDICT[status] : null;if (!verdict) return null;return (<Tooltip delayDuration={0}>@@ -912,7 +972,7 @@ function ModelRow({/** Override badge state when authoritative runtime state is available. */loaded?: boolean;onClick: () => void;- vramStatus?: VramFitStatus | null;+ vramStatus?: GgufFitClass | VramFitStatus | null;vramEst?: number;gpuGb?: number;tooltipText?: ReactNode;@@ -947,14 +1007,17 @@ function ModelRow({memory?: ModelMemorySource;className?: string;}) {- const exceeds = vramStatus === "exceeds";+ const exceeds = isOverBudget(vramStatus);const showVramTooltip =vramEst != null && vramEst > 0 && gpuGb != null && gpuGb > 0;const vramTooltipText =showVramTooltip && vramStatus? exceeds- ? `Needs ~${vramEst}GB VRAM (GPU: ${gpuGb}GB)`- : vramStatus === "tight"+ ? // "memory", not "VRAM": every over-budget verdict here is a total. A GGUF at+ // `partial` splits across VRAM and RAM, and the figure is weights plus activations+ // plus KV, so "Needs ~47GB VRAM" contradicted the offload verdict beside it.+ `Needs ~${vramEst}GB memory (GPU: ${gpuGb}GB)`+ : vramStatus === "tight" || vramStatus === "marginal"? `~${vramEst}GB VRAM (tight fit on ${gpuGb}GB)`: `~${vramEst}GB VRAM`: null;@@ -1129,10 +1192,10 @@ function ModelRow({META_COLUMN.vram,)}>- <VramBadge status={vramStatus} source="device" revealOnHover={!selected} />+ <VramBadge status={vramStatus} revealOnHover={!selected} /></span>) : (- <VramBadge status={vramStatus} source="device" revealOnHover={!selected} />+ <VramBadge status={vramStatus} revealOnHover={!selected} />)}{aligned ? (<span@@ -1449,9 +1512,20 @@ function GgufVariantExpander({onDevice = false,allowPin = false,onHasVision,+ diffusionLoad = false,+ hostPooledMemory = false,+ gpuCount,}: {repoId: string;pipelineTag?: string | null;+ /** True on Images / Video, where a GGUF is placed by the diffusion backend rather than+ * llama-server, so the llama.cpp budget does not apply. Audio is task-scoped but not this. */+ diffusionLoad?: boolean;+ /** The LOAD DEVICE's memory is a window into host RAM (Apple Silicon, a ROCm APU). Only a+ * diffusion load reads it: see `diffusionRefuses`. */+ hostPooledMemory?: boolean;+ /** How many GPUs gpuGb is the sum of, for the loader's per-card VRAM reserve. */+ gpuCount?: number;/** Snapshot the cached listing pinned this repo to, if any. */loadId?: string | null;/** Cache directory this downloaded row represents, if any. */@@ -1608,27 +1682,40 @@ function GgufVariantExpander({],);- // GGUF fit classification matching llama-server's _select_gpus logic:- // fits = model <= 0.7 * total GPU memory- // tight = model > 0.7 * GPU but <= 0.7 * GPU + 0.7 * system RAM (--fit uses CPU offload)- // oom = model > 0.7 * GPU + 0.7 * system RAM- const gpuBudgetGb = (gpuGb ?? 0) * 0.7;- const totalBudgetGb = gpuBudgetGb + (systemRamGb ?? 0) * 0.7;+ // The user's saved VRAM Budget, which is what the loader admits against. The picker used to+ // ignore it, so moving the slider changed the Hub's verdicts and left chat's untouched.+ const budgetFraction = useVramBudgetFraction() ?? undefined;+ const anyBudgetGb = (gpuGb ?? 0) > 0 || (systemRamGb ?? 0) > 0;const getGgufFit = useCallback(- (sizeBytes: number): "fits" | "tight" | "oom" => {- // Preserve permissive behavior only when no budget was measured. A known- // zero Vulkan budget means every non-empty variant is OOM.- if (totalBudgetGb <= 0) return budgetKnown ? "oom" : "fits";- const gb = sizeBytes / 1024 ** 3;- if (gb <= 0 || gb <= gpuBudgetGb) return "fits";- // No-GPU / unified-memory hosts (Mac) have only the RAM budget, so the tier- // collapses to fit-or-oom against system RAM.- if (gpuBudgetGb <= 0) return gb <= totalBudgetGb ? "fits" : "oom";- if (gb <= totalBudgetGb) return "tight";- return "oom";+ (sizeBytes: number): GgufFitClass => {+ // Permissive only when no budget was measured. A known zero Vulkan budget means every+ // non-empty variant is OOM, which classifyGgufFit cannot tell apart from "not probed yet".+ if (!anyBudgetGb) return budgetKnown ? "oom" : "fits";+ if (diffusionLoad) {+ return classifyMediaGgufFit(+ sizeBytes,+ gpuGb ?? 0,+ mediaRamBudgetGb(systemRamGb ?? 0, hostPooledMemory),+ );+ }+ return classifyGgufFit(sizeBytes, {+ gpuGb: gpuGb ?? 0,+ systemRamGb: systemRamGb ?? 0,+ budgetFraction,+ gpuCount,+ });},- [budgetKnown, gpuBudgetGb, totalBudgetGb],+ [+ budgetKnown,+ anyBudgetGb,+ gpuGb,+ systemRamGb,+ budgetFraction,+ diffusionLoad,+ hostPooledMemory,+ gpuCount,+ ],);const variantGroups = useMemo(@@ -1646,7 +1733,7 @@ function GgufVariantExpander({const recommended = new Map<string, string>();for (const group of variantGroups) {const preferred = preferredByGroup.get(group.key) ?? null;- if (totalBudgetGb <= 0 && !budgetKnown) {+ if (!anyBudgetGb && !budgetKnown) {if (preferred) recommended.set(group.key, preferred.quant);continue;}@@ -1667,7 +1754,7 @@ function GgufVariantExpander({if (smallest) recommended.set(group.key, smallest.quant);}return recommended;- }, [variantGroups, preferredByGroup, totalBudgetGb, budgetKnown, getGgufFit]);+ }, [variantGroups, preferredByGroup, anyBudgetGb, budgetKnown, getGgufFit]);// The same recommendations, reachable from a row. `effectiveRecommendedByGroup`// is keyed by PRESENTATION group ("quantizations", "text-frames",// "reference-media"); the footprint pass below buckets by the backend's@@ -1943,7 +2030,6 @@ function GgufVariantExpander({effectiveRecommendedByGroup.get(group.key) === v.quant;const fit = getGgufFit(v.size_bytes);const oom = fit === "oom";- const tight = fit === "tight";const expectedBytes = ggufVariantExpectedBytes(v);// This row's own dependency group, never the listing's: see the// footprintVariants comment above.@@ -2002,8 +2088,11 @@ function GgufVariantExpander({</span><span className="flex items-center gap-1.5 shrink-0"><VramBadge- status={oom ? "exceeds" : tight ? "tight" : null}- source="gguf"+ status={+ diffusionRefuses(fit, diffusionLoad, hostPooledMemory)+ ? "exceeds"+ : fit+ }/><span className="font-mono text-ui-10 text-muted-foreground tabular-nums">{companionBytes === null ? (@@ -2192,6 +2281,15 @@ export const VIDEO_GEN_TASKS = ["image-text-to-video",] as const;+/** The tasks whose GGUFs are placed by the DIFFUSION backend, which is the only reason a picker+ * scores against `classifyMediaGgufFit`. Audio is task-scoped too but does not belong here: its+ * GGUFs go to llama.cpp (TTS) or the whisper sidecars (stt_ggml_sidecar.py, stt_mtmd_sidecar.py),+ * so scoring them at 70% hid runnable models and picked a smaller quant than needed. */+const DIFFUSION_TASKS: ReadonlySet<string> = new Set([+ ...IMAGE_GEN_TASKS,+ ...VIDEO_GEN_TASKS,+]);+// Speech pipeline tasks: owned by the Audio page. TTS picks load there rather than into chat; ASR picks map to the dictation sidecar.export const AUDIO_GEN_TASKS = ["text-to-speech",@@ -2531,6 +2629,16 @@ export function HubModelPicker({}) {const gpu = useGpuInfo();const inferenceGpu = useInferenceGpuInfo();+ // The saved VRAM Budget, threaded into every fit call in this component. Passing it to the quant+ // rows alone left the parent rows and the "Fits on device" filter scoring against the 0.97+ // default, so lowering the setting moved one and not the other.+ const budgetFraction = useVramBudgetFraction() ?? undefined;+ // Whether THIS picker's rows load through the diffusion backend. Not `Boolean(task)`: Audio is+ // task-scoped for the single-device budget but runs its GGUFs under llama.cpp / whisper.+ const diffusionLoad = useMemo(() => {+ const tasks = task ? (typeof task === "string" ? [task] : task) : [];+ return tasks.some((entry) => DIFFUSION_TASKS.has(entry));+ }, [task]);// What the backend actually holds, not the dropdown highlight, which can be a// staged pick. The selection alone was wrong: an image or video load evicts// the chat model and leaves the pick untouched, so its rows kept the "Loaded"@@ -3283,7 +3391,16 @@ export function HubModelPicker({// The catalog's own verdict where it has one, so this list and the OOM badge on its rows// cannot disagree: hfModelFitsDevice counts RAM toward a load that never leaves the card.(catalogFit(r.id, pipelineBudget) ??- hfModelFitsDevice(r, r.isGguf ? rowInferenceGpu : rowGpu));+ hfModelFitsDevice(r, diffusionLoad || !r.isGguf ? rowGpu : rowInferenceGpu, {+ budgetFraction,+ // Not `&& r.isGguf`: on a task page a safetensors row is placed by the same backend, and+ // this rule IS the budget those rows had before the classifiers were merged. Restricting+ // it to GGUF left this gate disagreeing with searchRowFitsDevice about the same row.+ mediaLoad: diffusionLoad,+ hostPooledMemory: gpu.loadDeviceSharesHostMemory,+ // The scoped inventory's own count, so it always describes rowInferenceGpu's capacity.+ gpuCount: rowInferenceGpu.deviceCount,+ }));const unslothRows = orderRecommendedRows({seeds: catalogSeedRows,results: recommendedSearch.results,@@ -3303,6 +3420,8 @@ export function HubModelPicker({.filter((r) => !deviceFiltered || fits(r));return [...unslothRows, ...communityRows];}, [+ budgetFraction,+ diffusionLoad,recommendedSearch.results,catalogSeedRows,downloadedSet,@@ -3329,29 +3448,65 @@ export function HubModelPicker({const recommendedMeta = useMemo(() => {const map = new Map<string,- { meta: string | null; status: VramFitStatus | null; est: number }+ {+ meta: string | null;+ /** GGUF rows carry the classifier's own verdict; curated torch rows carry "exceeds". */+ status: GgufFitClass | VramFitStatus | null;+ est: number;+ }>();/** Size-based verdict for a row whose real footprint we know, against the budget that row- * actually loads into. Same split as the list's own fit filter, so the badge and the- * "Fits on device" gate cannot disagree about one row. */- const exceedsSize = (+ * actually loads into. Same classifier as the quant rows below it, so the badge and the+ * "Fits on device" gate cannot disagree about one row.+ *+ * Returns the verdict, not a boolean. A boolean collapsed `marginal` and `partial` into "no+ * badge", so a repo whose SMALLEST quant already needs offload rendered as a clean fit beside+ * expanded rows saying the opposite. */+ const ggufRowFit = (sizeBytes: number | undefined,budget: typeof inferenceGpu,- ) =>- (budget.budgetKnown ||- budget.memoryTotalGb > 0 ||- budget.systemRamAvailableGb > 0) &&- sizeBytes != null &&- !fitsDevice({- sizeBytes,- gpuGb: budget.memoryTotalGb,- systemRamGb: budget.systemRamAvailableGb,- budgetKnown: budget.budgetKnown,- });+ ): GgufFitClass | VramFitStatus | null => {+ const anyBudget =+ budget.memoryTotalGb > 0 || budget.systemRamAvailableGb > 0;+ if (!budget.budgetKnown && !anyBudget) return null;+ if (sizeBytes == null) return null;+ // Probed and genuinely zero (a Vulkan device reporting nothing) means nothing fits.+ if (!anyBudget) return "oom";+ // Images / Video place this GGUF through the diffusion backend, so it takes the same rule+ // its quant rows take. Judging the parent by llama.cpp's budget and the children by the+ // media one let a row read as fitting while everything inside it read as oom.+ const fit = diffusionLoad+ ? classifyMediaGgufFit(+ sizeBytes,+ budget.memoryTotalGb,+ mediaRamBudgetGb(+ budget.systemRamAvailableGb,+ gpu.loadDeviceSharesHostMemory,+ ),+ )+ : classifyGgufFit(sizeBytes, {+ gpuGb: budget.memoryTotalGb,+ systemRamGb: budget.systemRamAvailableGb,+ budgetFraction,+ gpuCount: budget.deviceCount,+ });+ if (fit === "fits") return null;+ return diffusionRefuses(fit, diffusionLoad, gpu.loadDeviceSharesHostMemory)+ ? "exceeds"+ : fit;+ };// A curated pipeline loads through torch, and a task load puts the whole thing on ONE// device, so it is judged there. inferenceGpu is the GGUF backend's inventory, which can// be a different install (Vulkan llama.cpp) or the sum of several cards.- const pipelineBudget = artifactBudget(loadScopedGpu(gpu, Boolean(task)));+ const rowGpu = loadScopedGpu(gpu, Boolean(task));+ const pipelineBudget = artifactBudget(rowGpu);+ // The inventory of the runtime that PLACES the row, not of its file format. An Images or+ // Video GGUF goes to the diffusion backend, which is torch, and on a Vulkan chat build+ // inferenceGpu is a different device set entirely: it can see a card torch cannot, so the+ // media rule was scoring against capacity the diffusion loader never gets to use.+ const rowInferenceGpu = diffusionLoad+ ? rowGpu+ : loadScopedGpu(inferenceGpu, Boolean(task));// Community rows come from their own listing; without them folded in here// they render with no size or VRAM chip.for (const r of [@@ -3391,8 +3546,23 @@ export function HubModelPicker({(params ? estimateQuantBytes(params) : undefined);map.set(r.id, {meta,- status: exceedsSize(sizeBytes, inferenceGpu) ? "exceeds" : null,- est: sizeBytes ? Math.round(sizeBytes / 1024 ** 3) : 0,+ // The classifier's own verdict, so a GGUF row never borrows "exceeds", which is the+ // torch-only refusal used by the curated branch below.+ // The device the load LANDS on, same as the quant rows under it and the fit filter+ // beside it. The curated branch below already scoped; this one did not, so a downloaded+ // media parent could read as safe while every variant inside it read as oom.+ status: ggufRowFit(sizeBytes, rowInferenceGpu),+ // The figure the verdict was reached with, not the raw file size. classifyGgufFit scores+ // weights PLUS activations and KV, so a 20 GiB quant needing 24 GiB read "tight fit"+ // beside a tooltip saying "~20GB VRAM". The media rule scores the raw size, so that one+ // keeps it.+ est: sizeBytes+ ? Math.round(+ diffusionLoad+ ? sizeBytes / 1024 ** 3+ : requiredGgufMemoryGb(sizeBytes),+ )+ : 0,});continue;}@@ -3420,6 +3590,8 @@ export function HubModelPicker({}return map;}, [+ budgetFraction,+ diffusionLoad,recommendedSearch.results,communityBrowse.results,catalogSeedRows,@@ -3676,8 +3848,17 @@ export function HubModelPicker({info.available? loadScopedGpu(info, Boolean(task)).memoryTotalGb: undefined;- const expanderGpuGb = expanderGpuGbFrom(inferenceGpu);+ // Images / Video place through torch even where llama.cpp is a Vulkan build, so their budget+ // comes from the torch inventory. Everything else keeps the GGUF backend's own.+ const expanderBudgetGpu = diffusionLoad ? gpu : inferenceGpu;+ const expanderGpuGb = expanderGpuGbFrom(expanderBudgetGpu);const expanderSystemGpuGb = expanderGpuGbFrom(gpu);+ // From the SAME scoping decision as the capacity above: loadScopedGpu narrows the count to 1+ // with memoryTotalGb, so the per-card reserve is never charged host-wide against one card,+ // and the RAM tier is the one that belongs to the device the load lands on.+ const expanderScopedGpu = loadScopedGpu(expanderBudgetGpu, Boolean(task));+ const expanderGpuCount = expanderScopedGpu.deviceCount;+ const expanderRamGb = expanderScopedGpu.systemRamAvailableGb;// Each local section's search is scoped to its own models (matched by name).const localQuery = normalizeForSearch(debouncedQuery.trim());@@ -4241,10 +4422,17 @@ export function HubModelPicker({gpu,inferenceGpu,taskScoped: Boolean(task),+ // Separate from taskScoped: that picks the single-device budget for every task page,+ // this picks the diffusion RULE, which only Images and Video use.+ diffusionLoad,+ budgetFraction,+ hostPooledMemory: gpu.loadDeviceSharesHostMemory,},),[+ budgetFraction,catalog,+ diffusionLoad,catalogFit,gpu,inferenceGpu,@@ -4960,7 +5148,7 @@ export function HubModelPicker({? undefined: { repoId: entry.repoId, quant: entry.quant }}- gpuGb={inferenceGpu.memoryTotalGb}+ gpuGb={expanderGpuGb}alignMeta="device"selected={isSelected}loaded={isLoaded}@@ -5106,7 +5294,7 @@ export function HubModelPicker({loadId: c.load_id,}}- gpuGb={inferenceGpu.memoryTotalGb}+ gpuGb={expanderGpuGb}showVision={c.has_vision || sole.hasVision}selected={isSelected}loaded={rowState.loaded}@@ -5212,6 +5400,9 @@ export function HubModelPicker({</div>{expanderOpen && (<GgufVariantExpander+ diffusionLoad={diffusionLoad}+ hostPooledMemory={gpu.loadDeviceSharesHostMemory}+ gpuCount={expanderGpuCount}repoId={c.repo_id}pipelineTag={c.task ?? null}loadId={c.load_id}@@ -5227,8 +5418,8 @@ export function HubModelPicker({onNavigatePastStart={() => hubModelList.focusOption(optionKey)}onNavigatePastEnd={() => hubModelList.moveFocus(optionKey, "next")}gpuGb={expanderGpuGb}- systemRamGb={inferenceGpu.systemRamAvailableGb || undefined}- budgetKnown={inferenceGpu.budgetKnown}+ systemRamGb={expanderRamGb || undefined}+ budgetKnown={expanderBudgetGpu.budgetKnown}variantActions={{onUpdate: (quant, expectedBytes) =>updateGgufVariant(c.repo_id, quant, expectedBytes),@@ -6103,6 +6294,9 @@ export function HubModelPicker({!isDirectGguf &&isGgufExpanded(m.id) && (<GgufVariantExpander+ diffusionLoad={diffusionLoad}+ hostPooledMemory={gpu.loadDeviceSharesHostMemory}+ gpuCount={expanderGpuCount}repoId={m.id}onDevice={true}onSelect={onSelect}@@ -6115,16 +6309,9 @@ export function HubModelPicker({onNavigatePastEnd={() =>hubModelList.moveFocus(optionKey, "next")}- gpuGb={- inferenceGpu.available- ? inferenceGpu.memoryTotalGb- : undefined- }- systemRamGb={- inferenceGpu.systemRamAvailableGb ||- undefined- }- budgetKnown={inferenceGpu.budgetKnown}+ gpuGb={expanderGpuGb}+ systemRamGb={expanderRamGb || undefined}+ budgetKnown={expanderBudgetGpu.budgetKnown}/>)}</div>@@ -6246,6 +6433,9 @@ export function HubModelPicker({</div>{isGguf && !isGgufFile && isGgufExpanded(m.id) && (<GgufVariantExpander+ diffusionLoad={diffusionLoad}+ hostPooledMemory={gpu.loadDeviceSharesHostMemory}+ gpuCount={expanderGpuCount}repoId={m.id}onDevice={true}onSelect={onSelect}@@ -6259,10 +6449,8 @@ export function HubModelPicker({hubModelList.moveFocus(optionKey, "next")}gpuGb={expanderGpuGb}- systemRamGb={- inferenceGpu.systemRamAvailableGb || undefined- }- budgetKnown={inferenceGpu.budgetKnown}+ systemRamGb={expanderRamGb || undefined}+ budgetKnown={expanderBudgetGpu.budgetKnown}/>)}</div>@@ -6374,10 +6562,13 @@ export function HubModelPicker({</div>{isGguf && !isGgufFile && isGgufExpanded(m.id) && (<GgufVariantExpander+ diffusionLoad={diffusionLoad}+ hostPooledMemory={gpu.loadDeviceSharesHostMemory}+ gpuCount={expanderGpuCount}repoId={m.id}onDevice={true}onSelect={onSelect}- resolveDownloadFootprint={resolveDownloadFootprint}+ resolveDownloadFootprint={resolveDownloadFootprint}onConfigure={onConfigure}parentOptionKey={optionKey}onNavigatePastStart={() =>@@ -6387,10 +6578,8 @@ export function HubModelPicker({hubModelList.moveFocus(optionKey, "next")}gpuGb={expanderGpuGb}- systemRamGb={- inferenceGpu.systemRamAvailableGb || undefined- }- budgetKnown={inferenceGpu.budgetKnown}+ systemRamGb={expanderRamGb || undefined}+ budgetKnown={expanderBudgetGpu.budgetKnown}/>)}</div>@@ -6467,6 +6656,9 @@ export function HubModelPicker({/>{expandedGguf === id && (<GgufVariantExpander+ diffusionLoad={diffusionLoad}+ hostPooledMemory={gpu.loadDeviceSharesHostMemory}+ gpuCount={expanderGpuCount}repoId={id}pipelineTag={pipelineTagById.get(id) ?? null}onSelect={onSelect}@@ -6481,10 +6673,8 @@ export function HubModelPicker({hubModelList.moveFocus(optionKey, "next")}gpuGb={expanderGpuGb}- systemRamGb={- inferenceGpu.systemRamAvailableGb || undefined- }- budgetKnown={inferenceGpu.budgetKnown}+ systemRamGb={expanderRamGb || undefined}+ budgetKnown={expanderBudgetGpu.budgetKnown}variantActions={{onDelete: async (quant) => {await deleteCachedModel(@@ -6589,10 +6779,13 @@ export function HubModelPicker({/>{expandedGguf === id && (<GgufVariantExpander+ diffusionLoad={diffusionLoad}+ hostPooledMemory={gpu.loadDeviceSharesHostMemory}+ gpuCount={expanderGpuCount}repoId={id}pipelineTag={pipelineTagById.get(id) ?? null}onSelect={onSelect}- resolveDownloadFootprint={resolveDownloadFootprint}+ resolveDownloadFootprint={resolveDownloadFootprint}onConfigure={onConfigure}hfToken={hfToken || undefined}parentOptionKey={optionKey}@@ -6603,10 +6796,8 @@ export function HubModelPicker({hubModelList.moveFocus(optionKey, "next")}gpuGb={expanderGpuGb}- systemRamGb={- inferenceGpu.systemRamAvailableGb || undefined- }- budgetKnown={inferenceGpu.budgetKnown}+ systemRamGb={expanderRamGb || undefined}+ budgetKnown={expanderBudgetGpu.budgetKnown}variantActions={{onDelete: async (quant) => {await deleteCachedModel(@@ -6702,6 +6893,9 @@ export function HubModelPicker({/>{expandedGguf === id && (<GgufVariantExpander+ diffusionLoad={diffusionLoad}+ hostPooledMemory={gpu.loadDeviceSharesHostMemory}+ gpuCount={expanderGpuCount}repoId={id}pipelineTag={pipelineTagById.get(id) ?? null}onSelect={onSelect}@@ -6716,10 +6910,8 @@ export function HubModelPicker({hubModelList.moveFocus(optionKey, "next")}gpuGb={expanderGpuGb}- systemRamGb={- inferenceGpu.systemRamAvailableGb || undefined- }- budgetKnown={inferenceGpu.budgetKnown}+ systemRamGb={expanderRamGb || undefined}+ budgetKnown={expanderBudgetGpu.budgetKnown}variantActions={{onDelete: async (quant) => {await deleteCachedModel(@@ -6804,6 +6996,8 @@ function FineTunedRows({available: boolean;budgetKnown: boolean;memoryTotalGb: number;+ /** GPUs memoryTotalGb sums, for the loader's per-card VRAM reserve. */+ deviceCount?: number;systemRamAvailableGb: number;};}) {@@ -6955,6 +7149,7 @@ function FineTunedRows({loraModelList.moveFocus(optionKey, "next")}gpuGb={gpu.available ? gpu.memoryTotalGb : undefined}+ gpuCount={gpu.deviceCount}systemRamGb={gpu.systemRamAvailableGb || undefined}budgetKnown={gpu.budgetKnown}sourceOverride={isExportedGguf ? "exported" : undefined}diff --git a/studio/frontend/src/features/model-picker/components/model-selector/recommended-fit.ts b/studio/frontend/src/features/model-picker/components/model-selector/recommended-fit.tsindex 1ec4090e8c0..f26aef202e2 100644--- a/studio/frontend/src/features/model-picker/components/model-selector/recommended-fit.ts+++ b/studio/frontend/src/features/model-picker/components/model-selector/recommended-fit.ts@@ -4,6 +4,9 @@// Pure helpers for the Recommended list: which formats to surface and whether a// model fits the device. No React/DOM deps so they are easy to test.+import { classifyGgufFit } from "../../../../lib/gguf-fit.ts";+import { classifyMediaGgufFit } from "./model-catalog.ts";+const GGUF_SUFFIX_RE = /-GGUF(?:$|-)/i;const MLX_RE = /-MLX(?:$|-)/i;@@ -66,7 +69,7 @@ const PARAM_RE = /(?:^|[-_/. ])[eE]?(\d+(?:\.\d+)?)\s*[bB](?=$|[-_./ ])/;export function paramsFromId(id: string): number | undefined {const match = PARAM_RE.exec(id);if (!match) return undefined;- const billions = parseFloat(match[1]);+ const billions = Number.parseFloat(match[1]);return Number.isFinite(billions) && billions > 0 ? billions * 1e9 : undefined;}@@ -79,36 +82,69 @@ export function estimateQuantBytes(params: number): number {return params * MIN_QUANT_BYTES_PER_PARAM;}-/** A model fits when its on-disk size (or a precomputed VRAM estimate) is within- * the device budget (0.7*GPU + 0.7*RAM). Unknown device means we cannot tell, so- * treat it as fitting. Unknown size normally fits too, but Recommended passes- * `requireKnown` so a model we cannot size (e.g. a huge GGUF with no metadata or- * size token) is hidden rather than wrongly shown. */+/** A model fits when it can run at all: `classifyGgufFit` short of `oom`, so a partial CPU+ * offload counts, since that loads and merely runs slower. Shares the loader's formula with the+ * Hub badge and the quant rows, because this predicate ALSO gates the "Fits on device" filter,+ * and a filter that hides a row the quant list would badge as runnable is the same bug twice.+ *+ * Unknown device means we cannot tell, so treat it as fitting. Unknown size normally fits too,+ * but Recommended passes `requireKnown` so a model we cannot size (e.g. a huge GGUF with no+ * metadata or size token) is hidden rather than wrongly shown. */export function fitsDevice(opts: {sizeBytes?: number;- estimatedVramGb?: number;gpuGb?: number;systemRamGb?: number;budgetKnown?: boolean;requireKnown?: boolean;+ budgetFraction?: number;+ /** How many GPUs gpuGb sums, so the gate charges the loader's per-card VRAM reserve the same+ * number of times the badge does. Absent means one. */+ gpuCount?: number;+ /** Images / Video: the row is placed by the diffusion backend, not llama-server, so it takes the+ * media rule the quant rows under it use. Applies to every format on those pages, GGUF or not:+ * that rule is the budget all of them had before the classifiers were merged. */+ mediaLoad?: boolean;+ /** The load device's memory is a window into host RAM, so RAM is not a second budget to add.+ * Media rule only; the llama.cpp one already takes a RAM figure with the pool removed. */+ hostPooledMemory?: boolean;}): boolean {const {sizeBytes,- estimatedVramGb,gpuGb,systemRamGb,budgetKnown,requireKnown,+ budgetFraction,+ gpuCount,+ mediaLoad,+ hostPooledMemory,} = opts;- // Unified-memory hosts (Mac / no discrete GPU) report system RAM but no GPU,- // so the budget must include RAM. Only an entirely unknown budget fits freely.- const budgetGb = Math.max(0, gpuGb ?? 0) * 0.7 + Math.max(0, systemRamGb ?? 0) * 0.7;- if (budgetGb <= 0) return !budgetKnown;+ // Unified-memory hosts (Mac / no discrete GPU) report system RAM but no GPU, so the budget must+ // include RAM. Only an entirely unknown budget fits freely.+ const anyBudget =+ Math.max(0, gpuGb ?? 0) > 0 || Math.max(0, systemRamGb ?? 0) > 0;+ if (!anyBudget) return !budgetKnown;if (sizeBytes && sizeBytes > 0) {- return sizeBytes / 1024 ** 3 <= budgetGb;- }- if (estimatedVramGb && estimatedVramGb > 0) {- return estimatedVramGb <= budgetGb;+ if (mediaLoad) {+ // No RAM tier on a host pool: diffusion offload moves bytes inside that one pool and frees+ // nothing. llama.cpp below keeps its tier, because a GGUF really does spill into whatever+ // host RAM the GPU window does not already cover.+ return (+ classifyMediaGgufFit(+ sizeBytes,+ gpuGb ?? 0,+ hostPooledMemory ? 0 : (systemRamGb ?? 0),+ ) !== "oom"+ );+ }+ return (+ classifyGgufFit(sizeBytes, {+ gpuGb,+ systemRamGb,+ budgetFraction,+ gpuCount,+ }) !== "oom"+ );}return requireKnown ? false : true;}@@ -135,6 +171,15 @@ export function hfModelFitsDevice(systemRamAvailableGb: number;budgetKnown?: boolean;},+ /** `budgetFraction` is the user's saved VRAM Budget: omitted scores against the loader's default,+ * so a caller that forgets it judges rows on a budget the user has already replaced.+ * `mediaLoad` picks the diffusion rule for an Images / Video row. */+ opts: {+ budgetFraction?: number;+ gpuCount?: number;+ mediaLoad?: boolean;+ hostPooledMemory?: boolean;+ } = {},): boolean {if (gpu.memoryTotalGb <= 0 &&@@ -155,6 +200,10 @@ export function hfModelFitsDevice(systemRamGb: gpu.systemRamAvailableGb,budgetKnown: gpu.budgetKnown,requireKnown: true,+ budgetFraction: opts.budgetFraction,+ gpuCount: opts.gpuCount,+ mediaLoad: opts.mediaLoad,+ hostPooledMemory: opts.hostPooledMemory,});}@@ -169,23 +218,41 @@ export function loadScopedGpu<maxDeviceMemoryGb: number;loadDeviceMemoryGb: number;loadDeviceSharedMemory?: boolean;+ loadDeviceSharesHostMemory?: boolean;systemRamAvailableGb: number;systemRamAvailableHostGb?: number;+ deviceCount?: number;},->(gpu: T, taskScoped: boolean): T {+>(gpu: T, taskScoped: boolean): T & { deviceCount?: number } {if (!taskScoped || !gpu.available) return gpu;const deviceGb = gpu.loadDeviceMemoryGb || gpu.maxDeviceMemoryGb;if (deviceGb <= 0) return gpu;return {...gpu,memoryTotalGb: deviceGb,- systemRamAvailableGb:- gpu.loadDeviceSharedMemory === false- ? (gpu.systemRamAvailableHostGb ?? gpu.systemRamAvailableGb)- : gpu.systemRamAvailableGb,+ // Narrowed with the capacity it describes, or the loader's per-card VRAM reserve gets charged+ // once per HOST GPU against a ONE-card budget. Two 24 GiB cards at a 1.0 setting scored an+ // audio quant against 23.28 GiB where the loader offers the selected card's 23.5.+ deviceCount: 1,+ // The raw-host figure is the RAM a DEDICATED task device may claim back from a shared GPU's+ // reservation. Gated on the folded flag, not shared_memory: that one is Windows-only, so a+ // Linux ROCm APU took this branch and undid the very subtraction that keeps its GTT window+ // out of the RAM tier.+ systemRamAvailableGb: hostPooledLoadDevice(gpu)+ ? gpu.systemRamAvailableGb+ : (gpu.systemRamAvailableHostGb ?? gpu.systemRamAvailableGb),};}+/** Whether the device a task load lands on draws from host RAM. Prefers the folded flag, which+ * counts a Linux APU that reports unified_memory without shared_memory. */+function hostPooledLoadDevice(gpu: {+ loadDeviceSharedMemory?: boolean;+ loadDeviceSharesHostMemory?: boolean;+}): boolean {+ return gpu.loadDeviceSharesHostMemory ?? gpu.loadDeviceSharedMemory === true;+}+/** One fit predicate for both search lists (curated matches and the Hub rows* below them). The curated list only suppresses ids it kept, so a row it drops* reappears from the Hub list: judge both on the same size and budget, or the@@ -198,6 +265,7 @@ export function searchRowFitsDevice<loadDeviceMemoryGb: number;systemRamAvailableGb: number;budgetKnown?: boolean;+ deviceCount?: number;},>(row: {@@ -212,16 +280,37 @@ export function searchRowFitsDevice<gpu: G;inferenceGpu: G;taskScoped: boolean;+ /** Images / Video only. `taskScoped` picks the single-device budget for every task page; this+ * picks the diffusion RULE, which Audio must not get: its GGUFs run under llama.cpp. */+ diffusionLoad?: boolean;+ budgetFraction?: number;+ /** How many GPUs the aggregate sums, when the caller's inventory does not carry the count+ * itself. loadScopedGpu narrows it to 1 with the capacity, so a task page needs nothing here. */+ gpuCount?: number;+ /** The image/video load device's pool is host RAM, so RAM is not a second budget. */+ hostPooledMemory?: boolean;},): boolean {- const source = opts.isGguf ? opts.inferenceGpu : opts.gpu;+ const source = loadScopedGpu(+ opts.diffusionLoad || !opts.isGguf ? opts.gpu : opts.inferenceGpu,+ opts.taskScoped,+ );return hfModelFitsDevice({...row,isGguf: opts.isGguf,curatedSizeBytes: row.curatedSizeBytes ?? opts.curatedSizeBytes,},- loadScopedGpu(source, opts.taskScoped),+ source,+ // A task-scoped row is a media load, so it takes the media rule as well as the single-device+ // budget. Without this the search gate disagreed with the quant rows it gates.+ {+ budgetFraction: opts.budgetFraction,+ // From the SCOPED budget, so the count always describes the capacity beside it.+ gpuCount: source.deviceCount ?? opts.gpuCount,+ mediaLoad: opts.diffusionLoad,+ hostPooledMemory: opts.hostPooledMemory,+ },);}diff --git a/studio/frontend/src/features/model-picker/index.ts b/studio/frontend/src/features/model-picker/index.tsindex 0b8bf94c47d..245eb697757 100644--- a/studio/frontend/src/features/model-picker/index.ts+++ b/studio/frontend/src/features/model-picker/index.ts@@ -10,7 +10,10 @@ export {pinKey,usePinnedModelsStore,} from "./components/model-selector/pinned-models";-export { hfModelFitsDevice } from "./components/model-selector/recommended-fit";+export {+ hfModelFitsDevice,+ loadScopedGpu,+} from "./components/model-selector/recommended-fit";export {NumericValueInput,type NumericValueInputHandle,diff --git a/studio/frontend/src/hooks/gpu-vram.ts b/studio/frontend/src/hooks/gpu-vram.tsindex 3925cc6b04d..ef7612cc6c2 100644--- a/studio/frontend/src/hooks/gpu-vram.ts+++ b/studio/frontend/src/hooks/gpu-vram.ts@@ -128,7 +128,7 @@ export interface MemoryCapacityDevice {/** Whether this device's memory is a view into host RAM rather than beside it.* The one question capacity cares about; the two flags are how the backend* happens to report it on two platforms. */-function sharesHostMemory(device: {+export function sharesHostMemory(device: {sharedMemory?: boolean;unifiedMemory?: boolean;}): boolean {diff --git a/studio/frontend/src/hooks/use-gpu-info.ts b/studio/frontend/src/hooks/use-gpu-info.tsindex 6c96b490cfe..afe95c8631d 100644--- a/studio/frontend/src/hooks/use-gpu-info.ts+++ b/studio/frontend/src/hooks/use-gpu-info.ts@@ -15,6 +15,7 @@ import {import {gpuMemoryTotalsGb,gpuSharedHostMemoryGb,+ sharesHostMemory,systemRamAvailableOutsideSharedPoolGb,} from "./gpu-vram";import {@@ -57,6 +58,12 @@ export interface GpuInfo {loadDeviceMemoryGb: number;/** true when the image/video load device uses the host memory pool. */loadDeviceSharedMemory: boolean;+ /** The same question with the ROCm APU included: `shared_memory` is that flag AND Windows, so a+ * Linux APU reads as not-shared while its total is still a window into host RAM. Offload frees+ * nothing on either, which is the only thing a diffusion verdict needs to know. */+ loadDeviceSharesHostMemory: boolean;+ /** How many GPUs memoryTotalGb is the sum of, for the loader's per-card VRAM reserve. */+ deviceCount: number;cpuCore: number;cpuThread: number;/** host RAM free after removing the host-backed shared GPU pool. */@@ -79,6 +86,8 @@ const DEFAULT_GPU: GpuInfo = {maxDeviceMemoryGb: 0,loadDeviceMemoryGb: 0,loadDeviceSharedMemory: false,+ loadDeviceSharesHostMemory: false,+ deviceCount: 0,cpuCore: 0,cpuThread: 0,systemRamAvailableGb: 0,@@ -110,9 +119,20 @@ function toGpuInfo(const loadDevice = pickLoadDevice(devices);return {...base,+ // Folded, not raw `shared_memory`: hardware.py sets that flag only on Windows, so a Linux ROCm+ // APU arrives unified true / shared false and its GTT window was never subtracted here. The+ // RAM tier then offered the very bytes the window is a view INTO as a second budget.systemRamAvailableGb: systemRamAvailableOutsideSharedPoolGb(base.systemRamAvailableGb,- gpuSharedHostMemoryGb(devices),+ gpuSharedHostMemoryGb(+ devices.map((device) => ({+ ...device,+ shared_memory: sharesHostMemory({+ sharedMemory: device.shared_memory === true,+ unifiedMemory: device.unified_memory === true,+ }),+ })),+ ),),sharedMemory: memoryTotals.shared > 0 && memoryTotals.dedicated === 0,// Additive, and deliberately some() where sharedMemory above is "no dedicated@@ -133,6 +153,11 @@ function toGpuInfo(// Lowest visible ordinal = torch's current device = where the pipeline lands.loadDeviceMemoryGb: loadDevice?.memory_total_gb ?? 0,loadDeviceSharedMemory: loadDevice?.shared_memory === true,+ loadDeviceSharesHostMemory: sharesHostMemory({+ sharedMemory: loadDevice?.shared_memory === true,+ unifiedMemory: loadDevice?.unified_memory === true,+ }),+ deviceCount: devices.length,};}diff --git a/studio/frontend/src/lib/gguf-fit.ts b/studio/frontend/src/lib/gguf-fit.tsindex 4a0819f9f76..ddb56677152 100644--- a/studio/frontend/src/lib/gguf-fit.ts+++ b/studio/frontend/src/lib/gguf-fit.ts@@ -25,6 +25,10 @@ export interface GgufFitInput {* against the 0.97 default's 23.28 GiB, so a 18 to 19 GiB quant was badged* `fits` beside a bar reporting an overage. */budgetFraction?: number;+ /** How many GPUs `gpuGb` is the sum of. Only the reserve floor uses it, and only+ * above the default budget; absent means one card, which is what every verdict+ * scored against before it existed. */+ gpuCount?: number;}/** Fraction of GPU VRAM treated as usable.@@ -44,6 +48,9 @@ export interface GgufFitInput {* filter). */export { DEFAULT_VRAM_BUDGET_FRACTION as VRAM_HEADROOM_RATIO } from "./memory/thresholds.ts";import { DEFAULT_VRAM_BUDGET_FRACTION } from "./memory/thresholds.ts";+/** The loader's absolute reserve floor, `_VRAM_FLOOR_RESERVE_MIB` (512 MiB) in llama_cpp.py.+ * Capped there at 3% of the card, so it never rises above the default budget's own reserve. */+const VRAM_RESERVE_FLOOR_GB = 512 / 1024;/** GGUF weights are file size; runtime activations add roughly this fraction. */const ACTIVATIONS_RATIO = 0.15;/** Flat KV/context allowance at a typical 4K window. */@@ -61,7 +68,7 @@ export function requiredGgufMemoryGb(export function classifyGgufFit(sizeBytes: number,- { gpuGb, systemRamGb, budgetFraction }: GgufFitInput,+ { gpuGb, systemRamGb, budgetFraction, gpuCount }: GgufFitInput,): GgufFitClass {const required = requiredGgufMemoryGb(sizeBytes);if (!gpuGb || gpuGb <= 0) {@@ -77,7 +84,29 @@ export function classifyGgufFit(budgetFraction <= 1? budgetFraction: DEFAULT_VRAM_BUDGET_FRACTION;- const budget = gpuGb * fraction;+ // Not simply `gpuGb * fraction`. The loader's `_vram_usable_mib` charges+ // `max((1 - frac) * total, floor)`, where the floor is `min(512 MiB, 3% of total)`, so the+ // reserve never disappears at the top of the slider. Below the 0.97 default the percentage term+ // always wins and this is identical; above it, `gpuGb * fraction` claimed capacity the backend+ // does not offer, and a 20 GiB file on a full 24 GiB card at 1.0 read `fits` while `_select_gpus`+ // fell back to --fit.+ //+ // Charged per CARD, not per host: `_select_gpus` calls `_vram_usable_mib` for every device and+ // sums the results, so a k-GPU box holds back k floors. One floor for the whole box read 47.5+ // GiB usable on two 24 GiB cards at 1.0 where the loader offers 47.0, so a file needing 47.2+ // read `fits` against a load that fell back to --fit. Exact on matched cards, an even split on+ // a mixed one, which is still far nearer than charging the floor once.+ const cards =+ typeof gpuCount === "number" && Number.isFinite(gpuCount) && gpuCount >= 1+ ? Math.floor(gpuCount)+ : 1;+ const reserveFloorGb =+ cards *+ Math.min(+ VRAM_RESERVE_FLOOR_GB,+ (1 - DEFAULT_VRAM_BUDGET_FRACTION) * (gpuGb / cards),+ );+ const budget = gpuGb - Math.max((1 - fraction) * gpuGb, reserveFloorGb);if (required <= budget) return "fits";// Raw card, deliberately. This band means "over your budget, still card-sized",// which is the only thing that distinguishes it from `fits`: scoring it againstdiff --git a/studio/frontend/tests/on-device-dot-and-header-alignment.test.ts b/studio/frontend/tests/on-device-dot-and-header-alignment.test.tsindex c265379032b..a7af12010f2 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@@ -14,6 +14,16 @@ const PICKERS = read("../src/features/model-picker/components/model-selector/pickers.tsx",);const MODELS_TABLE = read("../src/features/hub/catalog/models-table.tsx");+const HUB_CARD = read("../src/features/hub/catalog/gguf-download-card.tsx");+const HUB_PAGE = read("../src/features/hub/hub-page.tsx");+const CATALOG = read(+ "../src/features/model-picker/components/model-selector/model-catalog.ts",+);+const RECOMMENDED = read(+ "../src/features/model-picker/components/model-selector/recommended-fit.ts",+);+const GPU_INFO = read("../src/hooks/use-gpu-info.ts");+const INSPECTOR = read("../src/features/hub/catalog/model-inspector.tsx");const SIDEBAR = read("../src/components/app-sidebar.tsx");const CSS = read("../src/index.css");@@ -58,10 +68,16 @@ test("a row's leading dot starts where its section label does", () => {// Section labels sit at px-2.5. The dot is centred in a 14px hover target, so its slot starts// at 10 - (14 - 5) / 2 = 5.5px for the dot to land on 10px. px-2 put it at 12.5px.assert.match(PICKERS, /py-1\.5 pl-\[5\.5px\] pr-2 text-left text-sm/);- const label = PICKERS.slice(PICKERS.indexOf("flex items-center justify-between gap-1 px-2.5"));+ const label = PICKERS.slice(+ PICKERS.indexOf("flex items-center justify-between gap-1 px-2.5"),+ );assert.ok(label.startsWith("flex items-center justify-between gap-1 px-2.5"));// The 14px hover target is what makes 5.5 the right number; shrinking it would move the dot.- assert.ok(PICKERS.includes('className="flex size-[14px] shrink-0 items-center justify-center"'));+ assert.ok(+ PICKERS.includes(+ 'className="flex size-[14px] shrink-0 items-center justify-center"',+ ),+ );});test("the parameter and size columns are sized to the ink they hold", () => {@@ -103,62 +119,378 @@ test("an over budget row dims instead of putting a pill on every line", () => {test("one fit badge, so a colour or reveal change cannot miss a list", () => {// The quantization rows had their own copy and stayed red when the pill went orange.- assert.equal(PICKERS.split("VRAM_VERDICT = {").length - 1, 1, "one verdict table");+ assert.equal(+ PICKERS.split("const VRAM_VERDICT").length - 1,+ 1,+ "one verdict table",+ );assert.ok(!PICKERS.includes("!text-red-700"), "no red fit badge left");assert.ok(!PICKERS.includes(">\n OOM\n"), "no OOM text pill left");- // Variant rows render the shared badge, in the GGUF vocabulary, and opt out of the hover reveal.+ // Variant rows hand the classifier's verdict straight to the badge, with no second mapping+ // between them to drift.assert.match(PICKERS,- /<VramBadge\n\s*status=\{oom \? "exceeds" : tight \? "tight" : null\}\n\s*source="gguf"\n\s*\/>/,+ /<VramBadge\n\s*status=\{\n\s*diffusionRefuses\(fit, diffusionLoad, hostPooledMemory\)/,);assert.equal(- PICKERS.split(- '<VramBadge status={vramStatus} source="device" revealOnHover={!selected} />',- ).length - 1,+ PICKERS.split("<VramBadge status={vramStatus} revealOnHover={!selected} />")+ .length - 1,2,"both model row slots reveal on hover",);+ // A selected row is exempt from dimming, so hiding its mark too left it with no verdict at all+ // until hovered, which is nothing at rest and nothing on touch.+ assert.match(PICKERS, /exceeds &&\n\s*!selected &&/);+});++test("chat and the Hub answer the fit question with one formula", () => {+ // The picker carried its own rule: 0.7 of GPU plus 0.7 of RAM against the raw file size, with a+ // comment claiming it matched _select_gpus. The loader admits against the saved VRAM Budget or+ // 0.97, over weights PLUS estimated KV, so 0.7 matched neither the loader nor the Hub badge.+ assert.ok(+ CATALOG.includes("return classifyGgufFitForDevice(sizeBytes, budget);"),+ "the catalog classifier delegates",+ );+ assert.ok(+ RECOMMENDED.includes('from "../../../../lib/gguf-fit.ts"'),+ "and so does the Recommended fit filter",+ );+ // No copy of the old budget survives in either GGUF path.+ assert.ok(+ !RECOMMENDED.includes("* 0.7"),+ "recommended-fit has no 0.7 budget left",+ );+ assert.ok(!PICKERS.includes("* 0.7"), "pickers has no 0.7 budget left");+ // model-catalog keeps one, and only for the media pickers: a GGUF offered on Images or Video is+ // placed by the diffusion backend, whose budget is far below llama.cpp's. On a 64 GiB Mac that+ // planner allows about 43.5 GiB, this rule 44.8, the llama.cpp rule 62.1. The boundaries are+ // asserted for real in model-catalog.check.ts.+ assert.ok(CATALOG.includes("export function classifyMediaGgufFit("));+ assert.match(+ PICKERS,+ /if \(diffusionLoad\) \{\n\s*return classifyMediaGgufFit\(/,+ );+ // Diffusion tasks only. Audio is task-scoped too but runs its GGUFs under llama.cpp (TTS) and+ // the whisper sidecars (ASR), so scoring it at 70% hid runnable models and shrank the quant.+ assert.ok(PICKERS.includes("const DIFFUSION_TASKS: ReadonlySet<string>"));+ assert.match(PICKERS, /\.\.\.IMAGE_GEN_TASKS,\n\s*\.\.\.VIDEO_GEN_TASKS,/);+ assert.ok(+ !PICKERS.includes("mediaLoad: taskScoped,"),+ "no task-wide media rule",+ );+ assert.ok(RECOMMENDED.includes("mediaLoad: opts.diffusionLoad"));+ // The RULE and the DEVICE SOURCE both follow the runtime that places the row. A diffusion load+ // is torch whatever the file format is, and on a Vulkan chat build inferenceGpu is a different+ // device set: it can see a card torch cannot, so a media GGUF was badged and recommended+ // against capacity the diffusion loader never gets.+ assert.ok(+ RECOMMENDED.includes(+ "opts.diffusionLoad || !opts.isGguf ? opts.gpu : opts.inferenceGpu",+ ),+ );+ assert.ok(+ PICKERS.includes(+ "diffusionLoad || !r.isGguf ? rowGpu : rowInferenceGpu",+ ),+ );+ assert.ok(+ PICKERS.includes("const expanderBudgetGpu = diffusionLoad ? gpu : inferenceGpu;"),+ );+ // And every expander reads that one budget, rather than reaching for inferenceGpu itself.+ assert.ok(+ !PICKERS.includes("inferenceGpu.systemRamAvailableGb"),+ "no expander takes the GGUF backend's RAM directly",+ );+ // The custom-folder expander was the one that kept reaching for the raw aggregate: on a media+ // page it classified against memory the diffusion loader never sees, and it was not even+ // load-scoped. Every row-level budget in this file now comes from the one chosen source.+ assert.ok(+ !PICKERS.includes("inferenceGpu.memoryTotalGb"),+ "no row takes the GGUF backend's capacity directly",+ );+ assert.ok(+ !PICKERS.includes("budgetKnown={inferenceGpu.budgetKnown}"),+ "and none takes its probe state either",+ );+ assert.equal(+ PICKERS.split("gpuGb={expanderGpuGb}").length - 1,+ 9,+ "seven expanders and the two quant rows beside them",+ );+ // The Hub card answers llama.cpp's question, so it must not answer it about a diffusion repo:+ // an oom there would read "still works with offloading" for a load the planner refuses.+ assert.ok(+ HUB_CARD.includes(+ "const showFitInfo = !mediaRuntime && (Boolean(gpuGb) || Boolean(systemRamGb));",+ ),+ );+ assert.match(+ INSPECTOR,+ /showMemoryBar=\{!runsOnMediaRuntime\}\n\s*mediaRuntime=\{runsOnMediaRuntime\}/,+ );+ // Parent rows and the fit gate take the same rule as the quant rows under them, or a media row+ // reads as fitting while everything inside it reads as oom.+ assert.match(PICKERS, /diffusionLoad\n\s*\? classifyMediaGgufFit\(/);+ // Both gates read the flag the same way, or one hides a row the other keeps.+ assert.ok(PICKERS.includes("mediaLoad: diffusionLoad,"));+ // And every media call site sets the flag, or the guard silently does nothing.+ assert.equal(+ PICKERS.split("diffusionLoad={diffusionLoad}").length - 1,+ 7,+ "every task-scoped expander",+ );+ // The RAM tier is dropped on a host pool, or the media rule adds the APU's window to the very+ // RAM it is a window INTO and returns partial for a load the planner refuses.+ assert.ok(PICKERS.includes("function mediaRamBudgetGb("));+ assert.ok(+ PICKERS.includes("return hostPooled ? 0 : systemRamGb;"),+ "no RAM budget beside a host pool",+ );+ assert.ok(+ RECOMMENDED.includes("hostPooledMemory ? 0 : (systemRamGb ?? 0)"),+ "the gate drops it too",+ );+ // The saved VRAM Budget now reaches chat. Moving the slider used to change the Hub's verdicts+ // and leave the picker's untouched.+ assert.ok(PICKERS.includes("useVramBudgetFraction()"));+ assert.ok(PICKERS.includes("budgetFraction,"));+ // Threaded through the row filters as well. Passing it to the quant rows alone left the parent+ // rows and the "Fits on device" gate scoring against the 0.97 default.+ assert.ok(HUB_PAGE.includes("useVramBudgetFraction()"));+ assert.ok(RECOMMENDED.includes("budgetFraction?: number;"));+ // Both surfaces count the cards, or the Hub badge and the picker badge diverge again the moment+ // the VRAM Budget goes above the default on a multi-GPU host. The two row gates take it from+ // the SCOPED source, which is 1 for a media row and the host count otherwise.+ assert.ok(HUB_PAGE.includes("gpuCount: source.deviceCount"));+ assert.ok(HUB_PAGE.includes("gpuCount: inferenceGpu.deviceCount"));+ // And both gates ask one helper, which picks the budget by the runtime that places the row: an+ // image or video repo goes to the diffusion planner on one torch device, under the media rule.+ // Judged by llama.cpp the Hub kept a 52 GiB media GGUF that clears 62.1 GiB on a 64 GiB Mac+ // and blows the planner's 44.8.+ assert.equal(+ HUB_PAGE.split("rowFitsDevice(row.result)").length - 1,+ 2,+ "both Hub fit gates",+ );+ assert.ok(+ HUB_PAGE.includes(+ "mediaRow || !result.isGguf ? gpu : inferenceGpu,",+ ),+ );+ assert.ok(HUB_PAGE.includes("mediaLoad: mediaRow,"));+ assert.ok(+ HUB_PAGE.includes(+ "studioPageForTask(result.pipelineTag) !== undefined",+ ),+ );+ // The count is narrowed WITH the capacity, so it can never describe a different inventory than+ // the gpuGb beside it. A task page puts the load on one device; charging the per-card reserve+ // once per host GPU against that one card scored an audio quant at 23.28 GiB where the loader+ // offers the selected card's 23.5.+ assert.ok(RECOMMENDED.includes("deviceCount: 1,"), "scoped to one device");+ assert.ok(PICKERS.includes("gpuCount: rowInferenceGpu.deviceCount"));+ assert.ok(RECOMMENDED.includes("gpuCount: source.deviceCount ?? opts.gpuCount"));+ assert.ok(+ !PICKERS.includes("gpuCount={inferenceGpu.deviceCount}"),+ "never the unscoped host count",+ );+ // Counted against the expanders themselves, not a fixed 7: the fine-tuned / exported GGUF list+ // is the eighth and was missed, so its host read as one card and over-budgeted at a 1.0 setting.+ assert.equal(+ PICKERS.split("gpuCount={expanderGpuCount}").length - 1,+ 7,+ "every task-scoped expander counts the scoped inventory",+ );+ assert.equal(+ PICKERS.split("gpuCount={gpu.deviceCount}").length - 1,+ 1,+ "the exported GGUF list counts its own host",+ );+ assert.equal(+ PICKERS.split("<GgufVariantExpander").length - 1,+ 8,+ "and that is every expander there is",+ );+ // The APU window comes out of the RAM tier where the figure is built, so every rule downstream+ // sees one pool counted once.+ assert.ok(+ GPU_INFO.includes("shared_memory: sharesHostMemory({"),+ "the RAM tier folds unified in",+ );+ assert.ok(HUB_CARD.includes("gpuCount?: number;"));+ assert.ok(RECOMMENDED.includes("budgetFraction: opts.budgetFraction,"));});test("each fit verdict is an info mark that explains itself", () => {- // A pill shouted a three letter acronym; the mark says what it means on hover. Tight spills- // past VRAM into system RAM, oom clears neither budget, so the two hints differ.+ // A pill shouted a three letter acronym; the mark says what it means on hover.assert.ok(PICKERS.includes("icon={InformationCircleIcon}"));- // A GGUF over budget still loads: llama-server hands it to --fit.+ // Keyed by the Hub's five classes, which is how the picker gained the tier it was missing:+ // over budget but still card-sized needs no system RAM, so it fires on unified memory too.+ assert.ok(PICKERS.includes("marginal: MIGHT_FIT"));+ assert.ok(PICKERS.includes("partial: OFFLOADS"));+ // Every over-budget GGUF says the same thing, however far over. llama-server never refuses one+ // on size: _select_gpus returns use_fit and --fit offloads the rest. Splitting the copy here hid+ // the honest answer on unified memory, where the RAM tier cannot fire and everything reads oom.+ assert.ok(PICKERS.includes("oom: OFFLOADS"));+ // A torch pipeline has no --fit, so that one keeps a refusal.+ assert.ok(PICKERS.includes("exceeds: WONT_FIT"));assert.ok(PICKERS.includes(- "hint: \"Model may not fit but still works with offloading. Expect slower inference.\"",+ 'hint: "Needs more memory than this device has. This model will not load."',),);- // A model row's `tight` comes from checkVramFit, which is 75-100% of VRAM: it fits on the card- // entirely, so telling that row it spills into system RAM was false. The two vocabularies now- // get their own copy, chosen at the call site.+ assert.ok(!PICKERS.includes("Larger than your VRAM and system RAM together"));+ // The training estimator's three words map onto those rather than carrying their own copy.+ // `tight` reaches the badge only from checkVramFit's 75-100% band, a torch estimate that still+ // fits on the card. Aliasing it to the GGUF copy told those rows they spill into system RAM.+ assert.ok(PICKERS.includes("tight: DEVICE_TIGHT"));assert.ok(PICKERS.includes(- 'hint: "Only fits by spilling into system RAM. Expect slower inference."',+ 'hint: "Uses nearly all your VRAM, with little headroom for anything else."',),);+ // Only oom fails to load, so only its hint says so; partial offloads and runs slower.assert.ok(PICKERS.includes(- 'hint: "Uses nearly all your VRAM, with little headroom for anything else."',+ 'hint: "Model may not fit but still works with offloading. Expect slower inference."',),);- // And a model row's `exceeds` no longer promises a slow load: it can be a curated pipeline whose- // loader refuses CPU offload outright.+ // The Hub says it in the same words, which is the point of sharing the classifier.assert.ok(- PICKERS.includes('hint: "Needs more memory than this device has."'),+ HUB_CARD.includes(+ '"Model may not fit but still works with offloading. Expect slower inference."',+ ),);- assert.ok(PICKERS.includes('source="gguf"'));- assert.ok(PICKERS.includes('source="device"'));- // A selected over-budget row is exempt from dimming, so hiding its mark left it with no verdict- // at all until hovered, which is nothing at rest and nothing on touch.- assert.match(PICKERS, /exceeds &&\n\s*!selected &&/);- // And the mark suppresses the button it sits inside, so reading it cannot start a download.- assert.match(PICKERS, /onClick=\{\(event\) => \{\n\s*event\.preventDefault\(\);/);- // Both marks are reachable by screen readers without the tooltip.+ // Neither surface makes a marginal offload conditional on other apps. _vram_usable_mib gives+ // free - reserve, which on a completely idle card IS the budget this tier has already passed,+ // so _select_gpus takes --fit every time; other apps only shrink free further. Saying it+ // "fits with almost no room to spare" promised a resident load the loader never admits.+ const mightFitHint =+ "Larger than your VRAM Budget allows, so part of it offloads even on an idle GPU. It is still smaller than the card, so raising the budget can keep it resident.";+ assert.ok(PICKERS.includes(mightFitHint));+ assert.ok(HUB_CARD.includes(mightFitHint));+ assert.ok(+ !PICKERS.includes("If other apps are using VRAM"),+ "no conditional offload copy",+ );+ assert.ok(!HUB_CARD.includes("If other apps are using VRAM"));+ assert.ok(!PICKERS.includes('label: "Might fit"'));+ assert.ok(!HUB_CARD.includes('label: "Might fit"'));+ assert.ok(!PICKERS.includes("Loading can fail while other apps"));+ assert.ok(!HUB_CARD.includes("Within the last GB of VRAM headroom"));+ // The Hub's oom row says it too, so the two surfaces read alike on a host where every+ // over-budget quant lands in that class.+ assert.ok(!HUB_CARD.includes('label: "Won\'t fit"'));+ assert.equal(+ HUB_CARD.split(+ '"Model may not fit but still works with offloading. Expect slower inference."',+ ).length - 1,+ 2,+ "partial and oom both",+ );++ // Marks are reachable by screen readers without the tooltip.+ assert.ok(PICKERS.includes('label: "Over budget"'));assert.ok(PICKERS.includes('label: "Does not fit"'));- assert.ok(PICKERS.includes('label: "Tight fit"'));+ // "will not load" is right for `exceeds`, which only ever comes from a torch row: inference.py+ // calls raise_if_offloaded after loading, and that raises ValueError on any CPU or disk offload+ // ("Inference does not support models loaded with CPU or disk offload"). A GGUF over budget is+ // handed to --fit instead, which is why it says the opposite.+ assert.ok(+ PICKERS.includes(+ 'hint: "Needs more memory than this device has. This model will not load."',+ ),+ );assert.ok(PICKERS.includes("aria-label={verdict.label}"));+ // An over-budget figure is a TOTAL: `partial` splits across VRAM and RAM, and the number is+ // weights plus activations plus KV, so "Needs ~47GB VRAM" argued with the offload verdict.+ assert.ok(+ PICKERS.includes("`Needs ~${vramEst}GB memory (GPU: ${gpuGb}GB)`"),+ );+ assert.ok(!PICKERS.includes("GB VRAM (GPU:"), "no VRAM wording on an overage");+ // A load that stays on the card still says VRAM, which is what it means there.+ assert.ok(PICKERS.includes("GB VRAM (tight fit on"));+ // A marginal row is a full GPU load, so it is not dimmed with the over budget ones.+ assert.ok(+ PICKERS.includes(+ 'return status === "partial" || status === "ram" || status === "oom" || status === "exceeds";',+ ) || /function isOverBudget[\s\S]{0,320}"exceeds"/.test(PICKERS),+ "dimming covers the orange verdicts only",+ );+});++test("a GGUF row takes the GGUF verdict, not the torch refusal", () => {+ // This branch used to set "exceeds", the one verdict that says a model will not load. A GGUF is+ // offloaded by llama-server rather than refused, so the row said the opposite of what happens,+ // and it is the verdict shown on the Recommended list where most rows are over budget.+ assert.ok(PICKERS.includes("status: ggufRowFit(sizeBytes, rowInferenceGpu),"));+ // A boolean here collapsed marginal and partial into "no badge", so a repo whose smallest quant+ // already needed offload rendered as a clean fit beside variant rows saying otherwise.+ assert.ok(!PICKERS.includes("exceedsSize"));+ assert.match(+ PICKERS,+ /const ggufRowFit = \([\s\S]{0,220}\): GgufFitClass \| VramFitStatus \| null =>/,+ );+ // Every surviving producer of "exceeds" is a curated torch pipeline, which has no --fit.+ const producers = PICKERS.split("\n").filter(+ (line) => line.includes('"exceeds"') && line.includes("status:"),+ );+ assert.equal(producers.length, 2, "curated rows only");+ for (const line of producers) {+ assert.match(line, /curatedFits \? null : "exceeds"/);+ }+});++test("a diffusion model too big for a shared pool is refused, not offloaded", () => {+ // diffusion_memory.py refuses up front on unified memory: offload "moves bytes within that pool+ // and frees nothing", and without the refusal the load "allocates past physical memory" with+ // "the failure is the OS killing the process with no Python exception". Saying it still works+ // with offloading is the worst thing this badge could say there.+ assert.ok(PICKERS.includes("function diffusionRefuses("));+ assert.ok(+ PICKERS.includes('return fit === "oom" && diffusionLoad && hostPooled;'),+ );+ // The LOAD DEVICE's pool, folding unified_memory in. hardware.py sets shared_memory only on+ // Windows, so a Linux ROCm APU arrives unified true / shared false while diffusion_memory.py+ // still calls it unified_memory and refuses. The aggregate shared flag missed that host.+ assert.ok(!PICKERS.includes("gpu.sharedMemory"), "not the aggregate flag");+ assert.ok(+ GPU_INFO.includes("loadDeviceSharesHostMemory: sharesHostMemory({"),+ "the flag is the load device's, folded",+ );+ // Both the quant rows and the parent row take it.+ assert.match(+ PICKERS,+ /diffusionRefuses\(fit, diffusionLoad, hostPooledMemory\)\n\s*\? "exceeds"/,+ );+ assert.ok(+ PICKERS.includes(+ "diffusionRefuses(fit, diffusionLoad, gpu.loadDeviceSharesHostMemory)",+ ),+ );+ // On a shared pool "VRAM" would name a number the user does not have.+ assert.ok(+ PICKERS.includes(+ 'hint: "Needs more memory than this device has. This model will not load."',+ ),+ );+ assert.equal(+ PICKERS.split("hostPooledMemory={gpu.loadDeviceSharesHostMemory}").length -+ 1,+ 7,+ "every task-scoped expander learns the pool kind",+ );+});++test("the row tooltip reports the figure the verdict was reached with", () => {+ // classifyGgufFit scores weights PLUS activations and KV, so a 20 GiB quant needing 24 GiB read+ // "tight fit" beside a tooltip saying "~20GB VRAM". The media rule scores raw size, so it keeps+ // the raw number.+ assert.ok(PICKERS.includes("requiredGgufMemoryGb(sizeBytes)"));+ assert.match(+ PICKERS,+ /diffusionLoad\n\s*\? sizeBytes \/ 1024 \*\* 3\n\s*: requiredGgufMemoryGb\(sizeBytes\)/,+ );});test("aligned meta slots spend their slack on the name", () => {diff --git a/studio/frontend/tests/recommended-catalog-seeds.test.ts b/studio/frontend/tests/recommended-catalog-seeds.test.tsindex 6e8d83b6442..5c6c01af40b 100644--- a/studio/frontend/tests/recommended-catalog-seeds.test.ts+++ b/studio/frontend/tests/recommended-catalog-seeds.test.ts@@ -9,6 +9,7 @@ import {VIDEO_CATALOG,curatedSizeBytesFor,} from "../src/features/model-picker/components/model-selector/model-catalog.ts";+import { classifyGgufFit } from "../src/lib/gguf-fit.ts";import {hfModelFitsDevice,loadScopedGpu,@@ -84,7 +85,11 @@ test("a listing row that passes the filters takes over its seed, in catalog orde});test("device fit is judged on whichever row renders", () => {- const small = { memoryTotalGb: 6, systemRamAvailableGb: 0, budgetKnown: true };+ const small = {+ memoryTotalGb: 6,+ systemRamAvailableGb: 0,+ budgetKnown: true,+ };const big = { memoryTotalGb: 80, systemRamAvailableGb: 0, budgetKnown: true };const listedLtx: Row = {id: LTX,@@ -129,7 +134,11 @@ test("device fit is judged on whichever row renders", () => {});test("an unlisted seed is sized from its id, and hidden when it cannot be", () => {- const small = { memoryTotalGb: 6, systemRamAvailableGb: 0, budgetKnown: true };+ const small = {+ memoryTotalGb: 6,+ systemRamAvailableGb: 0,+ budgetKnown: true,+ };// "LTX-2.3" has no "<n>B" token, so requireKnown hides it; "klein-9B" reads// as 9B -> 3.6 GB, inside the 4.2 GB budget.assert.equal(hfModelFitsDevice(SEEDS[0], small), false);@@ -161,7 +170,11 @@ const seed = (id: string, catalog = IMAGE_CATALOG): Row => ({test("a catalog-sized seed is judged on the catalog size, not on its id", () => {// 24 GB card -> 16.8 GB budget.- const card = { memoryTotalGb: 24, systemRamAvailableGb: 0, budgetKnown: true };+ const card = {+ memoryTotalGb: 24,+ systemRamAvailableGb: 0,+ budgetKnown: true,+ };const sdxl = seed(SDXL);const wan = seed(WAN, VIDEO_CATALOG);// SDXL Turbo is 8 GB but its id has no "<n>B" token to guess from; Wan 2.2@@ -185,7 +198,11 @@ test("a catalog-sized seed is judged on the catalog size, not on its id", () =>});test("a listing row still overrides the catalog size it seeded with", () => {- const card = { memoryTotalGb: 24, systemRamAvailableGb: 0, budgetKnown: true };+ const card = {+ memoryTotalGb: 24,+ systemRamAvailableGb: 0,+ budgetKnown: true,+ };// GGUF groups carry no catalog size, so an unsized GGUF seed stays hidden.assert.equal(curatedSizeBytesFor(LTX, VIDEO_CATALOG), undefined);assert.equal(hfModelFitsDevice({ id: LTX, isGguf: true }, card), false);@@ -256,6 +273,16 @@ test("a task row is sized against the device the load lands on", () => {const sdxl = seed(SDXL);assert.equal(hfModelFitsDevice(sdxl, twoCards), true);assert.equal(hfModelFitsDevice(sdxl, loadScopedGpu(twoCards, true)), false);+ // The device COUNT narrows with the capacity. classifyGgufFit charges the loader's per-card VRAM+ // reserve once per card, so leaving the host count of 2 on a one-card budget held back two+ // floors against a single device and under-budgeted every scoped quant.+ assert.equal(loadScopedGpu(twoCards, false).deviceCount, undefined);+ assert.equal(loadScopedGpu(twoCards, true).deviceCount, 1);+ const twoOfThree = { ...twoCards, deviceCount: 3 };+ assert.equal(loadScopedGpu(twoOfThree, false).deviceCount, 3);+ assert.equal(loadScopedGpu(twoOfThree, true).deviceCount, 1);+ // An unscoped load keeps the host count, so chat still charges one floor per card.+ assert.equal(loadScopedGpu(twoOfThree, true).memoryTotalGb, 8);});test("a dedicated task device keeps RAM reserved by a shared GPU", () => {@@ -278,6 +305,53 @@ test("a dedicated task device keeps RAM reserved by a shared GPU", () => {assert.equal(loadScopedGpu(mixedHost, true).systemRamAvailableGb, 40);assert.equal(loadScopedGpu(sharedLoadDevice, true).systemRamAvailableGb, 8);assert.equal(loadScopedGpu(mixedHost, false), mixedHost);++ // A Linux ROCm APU reports unified_memory without shared_memory, so it used to take the+ // raw-host branch above and undo the very subtraction that keeps its GTT window out of the RAM+ // tier. The folded flag is what the reservation question actually turns on.+ const linuxApu = {+ ...mixedHost,+ loadDeviceMemoryGb: 32,+ loadDeviceSharedMemory: false,+ loadDeviceSharesHostMemory: true,+ };+ assert.equal(loadScopedGpu(linuxApu, true).systemRamAvailableGb, 8);+ // The dedicated card still claims it back: this gate narrowed, it did not close.+ assert.equal(+ loadScopedGpu({ ...linuxApu, loadDeviceSharesHostMemory: false }, true)+ .systemRamAvailableGb,+ 40,+ );+});++test("a unified GPU window is not also offered as system RAM", () => {+ // 48 GiB host, a 32 GiB GTT window. gpuMemoryTotalsGb counts that window as DEDICATED when+ // shared_memory is false, so systemRamAvailableGb kept the whole 48 and classifyGgufFit added+ // half of it to the window a second time: a ~43 GiB file needing ~50 scored `partial` against+ // an invented ~55 GiB budget, promising an offload into memory the machine does not have.+ const apu = {+ available: true,+ budgetKnown: true,+ memoryTotalGb: 32,+ maxDeviceMemoryGb: 32,+ loadDeviceMemoryGb: 32,+ loadDeviceSharedMemory: false,+ loadDeviceSharesHostMemory: true,+ systemRamAvailableHostGb: 48,+ deviceCount: 1,+ };+ const scoped = (systemRamAvailableGb: number) =>+ loadScopedGpu({ ...apu, systemRamAvailableGb }, true);+ const verdict = (g: ReturnType<typeof scoped>) =>+ classifyGgufFit(43 * 1024 ** 3, {+ gpuGb: g.memoryTotalGb,+ systemRamGb: g.systemRamAvailableGb,+ gpuCount: g.deviceCount,+ });+ // Unsubtracted, the way a Linux APU used to arrive.+ assert.equal(verdict(scoped(48)), "partial");+ // Subtracted once, the way Windows and Apple Silicon always were.+ assert.equal(verdict(scoped(48 - 32)), "oom");});test("both search lists judge a curated id the same way", () => {@@ -303,6 +377,74 @@ test("both search lists judge a curated id the same way", () => {assert.equal(searchRowFitsDevice({ id: BNB, totalParams: 6e9 }, opts), false);});+test("the Hub fit gate judges a media GGUF by the planner that places it", () => {+ // The reported case: 52 GiB of video GGUF on a 64 GiB Mac. llama.cpp allows 52 * 1.15 + 1 =+ // 60.8 against a 63.5 GiB budget, so the "Fits on device" filter kept it; the diffusion planner+ // allows 44.8 and cannot offload on a host pool, so it never places.+ const mac = {+ available: true,+ budgetKnown: true,+ memoryTotalGb: 64,+ maxDeviceMemoryGb: 64,+ loadDeviceMemoryGb: 64,+ loadDeviceSharedMemory: true,+ loadDeviceSharesHostMemory: true,+ systemRamAvailableGb: 0,+ systemRamAvailableHostGb: 64,+ deviceCount: 1,+ };+ const row = {+ id: "unsloth/Some-Video-GGUF",+ isGguf: true,+ estimatedSizeBytes: 52 * 1024 ** 3,+ };+ assert.equal(hfModelFitsDevice(row, mac, { gpuCount: 1 }), true);+ const scoped = loadScopedGpu(mac, true);+ assert.equal(+ hfModelFitsDevice(row, scoped, {+ gpuCount: scoped.deviceCount,+ mediaLoad: true,+ hostPooledMemory: true,+ }),+ false,+ );+});++test("a media GGUF is sized against torch, not the GGUF backend", () => {+ // A Vulkan llama.cpp build sees cards torch cannot, so inferenceGpu is a different inventory+ // (use-gpu-info.ts keeps the torch view for diffusion for exactly this reason). Picking the+ // budget by FILE FORMAT sent an Images GGUF to the Vulkan card's capacity, which the diffusion+ // loader never gets to use.+ const vulkanCard = {+ available: true,+ budgetKnown: true,+ memoryTotalGb: 24,+ maxDeviceMemoryGb: 24,+ loadDeviceMemoryGb: 24,+ systemRamAvailableGb: 0,+ };+ const torchCard = { ...vulkanCard, memoryTotalGb: 12, maxDeviceMemoryGb: 12, loadDeviceMemoryGb: 12 };+ // 14 GiB: inside the 24 GiB card's media budget (16.8), past the 12 GiB one's (8.4).+ const row = { id: "unsloth/Some-Image-GGUF", estimatedSizeBytes: 14 * 1024 ** 3 };+ const opts = {+ isGguf: true,+ gpu: torchCard,+ inferenceGpu: vulkanCard,+ taskScoped: true,+ diffusionLoad: true,+ };+ assert.equal(searchRowFitsDevice(row, opts), false);+ // Chat is the case the GGUF backend's own inventory is right for, and it still gets it.+ assert.equal(+ searchRowFitsDevice(row, {+ ...opts,+ taskScoped: false,+ diffusionLoad: false,+ }),+ true,+ );+});+test("a search row is sized against the device a task load lands on", () => {const twoCards = {available: true,@@ -341,3 +483,32 @@ test("a GPU-less host keeps its unified-memory budget", () => {};assert.equal(loadScopedGpu(mac, true), mac);});++test("a media row is judged by the rule its quant rows use", () => {+ // Images / Video place a GGUF through the diffusion backend, whose budget on a 64 GiB unified+ // host is (total - 20% reserve) * 0.85 = 43.5 GiB (diffusion_memory.py). llama.cpp allows 62.1.+ // Judging the parent row by one and its quants by the other let a row read as fitting while+ // everything inside it read as oom.+ const mac = { memoryTotalGb: 64, systemRamAvailableGb: 0, budgetKnown: true };+ const row = {+ id: "unsloth/Some-Image-Model-GGUF",+ isGguf: true,+ // 50 GiB, which the two rules disagree about: 50 > 44.8, but 50 * 1.15 + 1 = 58.5 <= 62.1.+ curatedSizeBytes: 50 * 1024 ** 3,+ };+ assert.equal(+ hfModelFitsDevice(row, mac),+ true,+ "chat keeps the llama.cpp rule",+ );+ assert.equal(+ hfModelFitsDevice(row, mac, { mediaLoad: true }),+ false,+ "a media row does not",+ );+ // Every format on a task page, not just GGUF: this rule is the budget all of them had before the+ // classifiers were merged, and restricting it to GGUF left the list gate and the search gate+ // answering differently for one row.+ const safetensors = { ...row, id: "unsloth/Some-Image-Model", isGguf: false };+ assert.equal(hfModelFitsDevice(safetensors, mac, { mediaLoad: true }), false);+});diff --git a/studio/frontend/tests/recommended-curated-row-metadata.test.ts b/studio/frontend/tests/recommended-curated-row-metadata.test.tsindex e11a3c9ddb4..179c1da83ee 100644--- a/studio/frontend/tests/recommended-curated-row-metadata.test.ts+++ b/studio/frontend/tests/recommended-curated-row-metadata.test.ts@@ -283,8 +283,12 @@ for (const declaration of ["recommendedMeta", "recommendedVramMap"]) {assert.ok(estimatorAt >= 0, `${declaration} no longer estimates VRAM at all`);assert.ok(curatedAt < estimatorAt, "the QLoRA estimator runs first");// A task load puts the whole pipeline on one device, and torch is not the GGUF backend's- // inventory, so the budget is the load-scoped one the list's own fit filter uses.- assert.match(text, /artifactBudget\(loadScopedGpu\(gpu, Boolean\(task\)\)\)/);+ // inventory, so the budget is the load-scoped one the list's own fit filter uses. Inline or+ // via a local, as long as what reaches artifactBudget went through loadScopedGpu(gpu, ...).+ assert.match(+ text,+ /artifactBudget\(loadScopedGpu\(gpu, Boolean\(task\)\)\)|rowGpu = loadScopedGpu\(gpu, Boolean\(task\)\);[\s\S]{0,400}artifactBudget\(rowGpu\)/,+ );});}@@ -306,10 +310,19 @@ test("every list that judges a row against the device asks the same helper", ()});test("GGUF rows keep the inference backend's budget", () => {- // They load through llama.cpp, so its inventory is the right one for them.+ // They load through llama.cpp, so its inventory is the right one for them, load-scoped the way+ // the quant rows and the fit filter scope it: a task load lands on ONE device, and judging the+ // parent by the multi-GPU sum let a downloaded media row read as safe over oom variants.+ assert.match(+ declarationText("recommendedMeta"),+ /ggufRowFit\(sizeBytes, rowInferenceGpu\)/,+ );+ // And it is the inventory of the runtime that PLACES the row, not of its file format: an+ // Images or Video GGUF goes to torch, which on a Vulkan chat build is a different device set+ // than llama.cpp reports.assert.match(declarationText("recommendedMeta"),- /exceedsSize\(sizeBytes, inferenceGpu\)/,+ /rowInferenceGpu = diffusionLoad\n\s*\? rowGpu\n\s*: loadScopedGpu\(inferenceGpu, Boolean\(task\)\)/,);});