Skip to content

armgit / fuobe

Public Imported from GitHub
0

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.

Workers: a card takes the lanes made for its size

Adarsha94fdb8f45d9
diff --git a/docs/gpu-workers.md b/docs/gpu-workers.md
index ea8802ef..4832da14 100644
--- a/docs/gpu-workers.md
+++ b/docs/gpu-workers.md
@@ -118,7 +118,8 @@ A worker gets a job only when all of these are true, all in one SQLite transacti
- it is paused in neither place, it is not draining, it is inside its hours, and the studio heard from it in the last
30 seconds;
- the job is in its pool, in a lane that the owner allows for it, after the lane's delay and `claim_after_ms`;
-- it has the workflow's files and packs (from its inventory) and enough VRAM;
+- it has the workflow's files and packs (from its inventory) and enough VRAM. A workflow's need is its whole GB less
+ 3%, because a card reports a little less than its size (a 32 GB card shows about 31.8 GiB);
- the retry rule allows it: a worker that lost or failed the job gets it again only when no other worker that can run
the job was heard from in the last 10 minutes;
- near the end of its hours, the job's estimate fits before the window closes.
diff --git a/src/lib/lanes.ts b/src/lib/lanes.ts
index 228ff3e7..7a9cfa82 100644
--- a/src/lib/lanes.ts
+++ b/src/lib/lanes.ts
@@ -23,9 +23,20 @@ export interface Needs {
workflowId: string;
files: FileNeed[];
packs: string[];
+ /** The graphics memory a worker must report, with VRAM_TOLERANCE already allowed for. */
minVramBytes: number;
}
+/**
+ * A card sold as a whole number of GB reports a little less than that (a 32 GB card about 31.8 GiB, a 10 GB card a
+ * few MB under 10 GiB). A workflow's VRAM need allows this much under its whole GB, so such a card takes the lanes made
+ * for its size.
+ */
+export const VRAM_TOLERANCE = 0.03;
+
+/** The graphics memory a workflow of `gb` whole GB needs from a worker, in bytes (3% under the whole GB). */
+export const minVramBytesFor = (gb: number) => Math.round((gb || 0) * 2 ** 30 * (1 - VRAM_TOLERANCE));
+
type Sha = (text: string) => string;
const bigFiles = (index: RequirementIndex, wf: IndexWorkflow) =>
@@ -64,7 +75,7 @@ export function allLanes(index: RequirementIndex, sha: Sha): { lane: string; lab
return [...by].map(([lane, workflows]) => ({ lane, label: laneLabel(index, lane, sha), workflows })).sort((a, b) => a.label.localeCompare(b.label));
}
-/** What a workflow's task needs: its default files (folder, name, exact size, sha256 when pinned), packs and VRAM. */
+/** What a workflow's task needs: its default files (folder, name, exact size, sha256 when pinned), packs and VRAM (with the tolerance). */
export function needsOf(index: RequirementIndex, workflowId: string): Needs | null {
const wf = index.workflows[workflowId];
if (!wf) return null;
@@ -72,7 +83,7 @@ export function needsOf(index: RequirementIndex, workflowId: string): Needs | nu
.map((k) => index.files[k])
.filter(Boolean)
.map((f) => ({ folder: f.folder, name: f.file, size: f.sizeBytes, sha256: f.sha256 ?? null }));
- return { workflowId, files, packs: Object.keys(wf.packs).sort(), minVramBytes: Math.round((wf.vramGb || 0) * 2 ** 30) };
+ return { workflowId, files, packs: Object.keys(wf.packs).sort(), minVramBytes: minVramBytesFor(wf.vramGb) };
}
/** A worker's verified files and node packs (PUT /api/gpu/computer/inventory). */
diff --git a/tests/worker-environment.test.ts b/tests/worker-environment.test.ts
new file mode 100644
index 00000000..ed986da5
--- /dev/null
+++ b/tests/worker-environment.test.ts
@@ -0,0 +1,26 @@
+import { describe, expect, it } from "vitest";
+import { minVramBytesFor, needsOf, VRAM_TOLERANCE } from "@/lib/lanes";
+import type { RequirementIndex } from "@/lib/gpu/types";
+
+describe("VRAM: a card takes the lanes made for its size", () => {
+ const index = {
+ files: {},
+ packs: {},
+ workflows: { big: { core: [], packs: {}, files: [], optional: [], vramGb: 32, isolated: false, firstRun: [] }, mid: { core: [], packs: {}, files: [], optional: [], vramGb: 24, isolated: false, firstRun: [] } },
+ } as unknown as RequirementIndex;
+ const MiB = 2 ** 20;
+
+ it("allows 3% under the whole GB", () => {
+ expect(VRAM_TOLERANCE).toBe(0.03);
+ expect(minVramBytesFor(32)).toBe(Math.round(32 * 2 ** 30 * 0.97));
+ expect(minVramBytesFor(0)).toBe(0);
+ const big = needsOf(index, "big")!.minVramBytes;
+ // A 32 GB card reports about 31.8 GiB: it takes the 32 GB lanes. A 30 GiB card doesn't.
+ expect(big <= 32_607 * MiB).toBe(true);
+ expect(big <= 30 * 2 ** 30).toBe(false);
+ // A 24 GB card that reports a few MB under 24 GiB takes the 24 GB lanes; a 22 GiB card doesn't.
+ const mid = needsOf(index, "mid")!.minVramBytes;
+ expect(mid <= 24_564 * MiB).toBe(true);
+ expect(mid <= 22 * 2 ** 30).toBe(false);
+ });
+});