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
Docs: who picks first, and streaming from RAM, on the workers
Adarsh8b6e3d254e96
diff --git a/docs/adding-a-model.md b/docs/adding-a-model.mdindex c8c7ea25..31dab439 100644--- a/docs/adding-a-model.md+++ b/docs/adding-a-model.md@@ -178,6 +178,37 @@ one is in [Workers: Model variants](gpu-workers.md#model-variants).A variant never adds a node, an input or a file outside the catalog's pins: the worker still loads only files itverified, and runs all its checks on the graph with the variant's files.+### Streaming from RAM++A workflow's `vramGb` is what it needs with every model weight on the card. ComfyUI can also keep part of the weights+in system RAM and stream them to the card at each step (dynamic VRAM loading). The run is slower, but a smaller card+with enough RAM can run the workflow. How workers and a person's own GPU use it is in+[Workers: Streaming from RAM](gpu-workers.md#streaming-from-ram).++1. Measure it first: run the workflow on a card smaller than its `vramGb`, with ComfyUI's dynamic VRAM on, and note the+ VRAM and the RAM the run needed.+2. Add the workflow to `workflows/comfyui/stream-needs.json`, the one list of streaming needs. Workflows with the same+ need share an entry:++ ```json+ {+ "streams": [+ { "workflows": ["minimax-h3-image-t2i", "krea2-turbo-t2i"], "vramGb": 10, "ramGb": 32 }+ ]+ }+ ```++ - `vramGb`: the card's memory it needs then, in GB. It must be below the workflow's own `vramGb`.+ - `ramGb`: the system RAM it needs then, in GB.+ - A workflow is in one entry at most. The need applies to whichever file set a GPU runs (its own files or a+ variant's).+3. Run `node scripts/comfy/build-requirements.mjs`. It writes each need into `requirements.json` (`stream`) and stops+ when a number isn't above 0, when `vramGb` isn't below the workflow's own, when a workflow isn't in the manifest or+ is named twice, or when an entry has a field it doesn't know.++Like every file of the catalog, a change to `stream-needs.json` (and so to `requirements.json`) changes the catalog+version, so the workers update to it.+## 7. The rest of the studio- Give each new studio or tool a row on the `/connect` board (`STUDIO_ROWS` in `src/server/gpu/tools.ts`).diff --git a/docs/admin-api.md b/docs/admin-api.mdindex a56fb4a0..edb7ce6d 100644--- a/docs/admin-api.md+++ b/docs/admin-api.md@@ -45,7 +45,7 @@ Keep the token out of URLs, logs and shared files. Send it only in the `Authoriz| `outputs:moderate` | `POST /api/admin/outputs/hide`, `/unhide` and `/remove` || `reports:read` | `GET /api/admin/reports` (reporters' emails only with `accounts:read`) || `workers:read` | `GET /api/admin/workers`, `GET /api/admin/workers/jobs`, `GET /api/admin/workers/events` |-| `workers:write` | `PATCH /api/admin/workers/{id}`: pause, resume, drain, hours, lanes, revoke; and `POST /api/admin/workers/{id}/update` |+| `workers:write` | `PATCH /api/admin/workers/{id}`: pause, resume, drain, hours, lanes, pick order, revoke; and `POST /api/admin/workers/{id}/update` || `workers:update` | `POST /api/admin/workers/{id}/update` only: ask a worker to update its program now || `workers:tokens` | `POST /api/admin/workers`, and `PATCH /api/admin/workers/{id}` with `rotate`: both answer with a worker token. A worker receives accounts' queued jobs with their input files and sends back the results, so give this scope only to a tool you'd trust with those || `queue:read` | `GET /api/admin/queue`, `GET /api/admin/queue/settings`, `GET /api/admin/queue/overrides` |@@ -123,16 +123,16 @@ Times are epoch milliseconds and sizes are bytes. Every answer is `Cache-Control| `POST /api/admin/queue/overrides` | `{ kind: "run", generationId, action: "next" | "hold", worker?, forMin? }` or `{ kind: "person", person | account, action: "boost" | "hold", forMin }` (`forMin` is needed for a boost) | 201 `{ override, replaced }`; 404 for no such run, worker or person with a run on the GPUs; 409 for a run that ended || `DELETE /api/admin/queue/overrides/{id}` | | `{ override }` (ended now); 404 when it isn't in effect || `POST /api/admin/queue/cancel` | `{ generationId }` | `{ generationId, status }`: the run ends as the person's own Cancel ends it; 404 for no such run, 409 for one that ended |-| `GET /api/admin/queue/settings` | | `{ settings: { runCeilingS: { default, lanes }, ownerWaitLimitS, fairShare, pickAllowanceMs, pausedBudgetS } }` ([gpu-workers.md](gpu-workers.md#the-queue)) |-| `PATCH /api/admin/queue/settings` | any of `runCeilingS: { default, lanes? }` (seconds, 60 to 86400; a given `runCeilingS` replaces the default and every lane's value), `ownerWaitLimitS` (seconds, 60 to 604800, or `null` for no limit), `fairShare` (boolean), `pickAllowanceMs` (0 to 3600000), `pausedBudgetS` (seconds, 0 to 604800) | `{ settings }`; 400 with the reason for a value out of bounds, an unknown setting or an unknown lane |+| `GET /api/admin/queue/settings` | | `{ settings: { runCeilingS: { default, lanes }, ownerWaitLimitS, fairShare, pickAllowanceMs, firstPickGraceMs, pausedBudgetS } }` ([gpu-workers.md](gpu-workers.md#the-queue)) |+| `PATCH /api/admin/queue/settings` | any of `runCeilingS: { default, lanes? }` (seconds, 60 to 86400; a given `runCeilingS` replaces the default and every lane's value), `ownerWaitLimitS` (seconds, 60 to 604800, or `null` for no limit), `fairShare` (boolean), `pickAllowanceMs` (0 to 3600000), `firstPickGraceMs` (0 to 600000; [gpu-workers.md](gpu-workers.md#who-picks-first)), `pausedBudgetS` (seconds, 0 to 604800) | `{ settings }`; 400 with the reason for a value out of bounds, an unknown setting or an unknown lane || `GET /api/admin/site/uploads` | | `{ switches: { soundConvert, soundTrim, videoTrim, photoConvert, photoCrop } }`: what a browser may do to a file that doesn't fit a tool before it is uploaded (convert a sound to MP3, offer a part of a sound or clip, convert or shrink a photo, offer a crop). All `true` by default. Every visitor reads the same values at `GET /api/site/uploads` || `PATCH /api/admin/site/uploads` | any of the five, each `true` or `false` | `{ switches }`; 400 with the reason for an unknown switch or a value that isn't a boolean. A switch that is off leaves that kind of file as it is: the tool says why it can't take it, and the server's checks apply. Browsers pick it up when they next load a page || `GET /api/admin/site/runs` | | `{ failureDetail }`: what a person reads when a run of theirs on this install's GPUs fails. `full`: the plain sentence and, under it, the cleaned technical reason (ComfyUI's own: no folders, addresses, keys or prompt text); `friendly`: the plain sentence only. Settings → Failed runs is the same choice. A new install starts with `full`; an install that had runs or settings before this choice existed keeps `friendly` || `PATCH /api/admin/site/runs` | `{ "failureDetail": "full" \| "friendly" }` | `{ failureDetail }`; 400 for any other body. Runs read it the next time they are shown. A person only ever sees the details of their own runs |-| `GET /api/admin/workers` | | `{ workers, lanes }`. Each worker adds `asked: { at, words }` or null, `jobs` (each job it holds: `{ taskId, generationId, slot, lane, laneLabel, stage, state, claimedAt, startedAt, progress, progressAt, movedAt, gpuBusy, stallMs, doing, typicalMs, etaS, owners, feature?, modelName?, op?, kind? }`: `doing` is what its ComfyUI runs now (`{ node, nodeClass, nodeTitle, value?, max?, pass? }`, or null), for the owner only; `movedAt` is when the worker last saw the job move, on the site clock, or null from an older worker; `gpuBusy` is its GPU use from 0 to 100, or null; past `stallMs` without a move the worker gives the job back; `etaS` is more than 0 or null, never 0 for a running job) and `lastEvent: { at, kind, event, words }` or null |+| `GET /api/admin/workers` | | `{ workers, lanes }`. Each worker adds `pickOrder`, `asked: { at, words }` or null, `jobs` (each job it holds: `{ taskId, generationId, slot, lane, laneLabel, stage, state, claimedAt, startedAt, progress, progressAt, movedAt, gpuBusy, stallMs, doing, typicalMs, etaS, owners, feature?, modelName?, op?, kind? }`: `doing` is what its ComfyUI runs now (`{ node, nodeClass, nodeTitle, value?, max?, pass? }`, or null), for the owner only; `movedAt` is when the worker last saw the job move, on the site clock, or null from an older worker; `gpuBusy` is its GPU use from 0 to 100, or null; past `stallMs` without a move the worker gives the job back; `etaS` is more than 0 or null, never 0 for a running job) and `lastEvent: { at, kind, event, words }` or null || `POST /api/admin/workers` | `{ name, pool? }` | 201 `{ id, token }`: the worker's token, once || `POST /api/admin/workers/{id}/update` | none | `{ worker }`: its next beat answer asks it to update now. It looks for new code at once and restarts on it after the job in hand (a person's job is never cut off). Each worker in `GET /api/admin/workers` has `update`: `state` (`current`, `updating` while behind the site's version for under 3 minutes, `behind` after), `since`, `behindMs`, `site`, `worker`, `commit` (first 12 hex), `peopleHeld`, `peopleWaiting`, `askedAt`, `words` and `needsOwner` |-| `PATCH /api/admin/workers/{id}` | any of `paused`, `pauseNow`, `drain`, `autoResume`, `hours`, `allow`, `claimAfterMs`, `switchAfterMs`, `rotate` (needs `workers:tokens`), `revoke` | `{ worker, token? }`: a new worker token after `rotate`, once |+| `PATCH /api/admin/workers/{id}` | any of `paused`, `pauseNow`, `drain`, `autoResume`, `hours`, `allow`, `claimAfterMs`, `switchAfterMs`, `pickOrder` (a whole number from -100 to 100, 0 by default: a free worker with a higher one gets first pick, [gpu-workers.md](gpu-workers.md#who-picks-first)), `rotate` (needs `workers:tokens`), `revoke` | `{ worker, token? }`: a new worker token after `rotate`, once. 400 with the reason for a value that isn't allowed || `GET /api/admin/workers/jobs` | `before`, `limit` (1 to 200, 50), `worker`, `generation` | `{ items, next }`: the workers' log, newest first. Each item: `{ id, at, event, workerId, workerName, taskId, generationId, principal, lane, execMs, device }` ([gpu-workers.md](gpu-workers.md)) || `GET /api/admin/workers/events` | `worker`, `kinds` (a comma list of `state`, `job`, `stage`, `looking`, `admin`, `version`, `log`; all when not given), `before`, `after`, `generation`, `limit` (1 to 500, 100) | `{ items, next, latest }`: the workers' timeline, newest first. Each item: `{ id, at, workerId, workerName, kind, event, words, taskId, generationId, lane, laneLabel, state, detail }`. `next` pages back (as `before`); `latest` is the newest row id (as `after`, for new rows only) ([gpu-workers.md](gpu-workers.md)) || `GET /api/admin/audit` | `before` (the last page's `next`), `limit` (1 to 200, default 50), `actor` (`owner`, `token` or `system`), `token` (a token id), `action`, `changes=1` (changes only: no reads, file views or refusals) | `{ items, next }` |diff --git a/docs/gpu-workers.md b/docs/gpu-workers.mdindex 4b9a453f..abee2293 100644--- a/docs/gpu-workers.md+++ b/docs/gpu-workers.md@@ -436,16 +436,19 @@ A worker gets a job only when all of these are true, all in one SQLite transacti30 seconds;- its worker program speaks protocol 2 or later (an older one takes nothing until it is updated);- 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. The files are the workflow's own, or+- it has the workflow's files and packs (from its inventory) and enough memory. The files are the workflow's own, orevery file of one of its model variants (see "Model variants" below), and the VRAM is that of the files it would run.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);+ about 31.8 GiB). A workflow with a streaming need also runs on a smaller card with enough system RAM (see+ "Streaming from RAM" below);- it verified every run-time file the job loads (see "Run-time files" below);- the retry rule allows it: a worker that lost or failed the job gets it again only when no other worker that can runthe job was heard from in the last 10 minutes;- near the end of its hours, the job's estimate fits before the window closes;- it holds no other job. A worker runs one job at a time: while it holds one, a claim gives it that job again when- it lost track of it, and nothing new.+ it lost track of it, and nothing new;+- no free worker with a higher pick order would take the job next, for the first-pick grace (see "Who picks first"+ below).Jobs go by class (`paid`, then `free`, then `owner`), then by the lowest `rank_at` (then the oldest). With thepick allowance at 0 (the default), that is the whole rule. Above 0, a worker may take one of the owner's own jobs in its@@ -465,10 +468,13 @@ in that class came.| `ownerWaitLimitS` | How long the owner's own jobs may wait before a worker first takes them, in seconds. `null`: no limit | `null` || `fairShare` | Each class goes round its accounts (above). Off: strict order | `false` || `pickAllowanceMs` | How long a job in a worker's warm lane may go ahead of an older one (above). 0: strict order | `0` |+| `firstPickGraceMs` | How long a job may be left for a free worker with a higher pick order before another worker takes it (see "Who picks first" below). 0: no job is left for anyone | `20000` (20 seconds) || `pausedBudgetS` | How long, in all, a run that has started may spend back in line while its worker steps aside, and still be inside the deadline its hold asks for ([billing-hook.md](billing-hook.md)). A run past it still delivers its result | `7200` (2 hours) |A worker's run limit for one attempt is 3 times the lane's 90th percentile on that worker plus its model load, at-least 10 minutes and never past the lane's run ceiling. With no measured run in the lane yet, it is the ceiling.+least 10 minutes and never past the lane's run ceiling. With no measured run in the lane yet, it is the ceiling. Each+worker's limits come from its own measured runs, so a slower worker gets longer limits than a faster one in the same+lane.If a worker stops answering for 2 minutes, its ComfyUI is down for 2 minutes, or the job is still sending its files15 minutes after the worker claimed it (or after its ComfyUI lost the job and the worker sent it again), its job goes@@ -519,6 +525,33 @@ in words: "Took a … run", "Sent back in line: went silent", "Delivered after 4`log` (its own log lines, from its beat). Log lines are kept 7 days, the rest 30 days. The owner reads it at`GET /api/admin/workers/events` ([admin-api.md](admin-api.md)).+### Who picks first++Each worker has a pick order, a whole number (0 by default; the owner sets it in Settings →+Workers, "Picks first", or with `pickOrder` on `PATCH /api/admin/workers/<id>`). A worker with a higher pick order+gets the first pick of every job it can run while it is free. When a worker claims, the studio looks at each worker+with a higher pick order that is free now:++- heard from in the last 30 seconds, paused neither on the website nor on its PC, not draining, inside its hours;+- holding no job in its GPU's slot, and held back by nothing its beat says (`holding`: starting its ComfyUI, local work+ first, an update…).++For each, the studio works out the job that worker's own claim would take next, by the same rules as any claim (its+pool, its allowed lanes after their delays, its files, packs and memory, the retry rule, its hours and its mode). The+claiming worker leaves that job to it, and takes its own next best job, or nothing. It leaves the job only while the+job has been there for that worker for less than the first-pick grace (`firstPickGraceMs`, 20 seconds by default):+from when the job came, plus that worker's claim delay and its lane's delay. After the grace, any worker takes it, so+no job waits longer than the grace for a worker that picks first. A job back in line after an attempt is past its grace+already. When the preferred worker is off, paused, busy, outside its hours or can't run the job, the other workers+take the job at once, with no added wait. (A lane's delay is different: it always waits, whether or not another worker+is there.)++A person's run left this way doesn't count for the other worker's `claimableNow`, so local work on its PC makes no+room for it. Workers with a higher pick order are looked at from the highest down; one never leaves a job for a worker+with a lower or equal pick order. The claim's words say when it left a job: "Asked for work: 1 waiting, 1 left for a+worker that picks first". With every pick order 0, or a grace of 0, the line is as it was. It all happens inside the+claim's one SQLite transaction; with no worker above the claiming one, it costs one query.+### Who goes firstThe owner can change who the workers serve first, through the admin API ([admin-api.md](admin-api.md), scope@@ -660,6 +693,29 @@ A person's own GPU counts a workflow as ready when its own files are there, or ethen loads the variant's files when the GPU check found them and not the workflow's own, so nobody downloads a file ofthe same model in another format.+### Streaming from RAM++A workflow's VRAM need is for every model weight on the card. ComfyUI can keep part of the weights in system RAM and+stream them to the card at each step (dynamic VRAM loading): slower, but a smaller card runs it. A workflow may have a+streaming need, `{ vramGb, ramGb }` (`workflows/comfyui/stream-needs.json`, built into `requirements.json`;+[adding-a-model.md](adding-a-model.md#streaming-from-ram) says how to add one).++- **Which workers qualify.** A worker has the memory for a workflow when its VRAM covers the workflow's VRAM need (as+ always), or when the workflow has a streaming need and the worker's VRAM covers the need's `vramGb` and its RAM covers+ the need's `ramGb`. Both have the same 3% allowance as the VRAM need: a PC with 32 GB of RAM reports about 31.9 GiB.+ The RAM is the one its ComfyUI reports (`ramBytes` in its facts, once its ComfyUI has started). A worker whose RAM+ isn't known yet, or whose ComfyUI runs with dynamic VRAM off (`--disable-dynamic-vram`, `--highvram`, `--gpu-only`,+ `--novram` or `--cpu`; `dynamicVramOff` in its facts), qualifies on VRAM only.+- **The same rule everywhere.** The claim, the check that some worker could ever run a run before it is queued, and the+ choice of a model variant's files all read it (`memoryFit` and `streamFits` in `src/lib/lanes.ts`). A variant's own+ VRAM need counts as the VRAM need; the workflow's streaming need applies to whichever file set the worker runs.+- **Times.** A worker that streams runs slower. Its run limits come from its own measured runs in the lane (above), so+ they stay right for it.++A person's own GPU (Fuobe Connect) reads the same rule from its check: a card short of the VRAM need, whose VRAM and RAM+cover the streaming need with dynamic VRAM on, is ready, and its line says "Ready · uses system RAM, slower". A check+that didn't read the RAM counts the VRAM need only.+### What the worker checks itselfBefore its ComfyUI gets a graph, the worker checks all of these. The studio cannot change these checks. To add a model,@@ -1124,7 +1180,7 @@ Each worker counts against its own rate limits, so three workers that beat every`receivedAt` (null: none).- `GET /api/admin/workers/events`: the workers' timeline (above), newest first, by worker, kinds and run, in pages.- `PATCH /api/admin/workers/<id>`: `{ paused, pauseNow, drain, autoResume, hours, allow, claimAfterMs, switchAfterMs,- rotate, revoke }`. Hours are `{ "always": true }` or `{ "tz": "Asia/Kolkata", "days": { "mon": [["01:00", "09:00"]] } }`.+ pickOrder, rotate, revoke }`. `pickOrder` is a whole number from -100 to 100 ("Who picks first" above). Hours are `{ "always": true }` or `{ "tz": "Asia/Kolkata", "days": { "mon": [["01:00", "09:00"]] } }`.A window can go past midnight.- `GET /api/admin/queue`: the jobs that wait in each lane, the oldest job, the estimate, and which workers have thelane warm; and what the workers do now: `running` (each job a worker runs: its run, model, worker, step, progress,@@ -1150,8 +1206,12 @@ routes.`tests/worker-runner.test.ts`, `tests/worker-recovery.test.ts`, `tests/worker-parts.test.ts`,`tests/worker-turns.test.ts`, `tests/worker-turns-run.test.ts`, `tests/worker-update.test.ts`, `tests/cpu-slot.test.ts`,`tests/worker-cpu-slot.test.ts`, `tests/fuobe-connect-nodes.test.ts`, `tests/model-variants.test.ts`,- `tests/pool-model-variants.test.ts`). The model variant tests check the build's refusals, which files a worker gets- by its card and its files, the swapped graph and ticket, and an older worker program. The CPU slot tests run a CPU task while a GPU job runs, refuse a GLB that names+ `tests/pool-model-variants.test.ts`, `tests/stream-needs.test.ts`, `tests/pool-first-pick.test.ts`). The model variant+ tests check the build's refusals, which files a worker gets by its card and its files, the swapped graph and ticket,+ and an older worker program. The streaming tests check the build's refusals, the memory rule (VRAM only, VRAM and+ RAM, unknown RAM, dynamic VRAM off, the 3% allowance) on the claim and on a person's own GPU. The first-pick tests+ check that a job is left for a free worker that picks first, and taken at once when that worker is busy, paused,+ silent, outside its hours or can't run it, or after the grace. The CPU slot tests run a CPU task while a GPU job runs, refuse a GLB that namesan outside file on the worker, bring a turntable back with its GLB, check that an account's picture reaches itsComfyUI with no EXIF, and drop a preview over 64 KB. The turn tests use a fake port table, fake GPUcounters and a fake lock file. With only local ComfyUI work on the GPU, the worker writes `siteWaiting` and claims