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 dynamic VRAM fault is freed and tried once more, like running out of memory

Adarshb4ad3289eda3
diff --git a/docs/gpu-workers.md b/docs/gpu-workers.md
index eb15bbe4..99def719 100644
--- a/docs/gpu-workers.md
+++ b/docs/gpu-workers.md
@@ -777,8 +777,9 @@ Every other workflow streams by the computed rule.
VRAM need counts as the VRAM need, and its own files count for the computed rule.
- **When a streamed job runs out of memory.** The claim notes on the task that the worker took it by streaming. If that
job then fails because it ran out of memory, the worker no longer takes that workflow by streaming. Out of memory
- means CUDA out of memory, "Allocation on device", "The paging file is too small", Python's `MemoryError` or "not
- enough memory", in the failed entry's execution error or the worker's reason. The workflow goes on the worker's list
+ means CUDA out of memory, "Allocation on device", "The paging file is too small", Python's `MemoryError`, "not
+ enough memory" or dynamic VRAM's "Fault failed: <code>" (its weights could not be placed on the card), in the failed
+ entry's execution error or the worker's reason (one list, `OUT_OF_MEMORY` in `src/lib/comfy-reason.ts`). The workflow goes on the worker's list
(`no_stream_json` on the worker, with the time; `noStream` in `GET /api/admin/workers`). If another worker can run
the job, it goes back in line with its place kept, as a try that costs the run nothing. Its error doesn't show. With
no other worker for it, or for a job taken with every weight on the card, or for any other error, the job fails as
@@ -1103,7 +1104,8 @@ The worker keeps its jobs going by itself:
- **A job that the studio took back** (its token for the job no longer works, for example after the worker was out of
touch) is stopped in its ComfyUI at once, so it never keeps the GPU busy for nothing.
- **Out of memory.** The worker frees its ComfyUI's memory (`/free`) and sends the job once more. Only a second time
- fails the job. The execution time that it reports is the retry's only.
+ fails the job. This covers dynamic VRAM's "Fault failed" too: a model loaded straight after another one may find no
+ room for its weights until the first one is let go. The execution time that it reports is the retry's only.
- **Inputs are read once.** The worker keeps a copy of each input (by its SHA-256) while its job runs, so a job that
is sent again reads nothing from the studio twice. If the studio will not send an input again (429 with no
`Retry-After`), the job fails at once instead of looping. The copies go when the job ends, and also when a claim
diff --git a/src/lib/comfy-reason.ts b/src/lib/comfy-reason.ts
index b5e56069..63c18d91 100644
--- a/src/lib/comfy-reason.ts
+++ b/src/lib/comfy-reason.ts
@@ -187,7 +187,13 @@ function lastFrames(tb: unknown, n = 2): string[] {
return all.slice(-n);
}
-const OUT_OF_MEMORY = /out of memory|OutOfMemoryError|Allocation on device|not enough memory|MemoryError/i;
+/**
+ * ComfyUI's words for running out of memory, on the card or in RAM: CUDA, HIP or MPS out of memory, torch's
+ * OutOfMemoryError, "Allocation on device", Python's MemoryError, "not enough memory", Windows' "The paging file is too
+ * small", and dynamic VRAM's "Fault failed: <code>" (comfy_aimdo could not place a model's weights on the card). Every
+ * out-of-memory check reads this one list.
+ */
+export const OUT_OF_MEMORY = /out of memory|OutOfMemoryError|allocation on device|not enough memory|paging file is too small|MemoryError|\bFault failed: -?\d+|VRAM Allocation failed/i;
/**
* Why a job stopped while ComfyUI ran it: its execution error (the data of a history entry's "execution_error" message,
diff --git a/src/lib/computer-runner.ts b/src/lib/computer-runner.ts
index 7fa41135..94c54096 100644
--- a/src/lib/computer-runner.ts
+++ b/src/lib/computer-runner.ts
@@ -8,7 +8,7 @@
* a socket and a clock, and the tests drive it from Node against a stand-in ComfyUI.
*/
import { isGuard } from "./comfy-guard";
-import { entryReason, refusalReason } from "./comfy-reason";
+import { entryReason, OUT_OF_MEMORY, refusalReason } from "./comfy-reason";
import { withoutLocalPaths } from "./engine-error";
import { FINISH_RUN_MS, finishProblem, type FinishResult, type FinishStats } from "./finish-ticket";
import { fetchWithin } from "./fetch-within";
@@ -215,9 +215,6 @@ export interface WorkerHooks {
gpuBusy?(): number | null;
}
-/** ComfyUI's words for running out of memory (lib/gpu/fix-codes.ts says the same). */
-const OUT_OF_MEMORY = /out of memory|OutOfMemoryError|allocation on device/i;
-
/** The prompt ran out of memory (its entry's execution error says so). */
export function outOfMemory(e: HistoryEntryLike): boolean {
if (e.status?.status_str !== "error") return false;
diff --git a/src/lib/diagnose.ts b/src/lib/diagnose.ts
index 0ff1774d..1add6ef5 100644
--- a/src/lib/diagnose.ts
+++ b/src/lib/diagnose.ts
@@ -6,6 +6,7 @@
*
* Only an account's own GPU and keys are read this way. The owner's runs and runs on the studio's GPUs keep their words.
*/
+import { OUT_OF_MEMORY } from "./comfy-reason";
import { knownProblemOf } from "./gpu/known-problems";
import { balanceMessage, CLOUD_KEY, keyRejectedMessage, type CloudProvider } from "./your-keys";
@@ -559,8 +560,7 @@ export function checksTooFast(retryAfterS: number): Diagnosis {
/** The out-of-memory words of a run on the person's own GPU (the computer path says the same). */
export const OUT_OF_MEMORY_WORDS = "Your GPU ran out of memory. Try a smaller size or a shorter clip.";
-const OOM = /out of memory|CUDA error: out of memory|OutOfMemoryError|allocation on device|Allocation on device|MPS backend out of memory|HIP out of memory/i;
-export const isOutOfMemoryText = (s: string) => OOM.test(s);
+export const isOutOfMemoryText = (s: string) => OUT_OF_MEMORY.test(s);
const minutes = (n: number) => `${n} minute${n === 1 ? "" : "s"}`;
diff --git a/src/lib/gpu/fix-codes.ts b/src/lib/gpu/fix-codes.ts
index a24acf1a..f659681f 100644
--- a/src/lib/gpu/fix-codes.ts
+++ b/src/lib/gpu/fix-codes.ts
@@ -1,4 +1,5 @@
import type { GenerationFix } from "@/lib/catalog/types";
+import { OUT_OF_MEMORY } from "@/lib/comfy-reason";
/**
* What a ComfyUI refusal says was missing (SPEC §13.2): a model file a loader didn't list ("not in list"), or a node
@@ -43,4 +44,4 @@ export function fixFromPromptError(
}
/** An out-of-memory error in a run's execution_error. */
-export const isOutOfMemory = (text: string | undefined): boolean => !!text && /out of memory|OutOfMemoryError|CUDA error: out of memory|allocation on device/i.test(text);
+export const isOutOfMemory = (text: string | undefined): boolean => !!text && OUT_OF_MEMORY.test(text);
diff --git a/src/server/computer/tasks.ts b/src/server/computer/tasks.ts
index c3a12a03..b79d3389 100644
--- a/src/server/computer/tasks.ts
+++ b/src/server/computer/tasks.ts
@@ -27,7 +27,7 @@ import {
cleanNodeClass,
cleanNodeTitle,
} from "@/lib/relay";
-import { reasonText } from "@/lib/comfy-reason";
+import { OUT_OF_MEMORY, reasonText } from "@/lib/comfy-reason";
import { cleanPriority } from "@/lib/run-priority";
import { cleanNodeTimes } from "@/lib/node-times";
import { trackReport, type LiveProgress } from "@/lib/run-progress";
@@ -1387,13 +1387,6 @@ export const setPoolLost = (fn: (t: TaskRow) => void) => (poolLost = fn);
let poolOutOfMemory: ((t: TaskRow, now: number) => boolean) | null = null;
export const setPoolOutOfMemory = (fn: (t: TaskRow, now: number) => boolean) => (poolOutOfMemory = fn);
-/**
- * The words for running out of memory: on the card (CUDA out of memory, torch's OutOfMemoryError, "Allocation on
- * device"), in system RAM (Python's MemoryError, "not enough memory") or in Windows' page file ("The paging file is too
- * small for this operation to complete").
- */
-const OUT_OF_MEMORY = /out of memory|OutOfMemoryError|allocation on device|not enough memory|paging file is too small|MemoryError/i;
-
/**
* Did a finished job end by running out of memory: one of its entries failed with an execution error in those words, or
* the worker's reason for its failure (`why`) says so.
diff --git a/tests/comfy-reason.test.ts b/tests/comfy-reason.test.ts
index 79e267ff..30d061b7 100644
--- a/tests/comfy-reason.test.ts
+++ b/tests/comfy-reason.test.ts
@@ -99,6 +99,8 @@ describe("execution errors (/history or the websocket)", () => {
it("running out of memory: the node, in a few words", () => {
const data = { node_id: "7", node_type: "KSampler", exception_type: "torch.OutOfMemoryError", exception_message: "CUDA out of memory. Tried to allocate 2.00 GiB. GPU 0 has a total capacity of 31.84 GiB", traceback };
expect(executionReason(data)).toBe("CUDA out of memory in KSampler (node 7)");
+ // Dynamic VRAM could not place a model's weights on the card.
+ expect(executionReason({ node_id: "32", node_type: "KSampler", exception_type: "RuntimeError", exception_message: "Fault failed: 2", traceback })).toBe("Out of memory in KSampler (node 32)");
});
it("another exception: its type, its first line, and the last frames by file name only", () => {
diff --git a/tests/helpers/fake-local-comfy.ts b/tests/helpers/fake-local-comfy.ts
index c239061f..51a5f201 100644
--- a/tests/helpers/fake-local-comfy.ts
+++ b/tests/helpers/fake-local-comfy.ts
@@ -35,7 +35,7 @@ export interface LocalComfyOptions {
stepMs?: number;
steps?: number;
/** What the next prompt does. */
- failNext?: "oom" | "missing_node" | "missing_model" | "gone" | "never";
+ failNext?: "oom" | "vram-fault" | "missing_node" | "missing_model" | "gone" | "never";
/** Lose this many prompts in a row (taken, then gone: a restart while it waited). */
loseNext?: number;
/** What a job saves (default: what its save node makes: a clip, a sound, else a picture). "fake-png" is a web page named .png. */
@@ -414,8 +414,12 @@ export function startLocalComfy(given: LocalComfyOptions, port = 0): Promise<Loc
timer = setTimeout(next, stepMs);
return;
}
- if (job.fail === "oom") {
- const err = { prompt_id: job.id, node_id: node, node_type: "KSampler", exception_message: "Allocation on device 0 would exceed allowed memory. (out of memory)", exception_type: "torch.OutOfMemoryError" };
+ if (job.fail === "oom" || job.fail === "vram-fault") {
+ // "vram-fault": dynamic VRAM (comfy_aimdo) could not place a model's weights on the card.
+ const err =
+ job.fail === "oom"
+ ? { prompt_id: job.id, node_id: node, node_type: "KSampler", exception_message: "Allocation on device 0 would exceed allowed memory. (out of memory)", exception_type: "torch.OutOfMemoryError" }
+ : { prompt_id: job.id, node_id: node, node_type: "KSampler", exception_message: "Fault failed: 2", exception_type: "RuntimeError", traceback: [' File "comfy_aimdo/model_vbar.py", line 161, in vbar_fault\n', ' File "comfy_aimdo/model_vbar.py", line 109, in fault\n'] };
event(job.clientId, "execution_error", err);
return finish(job, { prompt: [job.number, job.id, job.graph, {}, []], outputs: {}, status: { status_str: "error", completed: false, messages: [begin, ["execution_error", { ...err, timestamp: Date.now() }]] } });
}
diff --git a/tests/stream-oom-fallback.test.ts b/tests/stream-oom-fallback.test.ts
index cc9073d8..6b957277 100644
--- a/tests/stream-oom-fallback.test.ts
+++ b/tests/stream-oom-fallback.test.ts
@@ -105,6 +105,8 @@ describe("the words for running out of memory (ranOutOfMemory)", () => {
expect(tasks.ranOutOfMemory([failed("OSError", "The paging file is too small for this operation to complete. (os error 1455)")])).toBe(true);
expect(tasks.ranOutOfMemory([failed("MemoryError", "")])).toBe(true);
expect(tasks.ranOutOfMemory([failed("RuntimeError", "Not enough memory resources are available to process this command.")])).toBe(true);
+ expect(tasks.ranOutOfMemory([failed("RuntimeError", "Fault failed: 2")])).toBe(true);
+ expect(tasks.ranOutOfMemory([failed("RuntimeError", "Fault failed to load")])).toBe(false);
expect(tasks.ranOutOfMemory([failed("ValueError", "bad input")])).toBe(false);
// The reason the worker gave, for an entry whose messages it didn't keep.
expect(tasks.ranOutOfMemory([{ status: { status_str: "error" } }], "CUDA out of memory in KSampler (node 12)")).toBe(true);
diff --git a/tests/worker-runner.test.ts b/tests/worker-runner.test.ts
index 01fd91a7..3dc501ac 100644
--- a/tests/worker-runner.test.ts
+++ b/tests/worker-runner.test.ts
@@ -234,6 +234,20 @@ describe("a worker's runner", () => {
expect(state(id2).state).toBe("failed");
});
+ it("dynamic VRAM could not place a model's weights (Fault failed): freed and sent once more, like running out of memory", async () => {
+ const w = worker();
+ const id = task();
+ const s = studio(w);
+ let freed = 0;
+ const before = fake.posts();
+ fake.opts.failNext = "vram-fault";
+ await runner(s, hooks({ free: async () => void freed++ })).claimAndRun();
+ expect(state(id).state).toBe("done");
+ expect(fake.posts() - before).toBe(2);
+ expect(freed).toBe(1);
+ expect(s.reports.some((x) => x.event === "failed")).toBe(false);
+ });
+
it("out of memory, then its retry doesn't move: given back as out of memory within minutes, never offered to this worker again", async () => {
const w = worker();
const id = task();