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: keep the whole file sets with a worker's lanes

Adarsh3d06fa8766a6
diff --git a/src/lib/lanes.ts b/src/lib/lanes.ts
index 2894a52d..598b1ee6 100644
--- a/src/lib/lanes.ts
+++ b/src/lib/lanes.ts
@@ -174,16 +174,19 @@ export const hasFiles = (inv: Inventory, needs: readonly FileNeed[] | undefined)
/**
* What a worker can run with what it has: the workflows whose files (its own, or one of its variants') and packs are all
* there (and whose packs' node classes its ComfyUI loaded, where it said), the lanes whose every workflow runs, and, for the other lanes, what it lacks. A task goes only to a worker that can run its workflow.
+ * `sets`: for each of those workflows that has model variants, the file sets it has whole (null: the workflow's own, else
+ * a variant's id).
*/
export function lanesFor(
index: RequirementIndex,
inv: Inventory,
sha: Sha,
-): { lanes: string[]; workflows: string[]; missing: { lane: string; label: string; files: string[]; bytes: number }[] } {
+): { lanes: string[]; workflows: string[]; missing: { lane: string; label: string; files: string[]; bytes: number }[]; sets: Record<string, (string | null)[]> } {
const packs = new Map(inv.nodePacks.map((p) => [p.name, p]));
const takes = new Set<string>(inv.media ?? ["image"]);
const ok = new Map<string, boolean>();
const workflows: string[] = [];
+ const sets: Record<string, (string | null)[]> = {};
const lacking = new Map<string, Map<string, number>>();
for (const id of Object.keys(index.workflows)) {
if (index.workflows[id].isolated) continue;
@@ -191,12 +194,15 @@ export function lanesFor(
const n = needsOf(index, id)!;
// Its own files, or every file of one of its variants: a worker that has either may run it.
let missingFiles = n.files.filter((f) => !hasFile(inv, f));
- if (missingFiles.length && variantNeeds(index, id).some((v) => hasFiles(inv, v.files))) missingFiles = [];
+ const variants = variantNeeds(index, id);
+ const whole = [...(missingFiles.length ? [] : [null]), ...variants.filter((v) => hasFiles(inv, v.files)).map((v) => v.id)];
+ if (whole.length) missingFiles = [];
const missingPacks = n.packs.filter((p) => !packs.has(p));
const missingMedia = mediaOf(index.workflows[id]).filter((k) => !takes.has(k));
const notLoaded = unloadedNodes(index.workflows[id], packs);
const fine = !missingFiles.length && !missingPacks.length && !missingMedia.length && !notLoaded.length;
if (fine) workflows.push(id);
+ if (fine && variants.length) sets[id] = whole;
ok.set(lane, (ok.get(lane) ?? true) && fine);
if (!fine) {
const m = lacking.get(lane) ?? new Map<string, number>();
@@ -209,7 +215,7 @@ export function lanesFor(
}
const lanes = [...ok].filter(([, v]) => v).map(([k]) => k).sort();
const missing = [...lacking].map(([lane, m]) => ({ lane, label: laneLabel(index, lane, sha), files: [...m.keys()].sort(), bytes: [...m.values()].reduce((a, b) => a + b, 0) }));
- return { lanes, workflows: workflows.sort(), missing };
+ return { lanes, workflows: workflows.sort(), missing, sets };
}
/**
diff --git a/src/server/computer/pool.ts b/src/server/computer/pool.ts
index 457b2a98..2e4da5f7 100644
--- a/src/server/computer/pool.ts
+++ b/src/server/computer/pool.ts
@@ -3,7 +3,7 @@ import { ENGINE_WORDS } from "@/lib/engine-error";
import crypto from "node:crypto";
import { FINISH_KINDS, type FinishTicket } from "@/lib/finish-ticket";
import { ceilingProblem, cleanCeiling, insideCeiling, lanesInside, type Ceiling } from "@/lib/job-ticket";
-import { allLanes, hasFile, hasFiles, laneLabel, lanesFor, MEDIA_KINDS, minVramBytesFor, needsOf, packKey, partLanes, unloadedNodes, type FileNeed, type Inventory, type NodePack, type Needs } from "@/lib/lanes";
+import { allLanes, hasFiles, laneLabel, lanesFor, MEDIA_KINDS, minVramBytesFor, needsOf, packKey, partLanes, unloadedNodes, type FileNeed, type Inventory, type NodePack, type Needs } from "@/lib/lanes";
import { fileChoices, hasVariants, pickFiles, swapGraphFiles, type FileChoice } from "@/lib/gpu/model-variants";
import type { FileKey } from "@/lib/gpu/types";
import { POOL_WORDS, RELAY_TIMES, SENT_STATES, type BeatAnswer, type ClaimedTask, type ComputerFacts, type CpuSlot, type WorkerAnswer, type WorkerBeat, type WorkerHolding } from "@/lib/relay";
@@ -175,7 +175,8 @@ interface Allow {
const allowOf = (w: WorkerRow) => json<Record<string, Allow>>(w.allow_json, {});
/** The lanes and workflows its files let it run, and the requirements index they were worked out with (none: an older row). */
-const capableOf = (w: WorkerRow) => json<{ lanes: string[]; workflows: string[]; index?: string }>(w.lanes_json, { lanes: [], workflows: [] });
+/** `sets`: the file sets it has whole of each workflow with model variants (lanesFor). Lanes worked out without it: its own files only. */
+const capableOf = (w: Pick<WorkerRow, "lanes_json">) => json<{ lanes: string[]; workflows: string[]; index?: string; sets?: Record<string, (string | null)[]> }>(w.lanes_json, { lanes: [], workflows: [] });
const factsOf = (w: WorkerRow) => json<ComputerFacts>(w.facts_json, {});
/** The worker's verified files as its last list said (inventory_json), read once for each list it sends. */
const inventories = new Map<string, { hash: string | null; inv: Inventory }>();
@@ -769,11 +770,11 @@ export function saveInventory(w: WorkerRow, raw: unknown): { lanes: string[]; wo
// it pictures only (the list is kept as sent, so its hash stays the one the worker computes).
const media = Array.isArray(o.media) ? MEDIA_KINDS.filter((k) => (o.media as unknown[]).includes(k)) : undefined;
const inv: Inventory = { files, nodePacks, ...(media && { media }) };
- const r = lanesFor(loadIndex(), inv, sha);
+ const { sets, ...r } = lanesFor(loadIndex(), inv, sha);
const invHash = inventoryHash({ ...inv, files: sent });
db()
.prepare("UPDATE relay_workers SET inventory_json = ?, inventory_hash = ?, lanes_json = ? WHERE id = ?")
- .run(JSON.stringify(inv), invHash, JSON.stringify({ lanes: r.lanes, workflows: r.workflows, index: indexKey() }), w.id);
+ .run(JSON.stringify(inv), invHash, JSON.stringify({ lanes: r.lanes, workflows: r.workflows, index: indexKey(), sets }), w.id);
return r;
}
@@ -789,7 +790,7 @@ export function refreshLanes(w: WorkerRow): boolean {
const key = indexKey();
if (capableOf(w).index === key) return false;
const r = lanesFor(loadIndex(), inventoryOf(w), sha);
- const lanesJson = JSON.stringify({ lanes: r.lanes, workflows: r.workflows, index: key });
+ const lanesJson = JSON.stringify({ lanes: r.lanes, workflows: r.workflows, index: key, sets: r.sets });
db().prepare("UPDATE relay_workers SET lanes_json = ? WHERE id = ?").run(lanesJson, w.id);
w.lanes_json = lanesJson;
return true;
@@ -933,20 +934,18 @@ function claimed(t: TaskRow, w: WorkerRow, device: string, now: number): Claimed
/**
* The files this worker runs a workflow with (src/lib/gpu/model-variants.ts pickFiles): a model variant made for its
- * card's generation (gpuGen in its facts), else the workflow's own files, else another variant, by the files it verified
- * and its VRAM. Null when it has the files of none, or too little VRAM. A worker program older than VARIANT_PROTOCOL
- * gets the workflow's own files only.
+ * card's generation (gpuGen in its facts), else the workflow's own files, else another variant, by the file sets it has
+ * whole (its lanes' `sets`, from the files it verified) and its VRAM. Null when it has none of them, or too little VRAM.
+ * A worker program older than VARIANT_PROTOCOL gets the workflow's own files only.
*/
-export function workerFiles(w: Pick<WorkerRow, "id" | "inventory_json" | "inventory_hash" | "facts_json" | "protocol">, workflowId: string): FileChoice | null {
- const index = loadIndex();
- const inv = inventoryOf(w);
+export function workerFiles(w: Pick<WorkerRow, "lanes_json" | "facts_json" | "protocol">, workflowId: string): FileChoice | null {
+ const cap = capableOf(w);
+ if (!cap.workflows.includes(workflowId)) return null;
+ const whole = cap.sets?.[workflowId] ?? [null];
const facts = json<ComputerFacts>(w.facts_json, {});
const vram = facts.vramBytes ?? 0;
- const has = (key: FileKey) => {
- const f = index.files[key];
- return !!f && hasFile(inv, { folder: f.folder, name: f.file, size: f.sizeBytes, sha256: f.sha256 ?? null });
- };
- return pickFiles(fileChoices(index, workflowId), { gpuGen: facts.gpuGen ?? null, has, fits: (gb) => minVramBytesFor(gb) <= vram, variants: (w.protocol ?? 0) >= VARIANT_PROTOCOL });
+ const choices = fileChoices(loadIndex(), workflowId).filter((c) => whole.includes(c.variant));
+ return pickFiles(choices, { gpuGen: facts.gpuGen ?? null, has: () => true, fits: (gb) => minVramBytesFor(gb) <= vram, variants: (w.protocol ?? 0) >= VARIANT_PROTOCOL });
}
/** How long a task should take on this worker: the lane's bench median there, or the task's own estimate. */
diff --git a/tests/model-variants.test.ts b/tests/model-variants.test.ts
index ef4285a7..c0d51a0d 100644
--- a/tests/model-variants.test.ts
+++ b/tests/model-variants.test.ts
@@ -198,6 +198,13 @@ describe("what a worker can run (lanesFor)", () => {
// What it lacks is said in the workflow's own files.
expect(part.missing.flatMap((m) => m.files)).toContain(FP8);
});
+
+ it("says which file sets of a workflow with variants it has whole", () => {
+ expect(lanesFor(idx, workerInventory([FP8, TE_FP8, INT8, TE_INT8, VAE]), sha).sets[KREA]).toEqual([null, "int8"]);
+ expect(lanesFor(idx, workerInventory([INT8, TE_INT8, VAE]), sha).sets[KREA]).toEqual(["int8"]);
+ expect(lanesFor(idx, workerInventory([FP8, TE_FP8, VAE]), sha).sets[KREA]).toEqual([null]);
+ expect(lanesFor(idx, workerInventory([INT8, VAE]), sha).sets[KREA]).toBeUndefined();
+ });
});
/** A person's ComfyUI (as its GPU check reads it) with these files and every node class. */
diff --git a/tests/pool-model-variants.test.ts b/tests/pool-model-variants.test.ts
index 95716aaf..8253e23b 100644
--- a/tests/pool-model-variants.test.ts
+++ b/tests/pool-model-variants.test.ts
@@ -202,6 +202,19 @@ describe("an older worker program (before protocol 5)", () => {
});
});
+describe("lanes worked out before model variants", () => {
+ it("count the workflow's own files only", () => {
+ ownerJob();
+ const w = worker("before", { files: BOTH, gpuGen: "8.6" });
+ const cap = JSON.parse(row(w).lanes_json!);
+ delete cap.sets;
+ db().prepare("UPDATE relay_workers SET lanes_json = ? WHERE id = ?").run(JSON.stringify(cap), w.id);
+ const c = claim(w)!;
+ expect(c.variant).toBeUndefined();
+ expect(c.graph).toEqual(GRAPH);
+ });
+});
+
describe("VRAM", () => {
it("a card with too little memory takes neither", () => {
ownerJob();