Files
raea/sdk/cloud/test/farm.ts
shinyobjectz 775469dbac raea cloud render farm: one render split across Modal GPUs, a bench of every GPU kind, and an agent box on a Fly Sprite
deploy/modal/farm.py (app raea-farm) serves sdk/cloud's jobs protocol on many GPUs. A raea render to a video or a folder is probed on one GPU (frame 0 and the manifest), timed on 8 frames, then split into contiguous runs on as many GPUs as pay for their start (a start at most a fifth of the work, farm_plan.gpus_for), with an optional price ceiling (max_usd, exit 3). Video runs are H.264 parts that the coordinator joins by stream copy while it renders the sound on its CPU; Blender scenes (Cycles on OptiX) split the same way and encode their parts on their own GPUs. raea asks for T4, A10, then L4 (its frames are bound by the CPU); Blender asks for L40S, RTX PRO 6000, then L4 (the most samples a dollar). GPUs render without the clipping check, with 4 cores and 16 GiB, a 2 s idle window (at 60 s a job billed several times its GPU work), shader and kernel caches on the volume, and raea's models from the raea-models volume (deploy/modal/models.sh). Each job's log ends with its bill per container.

bench/gpus.py runs raea (edit.tsx, Solari, clip check on and off) and Blender's Open Data benchmark on every Modal GPU kind at once; bench/results holds the 11-17 run and bench/report.py prints its tables. deploy/sprites/box.sh puts raea, the ACP agents and the server on a Sprite with its renders sent to the farm; it reads the org only from ~/.config/raea-cloud/sprites.env and refuses orgs listed under private/cloud. The client and offload.ts pass gpus, gpu and max_usd.

Checked: test/farm_plan.py (7, stand-in GPUs) passes; test/farm.ts against the deployed farm returned edit.tsx as 90 frames at 1080p in 70 s on a T4, and Blender's classroom as 20 frames at 1080p and 256 samples on up to 10 GPUs (frames 3.1x faster than on one).
2026-11-17 19:52:34 -08:00

52 lines
2.8 KiB
TypeScript

// raea's render farm, live (docs/cloud-render.feature CR9): a job sent the way a CPU box sends one, timed, and its
// video checked. RAEA_CLOUD_GPU_URL and RAEA_CLOUD_GPU_TOKEN name the farm (~/.config/raea-cloud/farm.env):
//
// node test/farm.ts raea [GPUS] test/gpu/edit.tsx to out/edit.mp4
// node test/farm.ts blender DIR FILE.blend FRAMES [GPUS] [SAMPLES]
// a Blender scene to out/render.mp4, frames A-B
import { spawnSync } from "node:child_process"
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"
import os from "node:os"
import path from "node:path"
import { RaeaCloud } from "../src/index.ts"
const [kind = "raea", ...rest] = process.argv.slice(2)
const url = process.env.RAEA_CLOUD_GPU_URL
const token = process.env.RAEA_CLOUD_GPU_TOKEN
if (!url || !token) throw new Error("set RAEA_CLOUD_GPU_URL and RAEA_CLOUD_GPU_TOKEN (the farm's)")
const here = path.dirname(new URL(import.meta.url).pathname)
const [dir, args, gpus] =
kind === "blender"
? [rest[0], ["blender", rest[1], "-o", "out/render.mp4", "--frames", rest[2], ...(rest[4] ? ["--samples", rest[4]] : [])], rest[3]]
: [path.join(here, "gpu"), ["render", "edit.tsx", "-o", "out/edit.mp4"], rest[0]]
const tmp = mkdtempSync(path.join(os.tmpdir(), "raea-farm-test-"))
try {
// a Mac's tar: gzip, and no AppleDouble files
const sent = path.join(tmp, "in.tgz")
const pack = spawnSync("tar", ["-czf", sent, "--no-mac-metadata", "-C", dir, "."], { env: { ...process.env, COPYFILE_DISABLE: "1" }, encoding: "utf8" })
if (pack.status) throw new Error(`the folder didn't pack: ${pack.stderr}`)
const folder = new Uint8Array(readFileSync(sent))
const cloud = new RaeaCloud({ url, token })
const t0 = performance.now()
const at = () => `${((performance.now() - t0) / 1000).toFixed(1).padStart(6)} s`
console.log(`${at()} ${(folder.length / 1e6).toFixed(1)} MB to ${new URL(url).host}: raea ${args.join(" ")}`)
const { exit, files } = await cloud.job(args, folder, {
as: "gz",
farm: gpus ? { gpus: Number(gpus) } : {},
onOutput: (t) => t.split("\n").filter(Boolean).forEach((l) => console.log(`${at()} ${l}`)),
})
const back = path.join(tmp, "out.tgz")
writeFileSync(back, files)
spawnSync("tar", ["-xzf", back, "-C", tmp])
const video = path.join(tmp, args[args.indexOf("-o") + 1])
const probe = spawnSync("ffprobe", ["-v", "error", "-count_frames", "-select_streams", "v", "-show_entries", "stream=nb_read_frames,width,height", "-of", "csv=p=0", video], { encoding: "utf8" })
console.log(`${at()} exit ${exit}; ${path.basename(video)}: ${probe.stdout.trim() || probe.stderr.trim()} (width,height,frames)`)
const keep = process.env.RAEA_FARM_KEEP
if (keep) spawnSync("cp", [video, keep])
process.exitCode = exit
} finally {
rmSync(tmp, { recursive: true, force: true })
}