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
Hosted runs: with the studio's GPUs first, the price check asks where the run will really go
Adarshae28a78652fd
diff --git a/docs/public-signup.md b/docs/public-signup.mdindex f2e2ad24..b83d4035 100644--- a/docs/public-signup.md+++ b/docs/public-signup.md@@ -389,7 +389,10 @@ With it on:- An account with no GPU of its own can run in the studios (generations, camera motions, effects, apps).- An account whose own GPU is online runs there by default, unless the billing service's policy puts the studio'sGPUs first (`prefer: "pool"`). The composer shows where a run goes ("Your GPU" or "This studio's GPUs"), and the- person can pick either. When the account's own GPU doesn't answer and the run named no place, the run is not moved+ person can pick either. With the studio's GPUs first and no pick, the price check names no place, as the run does,+ so it answers for where the server will really send the run: what the studio's GPUs don't take shows and runs as a+ run on the account's own GPU, with its own GPU's check before Run. When the account's own GPU doesn't answer and the+ run named no place, the run is not movedto the studio's GPUs: the page asks first, and runs it there if the person says so. A run the studio's GPUs wouldn'ttake (a model or a kind not offered there, extra LoRAs, a file kind they don't take, Image to 3D, the billing servicenot answering) goes to the account's own GPU as before, and waits for it there.diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsxindex 786b6ba9..942f3710 100644--- a/src/components/studio/composer.tsx+++ b/src/components/studio/composer.tsx@@ -20,7 +20,7 @@ import { locksByDefault } from "@/lib/catalog/palettes";import { DEFAULT_LOOK, lookCard } from "@/lib/catalog/soul-cards";import { formatsOf } from "@/lib/av/formats";import { poolRunState, quoteBody, useHostedQuote, useSettled, type RunOn } from "@/lib/hosted";-import { composerPlace } from "@/lib/run-place";+import { composerOnPool, composerPlace } from "@/lib/run-place";import { PoolNote } from "./pool-note";import { poolRunsModel } from "@/lib/pool-rules";import { HoldFilesCtx } from "@/lib/held-files";@@ -644,11 +644,22 @@ export function Composer({ docked }: { docked: boolean }) {// (The place the run names: none when the default is the studio's GPUs only because the studio puts them first.)const { runOn, place: runPlace } = composerPlace(runOnPick, ownOnline, viewerInfo?.prefer === "pool");const hostedHere = !!viewerInfo?.hosted && model?.engine === "open";- const poolPrice = hostedHere && runOn === "pool";- const wantPrice = poolPrice ? quoteBody(signed.request, runOn) : null;+ // The price check is asked with the place the run itself names: none while the studio puts its GPUs first and the+ // account's own GPU is online, so it answers for where the server would really send the run.+ const askPool = hostedHere && runOn === "pool";+ const wantPrice = askPool ? quoteBody(signed.request, runPlace) : null;const priceBody = useSettled(wantPrice);const priceQuery = useHostedQuote(priceBody);const hostedCheck = priceQuery.data;+ // What the check last said of a run that names no place, kept while it asks again for a changed draft.+ const [lastOnPool, setLastOnPool] = useState(true);+ const checkedOnPool = hostedCheck === undefined ? null : hostedCheck?.place === "pool";+ if (checkedOnPool !== null && checkedOnPool !== lastOnPool) setLastOnPool(checkedOnPool);+ // A run on this studio's GPUs (their price and line, no pre-flight of the account's own GPU, the price shown sent with+ // it): named there, or the check says the server sends it there. What they don't take runs on its own GPU, as before.+ const poolPrice = askPool && composerOnPool(runPlace, hostedCheck, lastOnPool);+ // Where the place switch says it runs.+ const shownOn: RunOn = runOn === "pool" && hostedHere && !poolPrice ? "own" : runOn;// The price check has answered for the draft as it is now (not one typed a moment ago).const priceSettled = !wantPrice || (priceBody === wantPrice && priceQuery.isFetched && !priceQuery.isFetching);const hostedQuote = hostedCheck?.quote;@@ -1690,11 +1701,11 @@ export function Composer({ docked }: { docked: boolean }) {<buttontype="button"onMouseDown={(e) => e.preventDefault()}- onClick={() => setRunOn(runOn === "own" ? "pool" : "own")}- aria-label={`Runs on ${runOn === "own" ? "your GPU" : "this studio's GPUs"}. Switch`}+ onClick={() => setRunOn(shownOn === "own" ? "pool" : "own")}+ aria-label={`Runs on ${shownOn === "own" ? "your GPU" : "this studio's GPUs"}. Switch`}className="shrink-0 rounded-md px-1.5 py-0.5 text-[12px] text-muted-foreground underline decoration-border-strong underline-offset-2 hover:text-foreground">- {runOn === "own" ? "Your GPU" : "This studio's GPUs"}+ {shownOn === "own" ? "Your GPU" : "This studio's GPUs"}</button>)}{costText && (diff --git a/src/components/studio/run-place-chip.tsx b/src/components/studio/run-place-chip.tsxindex 72fa5c37..b0f33d93 100644--- a/src/components/studio/run-place-chip.tsx+++ b/src/components/studio/run-place-chip.tsx@@ -11,7 +11,7 @@ import type { Engine, GenerationRequest } from "@/lib/catalog/types";import { CONNECT_GPU_EVENT, signInHref, useHydrated, useStatus, useViewer } from "@/lib/api";import { formatCost } from "@/lib/format";import { quoteBody, useHostedQuote, useSettled } from "@/lib/hosted";-import { checkedPool, runPlace, type RunAudience, type RunPlace, type RunPlaceInput } from "@/lib/run-place";+import { checkedPool, openCheckPlace, runPlace, type RunAudience, type RunPlace, type RunPlaceInput } from "@/lib/run-place";import { cn } from "@/lib/utils";import { chipBase, chipIdle } from "./chip";import { EngineSwitch } from "./engine-switch";@@ -55,8 +55,11 @@ export function useRunPlace(input: Omit<RunPlaceInput, "audience" | "format" | "*/export function useOpenRunPlace(models: readonly string[], request: GenerationRequest | null, o: { count?: number; ownGpuOnly?: boolean } = {}): RunPlace | null {const viewer = useRunViewer();- const mayPool = !!viewer && !o.ownGpuOnly && viewer.audience !== "owner" && viewer.hosted && (!viewer.gpu || viewer.preferPool);- const checked = useHostedQuote(useSettled(mayPool ? quoteBody(request, "pool") : null)).data;+ // Asked with the place the tool's run names (none for an account whose own GPU is there while this studio puts its+ // GPUs first: the server then sends what they don't take to that GPU, and the check answers so).+ const place = openCheckPlace(viewer, o.ownGpuOnly);+ const mayPool = place !== null;+ const checked = useHostedQuote(useSettled(mayPool ? quoteBody(request, place) : null)).data;if (!viewer) return null;// This studio's GPUs only on the server's word (as the studio composer asks it): a model it doesn't offer there, or// no complete run to check yet, is your GPU (connect it, or sign up).diff --git a/src/lib/hosted.ts b/src/lib/hosted.tsindex 4e95e1a3..7ca0d0d9 100644--- a/src/lib/hosted.ts+++ b/src/lib/hosted.ts@@ -159,9 +159,12 @@ export function poolRunState(check: HostedCheck | null | undefined): { refused:return { refused: false, text: q.text, ...(q.sub && { sub: q.sub }), ...(check?.line && { wait: lineWords(check.line) }) };}-/** The request as the price check sends it: the run, plus where it should go. */-export function quoteBody(req: GenerationRequest | null, runOn: RunOn): string | null {- return req ? JSON.stringify({ ...req, place: runOn }) : null;+/**+ * The request as the price check sends it: the run, plus the place the run itself names (none: the server decides, as it+ * does for the run, so the check answers for where the run would really go).+ */+export function quoteBody(req: GenerationRequest | null, place: RunOn | undefined): string | null {+ return req ? JSON.stringify(place ? { ...req, place } : req) : null;}/** "Tell me when": an offer's click goes to the billing service, which counts it. */diff --git a/src/lib/run-place.ts b/src/lib/run-place.tsindex 30378672..e8e2d4b8 100644--- a/src/lib/run-place.ts+++ b/src/lib/run-place.ts@@ -194,6 +194,30 @@ export function composerPlace(pick: "own" | "pool" | null, ownOnline: boolean, preturn preferPool ? { runOn: "pool", place: undefined } : { runOn: "own", place: "own" };}+/**+ * Is a composer's run one on this studio's GPUs (their price and place in line, no check of the person's own GPU, the+ * price shown sent with it)? A run that names its place: that place. One that names none (this studio's GPUs first while+ * the person's own GPU is online, so the server decides): only once the price check, asked with no place either, says the+ * run goes there. A model those GPUs don't take then runs on the person's own GPU, as before. `checked` undefined: no+ * answer for this draft yet, so `last` (what the check said for the draft before) stands meanwhile.+ */+export function composerOnPool(place: "own" | "pool" | undefined, checked: { place?: "pool" } | null | undefined, last: boolean): boolean {+ if (place) return place === "pool";+ return checked === undefined ? last : checked?.place === "pool";+}++/**+ * The place an app's own tool names in its price check, as its run names it: "pool" for a viewer with no GPU of its own;+ * none for one whose own GPU is there while this studio puts its GPUs first (the server then sends what they don't take+ * to that GPU, and the check says so). Null: no check (the owner, hosted runs off, a tool for the person's own GPU only,+ * or a viewer whose runs go to its own GPU).+ */+export function openCheckPlace(v: { audience: RunAudience; gpu: boolean; hosted: boolean; preferPool: boolean } | null, ownGpuOnly = false): "pool" | undefined | null {+ if (!v || ownGpuOnly || v.audience === "owner" || !v.hosted) return null;+ if (!v.gpu) return "pool";+ return v.preferPool ? undefined : null;+}+/** Drawn in this browser (a Kinetic template, Click to Ad's end card): the same place and price whoever looks. */export const IN_BROWSER: RunPlace = runPlace({ audience: "guest", engine: "browser", format: String });diff --git a/tests/pool-limits.test.ts b/tests/pool-limits.test.tsindex c98756dd..941e2382 100644--- a/tests/pool-limits.test.ts+++ b/tests/pool-limits.test.ts@@ -360,6 +360,29 @@ describe("where a run goes", () => {expect(named.body.code).toBe("not-offered");});+ it("with this install's GPUs first, the price check of a run that names no place answers for where it really goes", async () => {+ withBilling({ prefer: "pool", pool: { deny: ["oss-z-image-turbo"] }, limits: { activeRuns: 0, waiting: 0, runsPerHour: 0 } });+ const a = account({ gpu: "online" });+ const LORA = { loras: [{ file: "x.safetensors", url: "https://huggingface.co/x/x.safetensors" }] };+ type Check = { place?: string; quote?: { allowed: boolean; code?: string } };+ // A model they keep off: no pool place and no quote (Run stays on, and it runs on its own GPU).+ const kept = (await preview(IMAGE, a.cookie)).body as Check;+ expect(kept.place).toBeUndefined();+ expect(kept.quote).toBeUndefined();+ // Named there, it is refused before Run, as the run would be.+ const named = (await preview({ ...IMAGE, place: "pool" }, a.cookie)).body as Check;+ expect(named.place).toBe("pool");+ expect(named.quote).toMatchObject({ allowed: false, code: "not-offered" });+ // One they take, named none: this install's GPUs, with its price; with LoRAs, its own GPU again.+ withBilling({ prefer: "pool", limits: { activeRuns: 0, waiting: 0, runsPerHour: 0 } });+ const taken = (await preview(IMAGE, a.cookie)).body as Check;+ expect(taken.place).toBe("pool");+ expect(taken.quote).toMatchObject({ allowed: true });+ const lora = (await preview({ ...IMAGE, ...LORA }, a.cookie)).body as Check;+ expect(lora.place).toBeUndefined();+ expect(lora.quote).toBeUndefined();+ });+it("an own GPU that doesn't answer: a run that named no place is asked about, never moved and charged", async () => {withBilling({ limits: { activeRuns: 0, waiting: 0, runsPerHour: 0 } });const a = account({ gpu: "offline" });diff --git a/tests/run-place.test.ts b/tests/run-place.test.tsindex b9ede31b..510efa92 100644--- a/tests/run-place.test.ts+++ b/tests/run-place.test.ts@@ -1,5 +1,6 @@import { describe, expect, it } from "vitest";-import { checkedPool, composerPlace, IN_BROWSER, mainModel, placePrice, runPlace, type RunPlaceInput } from "@/lib/run-place";+import { quoteBody } from "@/lib/hosted";+import { checkedPool, composerOnPool, composerPlace, IN_BROWSER, mainModel, openCheckPlace, placePrice, runPlace, type RunPlaceInput } from "@/lib/run-place";/** Where a run happens and what it costs, for each audience and engine (the composers' place chip and send button). */const fmt = (usd: number) => `$${usd.toFixed(2)}`;@@ -204,6 +205,42 @@ describe("where a composer's run goes, and the place it names", () => {});});+describe("the price check asks with the place the run names", () => {+ const req = { feature: "image", modelId: "oss-z-image-turbo", prompt: "a fox" };+ it("named: with it; named none (the server decides): with none, so the answer is where the run would really go", () => {+ expect(JSON.parse(quoteBody(req, "pool")!)).toEqual({ ...req, place: "pool" });+ expect(JSON.parse(quoteBody(req, undefined)!)).toEqual(req);+ expect(quoteBody(null, "pool")).toBeNull();+ });++ it("a composer's run is one on this studio's GPUs when named there, or when its check says the server sends it there", () => {+ // Named: as named, whatever the check says.+ expect(composerOnPool("pool", undefined, false)).toBe(true);+ expect(composerOnPool("own", { place: "pool" }, true)).toBe(false);+ // Named none (this studio's GPUs first, its own GPU online): a model they don't take (LoRAs, a model kept off) gets+ // no pool answer, so it runs on its own GPU, with its own GPU's check before Run and no pool price.+ const lora = { place: undefined };+ expect(composerOnPool(undefined, lora, true)).toBe(false);+ expect(composerOnPool(undefined, null, true)).toBe(false);+ expect(composerOnPool(undefined, { place: "pool" }, false)).toBe(true);+ // No answer yet for a changed draft: the last answer stands meanwhile.+ expect(composerOnPool(undefined, undefined, true)).toBe(true);+ expect(composerOnPool(undefined, undefined, false)).toBe(false);+ });++ it("an app's tool: \"pool\" with no GPU of its own; none with one while this studio puts its GPUs first; else no check", () => {+ const v = (o: Partial<{ audience: "owner" | "account" | "guest"; gpu: boolean; hosted: boolean; preferPool: boolean }> = {}) => ({ audience: "account" as const, gpu: false, hosted: true, preferPool: false, ...o });+ expect(openCheckPlace(v())).toBe("pool");+ expect(openCheckPlace(v({ audience: "guest" }))).toBe("pool");+ expect(openCheckPlace(v({ gpu: true, preferPool: true }))).toBeUndefined();+ expect(openCheckPlace(v({ gpu: true }))).toBeNull();+ expect(openCheckPlace(v({ hosted: false }))).toBeNull();+ expect(openCheckPlace(v({ audience: "owner" }))).toBeNull();+ expect(openCheckPlace(v(), true)).toBeNull();+ expect(openCheckPlace(null)).toBeNull();+ });+});+describe("checkedPool", () => {it("is this studio's GPUs only when the price check says the run goes there", () => {expect(checkedPool({ place: "pool", quote: { text: "$0.02", sub: "Billed to your balance" } })).toEqual({ text: "$0.02", sub: "Billed to your balance" });