Files
shinyobjectz 3725537f35 sdk/cloud: renders on a GPU or a CPU from one image, render jobs, and a CPU box that hands its renders to a GPU worker (docs/cloud.feature CL13-CL15)
- The image is Node 24 on Debian trixie with glvnd and X11's libraries (libxext6 libx11-6 libgl1 libegl1), without
  which NVIDIA's Vulkan driver (mounted by the container runtime) doesn't load or gives no vkCreateInstance (driver
  610.57 on Modal's T4, A10G and A10). The entrypoint opens NVIDIA's driver when the host passed a GPU in, else Mesa's;
  WGPU_BACKEND=vulkan, and on the CPU EGL's vendors are hidden, since NVIDIA's EGL would hand wgpu an OpenGL adapter
  over llvmpipe. RAEA_CLOUD_DEVICE=gpu fails at start on no GPU; /v1/health says the device.
- /v1/jobs takes a project as a tar and gives back what the render made (CL14); deploy/modal/raea_cloud.py runs it on
  a Modal GPU list (L4, else A10G, else T4), one container that sleeps after five idle minutes.
- RAEA_CLOUD_GPU_URL on a CPU box sends raea render to the worker and lands its files back (CL15, image/raea.sh and
  server/offload.ts); deploy/k8s.gpu.yaml is such a worker.
- test/smoke.sh: worker and box, ten checks, all pass on 0.1.1-rc3. On Modal, test/gpu/edit.tsx (576 lit blocks,
  1080p, 90 frames): T4 156 s against llvmpipe on the same machine's 8 cores 203 s; a box on a Mac handed it to an A10
  (119 s) and the MP4 came back.
2026-11-10 21:52:21 -08:00

58 lines
2.7 KiB
Python

# raea cloud on Modal (docs/cloud.feature CL14): the image from image/Dockerfile, built by Modal, on an NVIDIA GPU that
# starts on the first request and stops when idle. From sdk/cloud:
#
# modal secret create raea-cloud RAEA_CLOUD_TOKEN=$(openssl rand -hex 32)
# modal deploy deploy/modal/raea_cloud.py # an L4, else an A10G, else a T4
# RAEA_CLOUD_GPU=L40S modal deploy deploy/modal/raea_cloud.py # one kind: T4, A10G, L40S, A100, H100, ... (Modal's)
# RAEA_CLOUD_GPU=none modal deploy deploy/modal/raea_cloud.py # CPU only, app raea-cloud-cpu
#
# The URL it prints is the server: GET /v1/health says which GPU raea renders on. Use it as a render worker for a CPU
# box (RAEA_CLOUD_GPU_URL, RAEA_CLOUD_GPU_TOKEN there) or on its own, agent and all.
#
# - A comma list is a fallback order: Modal starts the first kind it has free (L4s ran out for ten minutes on 11-10).
# - One container takes every request (max_containers=1): a render job is followed on the container that runs it.
# - It stops after RAEA_CLOUD_IDLE seconds without a request (300), and a request wakes it: about a minute cold.
# - Its home folder is the container's own, so it starts clean each time unless RAEA_CLOUD_STATE (in the secret) keeps
# it in a bucket; a render worker needs nothing kept.
# - Python because Modal apps are Python.
import os
import subprocess
import modal
HERE = os.path.dirname(os.path.abspath(__file__))
CLOUD = os.path.dirname(os.path.dirname(HERE))
GPU = os.environ.get("RAEA_CLOUD_GPU", "L4,A10G,T4")
GPU = None if GPU.lower() in ("", "none", "cpu") else [g.strip() for g in GPU.split(",") if g.strip()]
image = modal.Image.from_dockerfile(
os.path.join(CLOUD, "image", "Dockerfile"),
context_dir=CLOUD,
build_args={
"RAEA_VERSION": os.environ.get("RAEA_VERSION", "0.1.1"),
"AGENTS": os.environ.get("RAEA_CLOUD_AGENTS", "kimi-code"),
},
# Modal runs the function in Python, which the image doesn't have
add_python="3.12",
).entrypoint([])
app = modal.App(os.environ.get("RAEA_CLOUD_APP", "raea-cloud" if GPU else "raea-cloud-cpu"), image=image)
@app.function(
gpu=GPU,
cpu=float(os.environ.get("RAEA_CLOUD_CPU", 8)),
memory=int(os.environ.get("RAEA_CLOUD_MEMORY", 16384)),
secrets=[modal.Secret.from_name(os.environ.get("RAEA_CLOUD_SECRET", "raea-cloud"))],
scaledown_window=int(os.environ.get("RAEA_CLOUD_IDLE", 300)),
timeout=24 * 3600,
max_containers=1,
)
@modal.concurrent(max_inputs=64)
@modal.web_server(8080, startup_timeout=600)
def server():
# gpu: a GPU that doesn't open is an error at start, never a quiet fall back to the CPU
env = {**os.environ, "RAEA_CLOUD_DEVICE": "gpu" if GPU else "cpu"}
subprocess.Popen(["/opt/raea-cloud/image/entrypoint.sh"], env=env)