The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Readiness: a person's own GPU runs a workflow with its streaming need
Adarshf3b85ff7a234
diff --git a/src/lib/gpu/readiness.ts b/src/lib/gpu/readiness.tsindex a65db1ce..cca528ba 100644--- a/src/lib/gpu/readiness.ts+++ b/src/lib/gpu/readiness.ts@@ -2,7 +2,8 @@ import { compareVersions, formatBytes, nameKey, splitKey, vramGb } from "./requiimport { knownProblemNeed, knownProblems } from "./known-problems";import { fileChoices, pickFiles, type FileChoice } from "./model-variants";import { cardFits, GPU_NEED_TEXT, readCard, type GpuNeed } from "./rtx";-import type { Badge, FileKey, GpuInventory, IndexFile, InventorySummary, Need, Readiness, RequirementIndex, ToolReadiness, ToolRef, VramFit } from "./types";+import { streamFits } from "../lanes";+import type { Badge, FileKey, GpuInventory, IndexFile, InventorySummary, Need, Readiness, RequirementIndex, StreamNeed, ToolReadiness, ToolRef, VramFit } from "./types";/*** What can run on a viewer's ComfyUI (SPEC §7, review items 9 and 15). Pure: the same code runs on the@@ -167,7 +168,12 @@ export function gpuVramGb(inv: GpuInventory): number | undefined {return onCpu(inv) ? undefined : vramGb(inv.devices[0]?.vramTotal);}-export function vramFit(needGb: number, inv: GpuInventory): ToolReadiness["vram"] {+/**+ * How the card holds a workflow of `needGb`. Short of VRAM, a workflow with a streaming need (`stream`,+ * stream-needs.json) still runs when the card and the system RAM cover that need (src/lib/lanes.ts streamFits, the+ * workers' rule): part of its weights stay in RAM, so it is "tight" (slower) with `stream`, never "no".+ */+export function vramFit(needGb: number, inv: GpuInventory, stream?: StreamNeed): ToolReadiness["vram"] {const d = inv.devices[0];const cpu = onCpu(inv);const haveGb = gpuVramGb(inv) ?? 0;@@ -177,9 +183,13 @@ export function vramFit(needGb: number, inv: GpuInventory): ToolReadiness["vram"else if (haveGb >= needGb) fit = "fits";else if (haveGb >= 0.66 * needGb) fit = "tight";else fit = "no";- return { needGb, haveGb, fit, ...(apple && { apple: true }) };+ const streams = (fit === "tight" || fit === "no") && !cpu && streamFits(stream, { vramBytes: d?.vramTotal, ramBytes: inv.ram?.total, dynamicVramOff: inv.comfy?.flags.dynamicVramOff });+ if (streams) fit = "tight";+ return { needGb, haveGb, fit, ...(apple && { apple: true }), ...(streams && { stream: true }) };}+const FIT_RANK: Record<VramFit, number> = { any: 0, fits: 1, tight: 2, no: 3 };+function fileNeed(key: FileKey, f: IndexFile, kind: "model" | "model-replace", ctx: ReadinessContext): Need {return {key: `file:${key}`,@@ -214,7 +224,7 @@ export function workflowReadiness(id: string, inv: GpuInventory, idx: Requiremenif (!w || !inv.reachable) return base;// Its own files, or a model variant's that are all there.const files = filesHere(id, inv, idx) ?? { files: w.files, vramGb: w.vramGb };- const out: WorkflowReadiness = { ...base, state: "ready", firstRun: w.firstRun, unvalidated: !w.validated, vram: vramFit(files.vramGb, inv) };+ const out: WorkflowReadiness = { ...base, state: "ready", firstRun: w.firstRun, unvalidated: !w.validated, vram: vramFit(files.vramGb, inv, w.stream) };if (w.isolated && ctx.computer) return { ...out, state: "unsupported", reason: "This one needs its own ComfyUI, so it can't run next to your other add-ons." };if (w.isolated && ctx.account) return { ...out, state: "unsupported", reason: "This one needs its own ComfyUI, so it can't run next to your other add-ons." };// The NVIDIA RTX Video nodes: only on an NVIDIA RTX card (frame generation: RTX 40 or later). A card the check can't@@ -357,7 +367,10 @@ export function toolReadiness(out.needs = [...needs.values()];out.have = [...have.values()];out.downloadBytes = out.needs.filter((n) => n.kind === "model" || n.kind === "model-replace" || n.kind === "lora").reduce((a, n) => a + (n.sizeBytes ?? 0), 0);- out.vram = vramFit(needGb, inv);+ // The hardest part's fit, at the most VRAM any part needs; slower with RAM streaming when each part short of VRAM streams.+ const worst = parts.reduce((a, p) => (FIT_RANK[p.vram.fit] > FIT_RANK[a.fit] ? p.vram : a), parts[0].vram);+ const streams = worst.fit === "tight" && parts.every((p) => FIT_RANK[p.vram.fit] < FIT_RANK.tight || p.vram.stream);+ out.vram = { needGb, haveGb: worst.haveGb, fit: worst.fit, ...(worst.apple && { apple: true }), ...(streams && { stream: true }) };// A graph that needs an NVIDIA RTX card (no VRAM figure published) never reads "Runs on any computer".if (out.vram.fit === "any" && workflowIds.some((id) => idx.workflows[id]?.gpu)) out.vram = { ...out.vram, fit: "fits" };out.state = stateOf(out.needs, out.vram.fit);@@ -399,7 +412,7 @@ export function summaryOf(inv: GpuInventory, idx: RequirementIndex): InventorySu/** The line under a chip or a board row: "1 download · 12.3 GB", "Needs 24 GB", "Ready". */export function stateLine(t: Pick<ToolReadiness, "state" | "needs" | "downloadBytes" | "vram" | "gpuNeed">): string {- if (t.state === "ready") return t.vram.fit === "any" ? "Runs on any computer" : t.vram.fit === "tight" ? "Ready · slow on your GPU" : "Ready";+ if (t.state === "ready") return t.vram.fit === "any" ? "Runs on any computer" : t.vram.fit === "tight" ? (t.vram.stream ? "Ready · uses system RAM, slower" : "Ready · slow on your GPU") : "Ready";if (t.state === "gpu") return `Needs ${t.vram.needGb} GB`;if (t.state === "unsupported") return t.gpuNeed ? GPU_NEED_TEXT[t.gpuNeed] : "Needs a second ComfyUI";if (t.state === "unknown") return "Not checked";diff --git a/src/lib/gpu/types.ts b/src/lib/gpu/types.tsindex 81f667d1..7d0f3c13 100644--- a/src/lib/gpu/types.ts+++ b/src/lib/gpu/types.ts@@ -266,7 +266,8 @@ export interface ToolReadiness {needs: Need[];have: Need[];downloadBytes: number;- vram: { needGb: number; haveGb?: number; fit: VramFit; apple?: boolean };+ /** `stream`: short of VRAM, it runs with part of its weights streamed from system RAM (slower; fit "tight"). */+ vram: { needGb: number; haveGb?: number; fit: VramFit; apple?: boolean; stream?: true };firstRun: string[];unvalidated: boolean;/** Files Fuobe can't see on this ComfyUI (they never block). */diff --git a/tests/stream-needs.test.ts b/tests/stream-needs.test.tsindex d7c54001..e2287406 100644--- a/tests/stream-needs.test.ts+++ b/tests/stream-needs.test.ts@@ -2,8 +2,11 @@ import fs from "node:fs";import path from "node:path";import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";import { buildIndex, loadInputs } from "../scripts/comfy/build-requirements.mjs";+import { parseArgv } from "@/lib/gpu/argv";+import { emptyInventory } from "@/lib/gpu/gather";+import { stateLine, toolReadiness, vramFit, workflowReadiness } from "@/lib/gpu/readiness";import { parseIndex } from "@/lib/gpu/requirements";-import type { RequirementIndex } from "@/lib/gpu/types";+import type { GpuInventory, RequirementIndex } from "@/lib/gpu/types";import { memoryFit, minVramBytesFor, streamFits } from "@/lib/lanes";import { statsFacts } from "@/lib/local-comfy";import { tempDir } from "./helpers/temp-dir";@@ -12,7 +15,7 @@ import { tempDir } from "./helpers/temp-dir";* Streaming needs (workflows/comfyui/stream-needs.json): a workflow a card can't hold whole still runs on it with part of* its weights kept in system RAM and streamed to the card each step (ComfyUI's dynamic VRAM loading). The build checks* the file; a worker qualifies on memory with the workflow's VRAM, or with the streaming need's VRAM and RAM (3%- * allowance on both, never with unknown RAM or dynamic VRAM off).+ * allowance on both, never with unknown RAM or dynamic VRAM off); a person's own GPU reads the same rule.*/vi.setConfig({ testTimeout: 60_000 });@@ -104,6 +107,56 @@ describe("the memory rule (memoryFit, streamFits)", () => {});});+/** A person's ComfyUI with every file and node of the index, this card's VRAM and this RAM (none: not read). */+function comfy(vramGb: number, ramGb?: number, argv: string[] = ["main.py"]): GpuInventory {+ const inv = emptyInventory("server", 1);+ inv.reachable = true;+ inv.comfy = { version: "0.44.0", os: "posix", embeddedPython: false, deployEnv: "local-git", flags: parseArgv(argv) };+ inv.devices = [{ name: "cuda:0 NVIDIA GeForce RTX 3080 : cudaMallocAsync", type: "cuda", index: 0, vramTotal: vramGb * GB, vramFree: 0 }];+ if (ramGb) inv.ram = { total: ramGb * GB, free: 0 };+ inv.manager = { api: "none" };+ inv.nodes = { have: [], missing: [], total: 0, readAt: 1, how: "object_info" };+ for (const folder of idx.folders) inv.models[folder] = { have: {}, total: 0 };+ for (const f of Object.values(idx.files)) {+ inv.models[f.folder] ??= { have: {}, total: 0 };+ inv.models[f.folder].have[f.file] = f.sizeBytes;+ for (const [cls, input] of f.loaders ?? []) (inv.combos[`${cls}.${input}`] ??= []).push(f.file);+ }+ return inv;+}++describe("a person's own GPU (readiness)", () => {+ it("a smaller card with the RAM is ready, slower, in plain words", () => {+ const r = workflowReadiness(H3, comfy(10, 31.9), idx, { account: true });+ expect(r.state).toBe("ready");+ expect(r.vram).toMatchObject({ needGb: 32, fit: "tight", stream: true });+ const t = toolReadiness(`workflow:${H3}`, "H3 Image", [H3], [], comfy(10, 32), idx, { account: true });+ expect(t.state).toBe("ready");+ expect(t.vram.stream).toBe(true);+ expect(stateLine(t)).toBe("Ready · uses system RAM, slower");+ });++ it("too little RAM, RAM not read, or dynamic VRAM off: it needs the bigger card, as before", () => {+ expect(workflowReadiness(H3, comfy(10, 16), idx, { account: true }).state).toBe("gpu");+ expect(workflowReadiness(H3, comfy(10), idx, { account: true }).state).toBe("gpu");+ expect(workflowReadiness(H3, comfy(10, 64, ["main.py", "--disable-dynamic-vram"]), idx, { account: true }).state).toBe("gpu");+ expect(workflowReadiness(H3, comfy(8, 64), idx, { account: true }).state).toBe("gpu");+ });++ it("a card that holds it whole says nothing of RAM; a workflow with no streaming need is as before", () => {+ expect(vramFit(32, comfy(32, 64), { vramGb: 10, ramGb: 32 })).toEqual({ needGb: 32, haveGb: 32, fit: "fits" });+ expect(vramFit(32, comfy(10, 64))).toEqual({ needGb: 32, haveGb: 10, fit: "no" });+ expect(stateLine(toolReadiness(`workflow:${H3}`, "H3 Image", [H3], [], comfy(24, 16), idx, { account: true }))).toBe("Ready · slow on your GPU");+ });++ it("a tool whose other part can't stream needs the bigger card", () => {+ const noStream = Object.keys(idx.workflows).find((id) => !idx.workflows[id].stream && idx.workflows[id].vramGb >= 24 && !idx.workflows[id].isolated && !idx.workflows[id].gpu)!;+ const t = toolReadiness(`workflow:${H3}`, "Two", [H3, noStream], [], comfy(10, 64), idx, { account: true });+ expect(t.state).toBe("gpu");+ expect(t.vram.stream).toBeUndefined();+ });+});+const { db } = await import("@/server/db");const { resetRates } = await import("@/server/rate");const { setSetting } = await import("@/server/settings");