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.

Hosted runs: a 3D model runs on this install's GPUs while a worker's CPU slot finishes it

Adarshb50e0f0080da
diff --git a/docs/billing-hook.md b/docs/billing-hook.md
index 05b3c8b9..51ab34c9 100644
--- a/docs/billing-hook.md
+++ b/docs/billing-hook.md
@@ -144,9 +144,11 @@ A run made only of CPU work is free and never counted. Fuobe asks the service fo
counts against none of the policy's limits. A worker with a CPU slot runs it beside its GPU's job, in a line of its
own ([gpu-workers.md](gpu-workers.md), "The CPU slot"). A worker with none runs it in its GPU's line, as before.
-3D runs (Image to 3D and the other 3D tools) aren't offered on this install's GPUs yet, whatever `kinds.model3d` says.
-They run on the account's own GPU, as before. An account with no GPU of its own is told the tool isn't available here
-(403, `code: "own-gpu-tool"`).
+A 3D model whose GLB gets its finish (an image-to-3D model, or Hi3D's refine of one) runs on this install's GPUs while
+a worker's CPU slot runs that finish ([gpu-workers.md](gpu-workers.md), "The CPU slot"); then `kinds.model3d` says, as
+for any other kind. Every other 3D run (a splat, a scene, a still made into 3D in one chain), and any 3D run while no
+CPU slot finishes it, runs on the account's own GPU, as before. An account with no GPU of its own is then told the
+tool isn't available here (403, `code: "own-gpu-tool"`).
The policy's limits count runs on this install's GPUs only, never runs on the account's own GPU or key (those keep the
install's own limits). A run is one press of Run: its jobs and chain steps count once. `activeRuns` counts runs going
diff --git a/docs/gpu-workers.md b/docs/gpu-workers.md
index aae88786..9ae08471 100644
--- a/docs/gpu-workers.md
+++ b/docs/gpu-workers.md
@@ -584,7 +584,8 @@ kind, in the run's class and at the run's place in line. Light CPU work has its
finishing job's run limit is its lane's run ceiling, which the owner sets in the queue settings. Another program on the
GPU stops only the GPU's job; a pause now by hand stops both. A 3D run of an account on the install's GPUs is taken
only while a worker heard from in the last few minutes, built for this studio's catalog, has a CPU slot that runs the
-3D finish.
+3D finish, and only for a model whose GLB gets that finish (an image-to-3D model, or Hi3D's refine of one). Then the
+billing policy's `kinds.model3d` says, as for any other kind.
A finishing job is queued once for its run (and step), even when two app processes ask at the same time, and its
results are stored once. It waits for a CPU slot as long as its run may wait in line. If no CPU slot takes it by then,
diff --git a/src/app/api/generations/route.ts b/src/app/api/generations/route.ts
index c70d723e..72627a92 100644
--- a/src/app/api/generations/route.ts
+++ b/src/app/api/generations/route.ts
@@ -236,8 +236,8 @@ export async function POST(request: Request) {
return refuse(422, ISOLATED_ON_COMPUTER, { code: "isolated-on-computer" });
}
// An account's 3D model (Image to 3D, Photo to 3D, Make it 3D) runs on its own GPU or key, and is finished on
- // this server under the account's limits (model3d-finish.ts). This install's GPUs don't take 3D: decidePlace
- // refuses it there, and createGenerations refuses a run stamped for them.
+ // this server under the account's limits (model3d-finish.ts). This install's GPUs take a 3D model only where a
+ // worker's CPU slot finishes it (computer/finish.ts poolFinishes3d): decidePlace and createGenerations say so.
const skip = (body as { gpuCheck?: unknown } | null)?.gpuCheck === "skip";
const gate = await gateGeneration(gpuTargetFor(request, "read"), { request: req, route: planned.route, op: planned.op, modelId: planned.model.id, gpu: planned.gpu, h3: planned.h3, skip, actor: account?.id ?? "owner" });
if (!gate.ok) {
diff --git a/src/server/account-tool-run.ts b/src/server/account-tool-run.ts
index 80191894..fe06c395 100644
--- a/src/server/account-tool-run.ts
+++ b/src/server/account-tool-run.ts
@@ -42,7 +42,8 @@ import { answerPress, claimPress, pressTry, releasePress, toolPressKey, toolPres
* - the GPU pre-flight on its own ComfyUI (409 gpu-setup with the guided fix), and the LoRAs a step adds (409
* comfy_missing_model);
* - the moderation service's check, when one is set (hosted-run.ts moderateRun);
- * - a 3D model only on the account's own GPU or key (model3dAllowed): its finish runs on this server under its limits.
+ * - a 3D model on the account's own GPU or key (model3dAllowed): its finish runs on this server under its limits. On this
+ * install's GPUs the gate offers one only where a worker finishes it (hosted-run.ts poolGate).
*
* Then the tool's own start runs inside asAccount (tenant.ts): every generation it creates is stamped as the account's,
* reads only its files and goes to its GPU or key. Where a run goes is decided in one place (`placeOf`): with hosted
@@ -242,8 +243,9 @@ export interface ToolStep {
export type ToolPlace = { kind: "own" } | ({ kind: "pool" } & ToolPoolRun) | { kind: "refuse"; refusal: Refusal };
/**
- * Whether a run placed here may make a 3D model. A 3D model is finished on this server under the account's own limits
- * (model3d-finish.ts): allowed on the account's own GPU or key, never on this install's GPUs (hosted runs don't offer 3D yet).
+ * Whether a run placed on the account's own GPU or key may make a 3D model: always, finished on this server under the
+ * account's own limits (model3d-finish.ts). A run on this install's GPUs never comes here: the gate (hosted-run.ts
+ * poolGate) lets a 3D model there only where a worker's CPU slot finishes it.
*/
export const model3dAllowed = (place: Pick<ToolPlace, "kind">): boolean => place.kind === "own";
diff --git a/src/server/computer/finish.ts b/src/server/computer/finish.ts
index 582c283d..8ce4185c 100644
--- a/src/server/computer/finish.ts
+++ b/src/server/computer/finish.ts
@@ -7,7 +7,7 @@ import type { HistoryEntryLike, WantedFile } from "@/lib/relay";
import { accountTotalBytes, accountUsage, diskFloorBytes, diskFreeBytes, diskHasRoom } from "../account-files";
import { db } from "../db";
import { pictureWithoutMetadata } from "../media-clean";
-import { ACCOUNT_TURNTABLE, accountFinishProblem, MODEL_FINISH_VERSION, modelToFinish, OWN_ORBIT, withTurntable } from "../model3d-finish";
+import { ACCOUNT_TURNTABLE, accountFinishProblem, FINISHED_3D_OPS, MODEL_FINISH_VERSION, modelToFinish, OWN_ORBIT, withTurntable } from "../model3d-finish";
import { getSetting } from "../settings";
import { absolutePath, deleteAsset, getAsset, readRef, saveFile, type Asset } from "../storage";
import { tenantAccount } from "../tenant";
@@ -43,6 +43,15 @@ export function workersFinish(kind: FinishKind, now = Date.now()): boolean {
return rows.some((w) => ticketReady(w) && !!cpuSlotOf(w)?.finishes.includes(kind));
}
+/**
+ * May a 3D model's run go on this install's GPUs: one whose GLB gets its finish (an image-to-3D job or Hi3D's refine of
+ * one from ComfyUI: model3d-finish.ts FINISHED_3D_OPS), while a worker's CPU slot runs that finish (workersFinish). Every
+ * other 3D model (a scene, a splat, a rig, a still made into 3D in one chain) stays on a visitor's own GPU or key.
+ */
+export function poolFinishes3d(step: { provider: string; op: string }): boolean {
+ return step.provider === "comfyui" && FINISHED_3D_OPS.includes(step.op) && workersFinish("model3d");
+}
+
/** A finishing job's ticket as its task keeps it, or null. */
const ticketOf = (t: Pick<TaskRow, "finish_json">): FinishTicket | null => (t.finish_json ? json<FinishTicket | null>(t.finish_json, null) : null);
diff --git a/src/server/generations.ts b/src/server/generations.ts
index 201c4941..86706f39 100644
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@ -98,7 +98,7 @@ import { renderPathVideo } from "./path-render";
import { songFormat, songToolProblem } from "@/lib/lyrics";
import { hostedUntested } from "@/lib/catalog/hosted-untested";
import { modelToFinish, startModelFinish, startTurntable, stopModelFinish, type OutputStore } from "./model3d-finish";
-import { finishTask, pathOnWorker, startWorkerModelFinish, stopWorkerFinish, workersFinish } from "./computer/finish";
+import { finishTask, pathOnWorker, poolFinishes3d, startWorkerModelFinish, stopWorkerFinish, workersFinish } from "./computer/finish";
import { PATH_FPS, PATH_FRAMES } from "@/lib/camera-path";
import { cropPicture, isCropWindow } from "./crop-picture";
import { convertMask, decodePng, encodePng } from "./png";
@@ -1136,9 +1136,12 @@ export function createGenerations(sent: GenerationRequest, opts: CreateOptions =
const found = catalogModel && offeredFor(catalogModel, original.engine);
const shotModel = found && dualEngine(found) ? onEngine(found, engineFor(found, original.engine)) : found;
// An account's 3D model is finished on this server under its own limits (model3d-finish.ts). On this install's GPUs it
- // is finished on a worker's CPU slot (computer/finish.ts): offered only while a worker runs that finish. Any Angle's 3D
- // view is the exception: a splat and its turntable, nothing to finish.
- if (original.account && original.place === "pool" && shotModel?.kind === "model3d" && shotModel.id !== ANY_ANGLE.buildModel && !workersFinish("model3d")) throw new Error(OWN_GPU_TOOL_MESSAGE);
+ // is finished on a worker's CPU slot (computer/finish.ts): offered only for a model whose GLB gets that finish, while a
+ // worker runs it (poolFinishes3d). Any Angle's 3D view is the exception: a splat and its turntable, nothing to finish.
+ if (original.account && original.place === "pool" && shotModel?.kind === "model3d" && shotModel.id !== ANY_ANGLE.buildModel) {
+ const ops = original.op ? [original.op] : shotModel.routes.filter((r) => r.provider === "comfyui").map((r) => r.op);
+ if (!ops.length || !ops.every((op) => poolFinishes3d({ provider: "comfyui", op }))) throw new Error(OWN_GPU_TOOL_MESSAGE);
+ }
if (!opts.dependsOn && shotModel?.options.multiShot?.mode === "concat" && (original.params?.shots?.filter((x) => x.prompt.trim()).length ?? 0) > 1) {
return createShotFilm(original, shotModel);
}
diff --git a/src/server/hosted-run.ts b/src/server/hosted-run.ts
index 511558a9..6d6b3727 100644
--- a/src/server/hosted-run.ts
+++ b/src/server/hosted-run.ts
@@ -29,6 +29,7 @@ import { db } from "./db";
import { AccountRunError, createGenerations, outputKind, plannedSteps, previewChained, previewGeneration, stepsOf, type PlannedStep } from "./generations";
import { loadIndex } from "./gpu/index-file";
import { attemptLimitMs, MAX_ATTEMPTS, poolLane } from "./computer/pool";
+import { poolFinishes3d } from "./computer/finish";
import { holdTiming } from "./queue-settings";
import { HOSTED_GUEST_WORDS, HOSTED_WORDS, inputCounts, outputsWords, poolAllows, poolAllowsRun, poolAway, poolOnWorkers, poolReady, poolRunsProvider, poolTakes, poolTicketsReady, poolUploads, POOL_LANE, queueFacts, runFacts, runOnPool, workflowPicks } from "./hosted";
import { withRunStamp } from "./run-stamp";
@@ -223,7 +224,7 @@ export function stepsProblem(p: Policy, steps: PlannedStep[]): string | null {
if (s.provider === "comfyui" && !poolTakes(stepEndpoint(s))) return HOSTED_WORDS.notOffered;
continue;
}
- if (s.provider !== "comfyui" || s.kind === "model3d") return HOSTED_WORDS.notOffered;
+ if (s.provider !== "comfyui" || (s.kind === "model3d" && !poolFinishes3d(s))) return HOSTED_WORDS.notOffered;
if (!poolAllows(p, s.modelId, s.presetId) || !kindAllowed(p, s.kind as RunFacts["kind"])) return HOSTED_WORDS.notOffered;
if (!poolTakes(stepEndpoint(s))) return HOSTED_WORDS.notOffered;
}
@@ -298,11 +299,12 @@ export function pricedSteps(steps: PlannedStep[]): NonNullable<RunFacts["steps"]
}
/**
- * Why this install's GPUs won't take a run: a 3D model, a model or kind not offered there, a model their card can't run,
- * LoRAs, a kind of file, more outputs at once than a run there makes (`outputs`: a tool's run, which can't be cut down
- * the way the studios' own runs are), one that runs on the visitor's own setup only (`ownSetup`: a static item of
- * own-setup.ts, or a workflow none of this install's GPUs can run right now: none holds its files, serves its lane, or
- * has the memory), or (`busy`) not right now: the GPUs that could run it are being updated.
+ * Why this install's GPUs won't take a run: a 3D model no worker finishes (computer/finish.ts poolFinishes3d), a model
+ * or kind not offered there, a model their card can't run, LoRAs, a kind of file, more outputs at once than a run there
+ * makes (`outputs`: a tool's run, which can't be cut down the way the studios' own runs are), one that runs on the
+ * visitor's own setup only (`ownSetup`: a static item of own-setup.ts, or a workflow none of this install's GPUs can
+ * run right now: none holds its files, serves its lane, or has the memory), or (`busy`) not right now: the GPUs that
+ * could run it are being updated.
*/
export type GateReason = "model3d" | "notOffered" | "rtxCard" | "loras" | "inputs" | "outputs" | "ownSetup" | "busy";
@@ -325,11 +327,11 @@ export const gateText = (gate: GateRefusal, guest: boolean): string =>
/**
* The one check of whether this install's GPUs take a run, shared by the run itself (decidePlace) and the price check
- * before Run (poolQuote), so the two always agree: its output kind (no 3D there), the policy's model, app and kind
- * lists (for the run's own model and every other model it makes a step with, such as a 2K take's finish), a worker
- * allowed its lane, a card that can run it, LoRAs, the kinds of file it sends, and every later step of a chain (planned
- * only once the cheaper checks pass). `p` null: the billing service didn't answer, so only what needs no policy is
- * checked. Passed, it gives the planned steps for the run's one price.
+ * before Run (poolQuote), so the two always agree: its output kind (3D only where a worker finishes it), the policy's
+ * model, app and kind lists (for the run's own model and every other model it makes a step with, such as a 2K take's
+ * finish), a worker allowed its lane, a card that can run it, LoRAs, the kinds of file it sends, and every later step
+ * of a chain (planned only once the cheaper checks pass). `p` null: the billing service didn't answer, so only what needs
+ * no policy is checked. Passed, it gives the planned steps for the run's one price.
*
* First of all, every step's own setup (own-setup.ts): a model, mode or option that runs on a visitor's own GPU or key
* only is refused as "ownSetup" with that setup, on the run's own step and on every later step of a chain alike.
@@ -344,7 +346,9 @@ export function poolGate(
if (own) return { ok: false, reason: "ownSetup", setup: own };
const gpu = needsGpu(planned.route.endpoint);
const kind = outputKind(planned.op, planned.model);
- if (kind === "model3d") return { ok: false, reason: "model3d" };
+ // A 3D model only where a worker finishes it (its GLB checked, made for the web and given a turntable there): then the
+ // policy's kinds say, as for any other kind.
+ if (kind === "model3d" && !poolFinishes3d({ provider: planned.route.provider, op: planned.op })) return { ok: false, reason: "model3d" };
if (p && (!poolAllowsRun(p, planned, req.presetId) || !kindAllowed(p, kind))) return { ok: false, reason: "notOffered", setup: gpu };
// Nothing of this install's runs it right now (no worker holds its files, is allowed its lane, or has the memory it
// needs): a run that would wait for nothing, so it runs on the visitor's own GPU instead.
diff --git a/src/server/model3d-finish.ts b/src/server/model3d-finish.ts
index 5e288f57..dfc5b3b8 100644
--- a/src/server/model3d-finish.ts
+++ b/src/server/model3d-finish.ts
@@ -43,9 +43,12 @@ const PROGRESS_EVERY_MS = 2_000;
const isGlb = (o: OutputFile) => o.kind === "model3d" && (o.contentType === "model/gltf-binary" || /\.glb(\?|$)/i.test(o.url));
+/** The operations whose GLB gets a finish: an image-to-3D job and Hi3D's refine of one (not a scene, splat or rig). */
+export const FINISHED_3D_OPS: readonly string[] = ["image-to-3d", "refine-3d"];
+
/** Which output a finish works on: the first GLB of an image-to-3D job (or Hi3D's refine of one) from ComfyUI (not a scene, splat or rig). */
export function modelToFinish(r: { provider: string; op: string }, outputs: OutputFile[]): number {
- if (r.provider !== "comfyui" || (r.op !== "image-to-3d" && r.op !== "refine-3d")) return -1;
+ if (r.provider !== "comfyui" || !FINISHED_3D_OPS.includes(r.op)) return -1;
return outputs.findIndex((o) => isGlb(o) && !!o.assetId && !o.meta?.finish && !o.meta?.role);
}
diff --git a/tests/pool-limits.test.ts b/tests/pool-limits.test.ts
index 3c3528c7..d1e95c15 100644
--- a/tests/pool-limits.test.ts
+++ b/tests/pool-limits.test.ts
@@ -853,6 +853,36 @@ describe("the price check before Run and the run itself", async () => {
}
});
+ it("a 3D model runs here only while a worker's CPU slot finishes it, and then as the policy's kinds say; a splat or a scene never does", async () => {
+ const a = account();
+ const acct = auth.accountById(a.id)!;
+ withBilling({ limits: NO_LIMITS });
+ const req = { ...THREE_D, account: a.id } as never;
+ const refused = async (r: Record<string, unknown>) => {
+ const run = await hostedRun.decidePlace(acct, { ...r, account: a.id } as never, undefined);
+ return run.kind === "refuse" ? run.refusal.body.error : run.kind;
+ };
+ expect(await refused(THREE_D)).toBe(OWN_GPU_TOOL_MESSAGE);
+ // A worker whose CPU slot runs the 3D finish: the model's GLB is checked, made for the web and given its turntable there.
+ db().prepare("UPDATE relay_workers SET cpu_slot_json = ? WHERE id = ?").run(JSON.stringify({ finishes: ["model3d"] }), worker.id);
+ try {
+ expect((await hostedRun.decidePlace(acct, req, undefined)).kind).toBe("pool");
+ expect((await hostedRun.poolQuote(acct, req, undefined))?.quote.allowed).toBe(true);
+ // The policy's kinds still say.
+ withBilling({ limits: NO_LIMITS, kinds: { model3d: false } });
+ expect(await refused(THREE_D)).toBe(HOSTED_WORDS.notOffered);
+ withBilling({ limits: NO_LIMITS });
+ // A splat or a scene gets no finish there: it stays on a visitor's own setup.
+ expect(await refused({ ...THREE_D, modelId: "oss-triposplat", op: "splat" })).toBe(OWN_GPU_TOOL_MESSAGE);
+ expect(await refused({ ...THREE_D, modelId: "oss-scene-moge", op: "scene-3d" })).toBe(OWN_GPU_TOOL_MESSAGE);
+ } finally {
+ db().prepare("UPDATE relay_workers SET cpu_slot_json = NULL WHERE id = ?").run(worker.id);
+ }
+ // No CPU slot that finishes it any more: refused again, before Run and at the run alike.
+ expect(await refused(THREE_D)).toBe(OWN_GPU_TOOL_MESSAGE);
+ expect((await hostedRun.poolQuote(acct, req, undefined))?.quote).toMatchObject({ allowed: false, text: OWN_GPU_TOOL_MESSAGE });
+ });
+
it("while every worker that could run it is built from the catalog before the studio's update, Run is off with plain words, never a run that waits for nothing", async () => {
const a = account();
const acct = auth.accountById(a.id)!;