The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(gpu): der Fit-Check zeigt nie wieder den System-RAM als VRAM
purple5b1c7441e844
diff --git a/src/api/__tests__/fit-check-never-shows-system-ram.test.ts b/src/api/__tests__/fit-check-never-shows-system-ram.test.tsnew file mode 100644index 00000000..e2024bb0--- /dev/null+++ b/src/api/__tests__/fit-check-never-shows-system-ram.test.ts@@ -0,0 +1,165 @@+/**+ * @vitest-environment jsdom+ *+ * A5, GitHub #123 (Zhorts, 2026-09-01, Windows 11, RX 9070 XT, 64 GB RAM).+ *+ * The Model Manager fit check read "62 GB GPU · 62 GB RAM": the same number+ * twice, on a machine with a 16 GB card, while the Settings page one tab away+ * had the correct 16 GB. Two probes feed that chip and DiscoverModels keeps the+ * LARGER of the two, so one wrong number is enough to win.+ *+ * The wrong number came from ComfyUI. Without a usable GPU backend, and no ROCm+ * was detected on that box, ComfyUI still reports one device in /system_stats:+ * the CPU one, whose `vram_total` is `psutil.virtual_memory().total`. It is+ * system RAM in a field called vram_total, and `devices[0].vram_total` took it.+ *+ * The rule this file pins: system RAM never appears as VRAM, and where nothing+ * measured the GPU the answer is the word "unknown", not a number. A fit check+ * that admits it does not know is one a user can still act on. One that says+ * 62 GB sends him to download a model his card cannot hold.+ *+ * Run: npx vitest run src/api/__tests__/fit-check-never-shows-system-ram.test.ts+ */+import { describe, it, expect, vi, beforeEach } from 'vitest'+import { createElement } from 'react'+import { render, screen, cleanup } from '@testing-library/react'++const localFetch = vi.fn()++vi.mock('../backend', () => ({+ localFetch: (...a: unknown[]) => localFetch(...a),+ comfyuiUrl: (p: string) => `http://localhost:8188${p}`,+ fetchLocalhostBytes: vi.fn(),+ isTauri: () => false,+ backendCall: vi.fn(),+}))++import { pickDeviceVramBytes } from '../comfyui'+import { HardwareChip } from '../../components/models/ModelTiles'+import { comfyErrorHint } from '../vram-handoff'++const GB = 1024 * 1024 * 1024++/** Zhorts' box: ComfyUI on the processor, so one device and it is the CPU. */+const CPU_ONLY = [+ { name: 'cpu', type: 'cpu', index: null, vram_total: 62 * GB, vram_free: 40 * GB, torch_vram_total: 0, torch_vram_free: 0 },+]++/** The same box once a ROCm build is in place. */+const HIP_CARD = [+ { name: 'cuda:0 AMD Radeon RX 9070 XT : hipMallocAsync', type: 'cuda', index: 0, vram_total: 16 * GB, vram_free: 15 * GB },+]++beforeEach(() => {+ localFetch.mockReset()+ cleanup()+})++describe('the CPU pseudo-device is not a graphics card', () => {+ it('drops a CPU-only device list instead of calling its RAM VRAM', () => {+ // NEGATIVE CONTROL, backwards: this is exactly what the old reader did, and+ // it is where the 62 came from.+ expect(Math.round((CPU_ONLY[0].vram_total as number) / GB)).toBe(62)+ expect(pickDeviceVramBytes(CPU_ONLY)).toBeNull()+ })++ it('still reports a real card', () => {+ expect(pickDeviceVramBytes(HIP_CARD)).toBe(16 * GB)+ })++ it('ignores the CPU entry sitting next to a card', () => {+ // ComfyUI lists both on some builds. The card decides, not whichever entry+ // the list happened to put first.+ expect(pickDeviceVramBytes([...CPU_ONLY, ...HIP_CARD])).toBe(16 * GB)+ expect(pickDeviceVramBytes([...HIP_CARD, ...CPU_ONLY])).toBe(16 * GB)+ })++ it('leaves Apple unified memory alone', () => {+ // On a Mac the mps device really does have the machine's memory as its+ // VRAM, so this one is a right answer and must survive.+ const mps = [{ name: 'mps', type: 'mps', index: 0, vram_total: 32 * GB }]+ expect(pickDeviceVramBytes(mps)).toBe(32 * GB)+ })++ it('answers null for every shape that says nothing', () => {+ // NEGATIVE CONTROLS: an unknown payload never turns into a number.+ expect(pickDeviceVramBytes([])).toBeNull()+ expect(pickDeviceVramBytes(undefined)).toBeNull()+ expect(pickDeviceVramBytes(null)).toBeNull()+ expect(pickDeviceVramBytes({ devices: HIP_CARD })).toBeNull()+ expect(pickDeviceVramBytes([{ name: 'cuda:0', type: 'cuda' }])).toBeNull()+ expect(pickDeviceVramBytes([{ name: 'cuda:0', type: 'cuda', vram_total: 0 }])).toBeNull()+ expect(pickDeviceVramBytes([{ name: 'cuda:0', type: 'cuda', vram_total: '16 GB' }])).toBeNull()+ expect(pickDeviceVramBytes([{ name: 'cuda:0', type: 'cuda', vram_total: Infinity }])).toBeNull()+ })++ it('recognises the CPU entry by either field', () => {+ // Older ComfyUI builds name the device without filling `type`.+ expect(pickDeviceVramBytes([{ name: 'cpu', vram_total: 62 * GB }])).toBeNull()+ expect(pickDeviceVramBytes([{ type: 'CPU', name: '', vram_total: 62 * GB }])).toBeNull()+ // NEGATIVE CONTROL: a card whose name merely starts with those letters is+ // not the CPU device. Nothing real is dropped by this rule.+ expect(pickDeviceVramBytes([{ name: 'cpuid test card', type: 'cuda', vram_total: 8 * GB }])).toBe(8 * GB)+ })+})++describe('the hardware chip', () => {+ it('says unknown for the side nothing measured', () => {+ render(createElement(HardwareChip, { vramGb: null, ramGb: 62 }))+ expect(screen.getByText('GPU unknown')).toBeTruthy()+ expect(screen.getByText('62 GB RAM')).toBeTruthy()+ // NEGATIVE CONTROL: the number that was wrong must not be anywhere near the+ // GPU half of the chip.+ expect(screen.queryByText('62 GB GPU')).toBeNull()+ })++ it('shows both numbers when both were measured', () => {+ render(createElement(HardwareChip, { vramGb: 16, ramGb: 62 }))+ expect(screen.getByText('16 GB GPU')).toBeTruthy()+ expect(screen.getByText('62 GB RAM')).toBeTruthy()+ expect(screen.queryByText('GPU unknown')).toBeNull()+ })++ it('stays away entirely when nothing at all is known', () => {+ const { container } = render(createElement(HardwareChip, { vramGb: null, ramGb: null }))+ expect(container.textContent).toBe('')+ })+})++describe('hipErrorInvalidValue names the architecture instead of the error', () => {+ // A12, artoriuskurokami (Discord 2026-09-02, RX 9070 XT): image generation+ // dies with this, the same run on the processor completes.+ const RAW = "CUDA error: invalid argument\nSearch for 'hipErrorInvalidValue' in the ROCm documentation."++ it('names the detected target and the command that lists the build\'s', () => {+ const hint = comfyErrorHint('KSampler', 'RuntimeError', RAW, 'gfx1201')+ expect(hint).toContain('gfx1201')+ expect(hint).toContain('get_arch_list')+ // Rebuilding installs the same wheels, so the advice must not be that.+ expect(hint).not.toContain('Reinstall the ComfyUI environment')+ })++ it('points at the tool when no tool named the architecture', () => {+ const hint = comfyErrorHint('KSampler', 'RuntimeError', RAW, null)+ expect(hint).toContain('hipinfo')+ expect(hint).toContain('get_arch_list')+ // NEGATIVE CONTROL: nothing may be invented for the card. No gfx target and+ // no ROCm version appears when nothing on the machine reported one.+ expect(hint).not.toMatch(/gfx\d/)+ expect(hint).not.toMatch(/\b\d+\.\d+(\.\d+)?\b/)+ })++ it('leaves the other AMD failure to its own message', () => {+ // hipErrorNoBinaryForGPU is a different error with different advice and it+ // was here first. The new branch must not swallow it.+ const other = comfyErrorHint('KSampler', 'RuntimeError', 'hipErrorNoBinaryForGPU: Unable to find code object', 'gfx1030')+ expect(other).toContain('no compute kernels')+ expect(other).not.toContain('hipErrorInvalidValue')+ })++ it('says nothing about HIP for an error that is not about HIP', () => {+ // NEGATIVE CONTROL: a plain CUDA "invalid argument" on an NVIDIA box must+ // not be answered with AMD advice, so the match is on the HIP name alone.+ expect(comfyErrorHint('KSampler', 'RuntimeError', 'CUDA error: invalid argument', 'gfx1201')).toBe('')+ })+})diff --git a/src/api/comfyui.ts b/src/api/comfyui.tsindex 4525eb1e..4fb02ef2 100644--- a/src/api/comfyui.ts+++ b/src/api/comfyui.ts@@ -550,6 +550,53 @@ export async function refreshComfyModels(maxAttempts = 3): Promise<boolean> {let cachedVRAM: number | null = null+/**+ * Is this /system_stats entry ComfyUI's CPU pseudo-device?+ *+ * When torch has no usable GPU backend ComfyUI still reports one device, and+ * for that one `vram_total` is `psutil.virtual_memory().total`. It is system+ * RAM wearing a VRAM field's name.+ */+function isCpuDevice(dev: any): boolean {+ const type = String(dev?.type ?? '').trim().toLowerCase()+ const name = String(dev?.name ?? '').trim().toLowerCase()+ return type === 'cpu' || name === 'cpu' || name.startsWith('cpu:') || name.startsWith('cpu ')+}++/**+ * The largest real VRAM figure in a /system_stats payload, in bytes, or null.+ *+ * Zhorts, GitHub #123: the Model Manager fit check showed "62 GB GPU · 62 GB+ * RAM" on a box with a 16 GB RX 9070 XT and 64 GB of RAM, the same number+ * twice, while the Settings page a tab away had the correct 16 GB. This is+ * where the 62 came from. ROCm was not detected, so his ComfyUI ran on the+ * processor, so /system_stats carried exactly one device, the CPU one, whose+ * `vram_total` is the machine's RAM. The old reader took `devices[0]` whatever+ * it was, and DiscoverModels then kept the LARGER of that and the honest 16 GB+ * from detect_gpus.+ *+ * Two rules, and the second matters as much as the first:+ * - CPU entries are not a GPU and never contribute a size.+ * - When nothing else is left the answer is null, which the UI renders as+ * "unknown". A fit check that says nothing is a fit check a user can still+ * trust; one that says 62 GB sends him to download a model that cannot run.+ *+ * Apple's `mps` device is NOT excluded. Unified memory really is the VRAM+ * there, so the number is right for the machine it comes from.+ *+ * Pure and exported so the case above can be a test instead of a screenshot.+ */+export function pickDeviceVramBytes(devices: unknown): number | null {+ if (!Array.isArray(devices)) return null+ let best = 0+ for (const dev of devices) {+ if (isCpuDevice(dev)) continue+ const bytes = (dev as any)?.vram_total+ if (typeof bytes === 'number' && Number.isFinite(bytes) && bytes > best) best = bytes+ }+ return best > 0 ? best : null+}+export async function getSystemVRAM(): Promise<number | null> {if (cachedVRAM !== null) return cachedVRAMtry {@@ -557,9 +604,8 @@ export async function getSystemVRAM(): Promise<number | null> {if (!res.ok) return nullconst data = await res.json()// ComfyUI returns top-level devices[].vram_total in bytes- const devices = data?.devices ?? []- if (devices.length > 0) {- const vramBytes = devices[0]?.vram_total ?? 0+ const vramBytes = pickDeviceVramBytes(data?.devices)+ if (vramBytes !== null) {cachedVRAM = Math.round(vramBytes / (1024 * 1024 * 1024)) // bytes → GBreturn cachedVRAM}diff --git a/src/api/vram-handoff.ts b/src/api/vram-handoff.tsindex 69c3e915..d993f87f 100644--- a/src/api/vram-handoff.ts+++ b/src/api/vram-handoff.ts@@ -47,6 +47,7 @@import { backendCall, ollamaUrl, localFetch, isOllamaLocal, isWindows } from './backend'import { listRunningModels, loadModel, unloadModel } from './ollama'import { startBundledEngine } from './engine'+import { getAmdGpuArch } from '../lib/hardware'import { useSettingsStore } from '../stores/settingsStore'import {getImageModels,@@ -1488,7 +1489,10 @@ async function pollAndExtract(promptId: string, prompt: string, kindLabel: strin|| history.status.messages?.map((m: any) => m?.[1]?.message).filter(Boolean).join(' | ')|| history.status.messages?.[0]?.[1]?.message|| 'Unknown ComfyUI error'- const hint = comfyErrorHint(errEntry?.node_type, errEntry?.exception_type, String(rawMsg))+ // The architecture only matters for one branch and costs one cached+ // Tauri call, which is cheaper than the render that just failed.+ const arch = await getAmdGpuArch().catch(() => null)+ const hint = comfyErrorHint(errEntry?.node_type, errEntry?.exception_type, String(rawMsg), arch)return `${kindLabel} generation failed: ${rawMsg}${hint ? `\n\n${hint}` : ''}`}const projected = pace.projectedTotalMs()@@ -1520,7 +1524,12 @@ async function pollAndExtract(promptId: string, prompt: string, kindLabel: strin* Returns '' when we have nothing better to add than the verbatim error.* Exported + pure for the unit tests.*/-export function comfyErrorHint(nodeType: string | undefined, _excType: string | undefined, message: string): string {+export function comfyErrorHint(+ nodeType: string | undefined,+ _excType: string | undefined,+ message: string,+ gpuArch?: string | null,+): string {const m = message.toLowerCase()// FramePack wrapper version mismatch (David 2026-06-11, RTX 3060): the// installed ComfyUI-FramePackWrapper's LoadFramePackModel produces a@@ -1543,6 +1552,23 @@ export function comfyErrorHint(nodeType: string | undefined, _excType: string |m.includes('tensilelibrary')) {return 'Your AMD card was found and used, but the ROCm build of PyTorch in this ComfyUI environment carries no compute kernels for this particular chip, so the first step of the render had nothing to run. Rebuilding the environment installs the same wheels and will not change this. Set Settings → Hardware → ComfyUI GPU to Force CPU to render on the processor instead: much slower, but it completes. Running ComfyUI with HSA_OVERRIDE_GFX_VERSION=10.3.0 is the community workaround for RDNA 2 cards; it is not supported by AMD and LU does not set it for you.'}+ // A12 (artoriuskurokami, Discord 2026-09-02, RX 9070 XT): image generation+ // dies on `CUDA error: invalid argument / Search for 'hipErrorInvalidValue'`+ // while the same run on the processor completes. The card is RDNA 4, which is+ // new enough that a ROCm PyTorch built before it has no kernels for the+ // target, and HIP rejects the very first launch instead of saying so.+ //+ // The architecture is NAMED here when a tool named it (gpuArch comes from the+ // HIP SDK's hipinfo via detect_gpus) and otherwise the user is pointed at the+ // two commands that print it. Nothing in this string is a version or a table+ // of which card is which target: both sides are read off the machine.+ if (m.includes('hiperrorinvalidvalue')) {+ const mine = gpuArch ? `Your card reports ${gpuArch}. ` : ''+ const check = gpuArch+ ? `${gpuArch} has to appear in the list printed by`+ : 'Read your card\'s target from the gcnArchName line of hipinfo in the HIP SDK\'s bin folder, then check that it appears in the list printed by'+ return `Your AMD card was found and the render started, but the first HIP call came back with hipErrorInvalidValue. On a recent Radeon this is almost always an architecture mismatch: the chip reports one gfx target and the ROCm build of PyTorch in this ComfyUI environment carries kernels for other ones. ${mine}${check}: python -c "import torch; print(torch.cuda.get_arch_list())" run inside the ComfyUI environment. If it is missing there, rebuilding this environment installs the same wheels and will not add it; you need a PyTorch ROCm build that names your target. Set Settings, Hardware, ComfyUI GPU to Force CPU to finish the render on the processor in the meantime.`+ }if (m.includes('out of memory') || m.includes('outofmemory') || _excType === 'torch.OutOfMemoryError') {return 'Ran out of GPU memory. Try a shorter clip / lower resolution, set VRAM hand-off to "always" in Settings so the chat model is evicted first, or pick a lighter model.'}diff --git a/src/components/models/ModelTiles.tsx b/src/components/models/ModelTiles.tsxindex a1f193a9..a55856b3 100644--- a/src/components/models/ModelTiles.tsx+++ b/src/components/models/ModelTiles.tsx@@ -407,9 +407,18 @@ export function HardwareChip({ vramGb, ramGb }: { vramGb: number | null; ramGb:title="Detected hardware. Used for the 'runs on your PC' hints. Models are never hidden because of it."><HardDrive size={11} className="text-gray-400" />- {vramGb ? <span className="tabular-nums">{Math.round(vramGb)} GB GPU</span> : null}- {vramGb && ramGb ? <span className="opacity-40">·</span> : null}- {ramGb ? <span className="tabular-nums">{Math.round(ramGb)} GB RAM</span> : null}+ {/* A side we could not measure says so. Zhorts (GH #123) read "62 GB GPU"+ off this chip on a 16 GB card, because the number behind it was his+ system RAM; the source of that is fixed in api/comfyui.ts, and this is+ the other half. Leaving the half out entirely reads as "no GPU", and+ an unmeasured GPU is not the same thing as an absent one. */}+ {vramGb+ ? <span className="tabular-nums">{Math.round(vramGb)} GB GPU</span>+ : <span>GPU unknown</span>}+ <span className="opacity-40">·</span>+ {ramGb+ ? <span className="tabular-nums">{Math.round(ramGb)} GB RAM</span>+ : <span>RAM unknown</span>}</span>)}diff --git a/src/lib/hardware.ts b/src/lib/hardware.tsindex 3fec9317..ba0e522c 100644--- a/src/lib/hardware.ts+++ b/src/lib/hardware.ts@@ -19,6 +19,8 @@ interface DetectedGpu {name: string;memory_mib: number | null;source: string;+ /** `gcnArchName` from the HIP SDK ("gfx1201"), when a tool named it. */+ arch?: string | null;}/**@@ -92,3 +94,31 @@ export function bundleVramNeedGb(bundle: { vramRequired?: string; totalSizeGB?:if (single) return parseInt(single[1])return bundle.totalSizeGB ?? 0}++// ─── AMD compute architecture ───────────────────────────────────────++let cachedAmdArch: string | null | undefined = undefined;++/**+ * The gfx target of the first AMD card, as the HIP SDK's own `hipinfo` named+ * it, or null when no tool named one.+ *+ * Read, never derived: the mapping from a marketing name ("RX 9070 XT") to a+ * gfx target is AMD's to publish, and a table of it in here would be wrong the+ * day a new card ships. Used to make the hipErrorInvalidValue message name the+ * architecture the user has to match (A12, artoriuskurokami, RDNA4).+ *+ * Cached because it cannot change while the app runs, and fail-soft because a+ * message that says a little less is better than an error path that throws.+ */+export async function getAmdGpuArch(): Promise<string | null> {+ if (cachedAmdArch !== undefined) return cachedAmdArch;+ try {+ const gpus = await backendCall<DetectedGpu[]>("detect_gpus");+ const amd = (Array.isArray(gpus) ? gpus : []).find((g) => g.vendor === "amd" && !!g.arch);+ cachedAmdArch = amd?.arch ?? null;+ } catch {+ cachedAmdArch = null;+ }+ return cachedAmdArch;+}