Production utilities for Stable Diffusion and ComfyUI pipelines.
Small, sharp tools extracted from a working VFX pipeline: VRAM-aware batch planning, latent-space helpers, and ComfyUI workflow graph manipulation — the glue code everyone rewrites and nobody publishes.
Estimates peak VRAM for a (resolution, batch, dtype, model) combination and picks the largest batch size that fits, with headroom for the VAE decode spike — which is where most "it worked in testing" render jobs actually die.
from dpu.vram import plan_batches
plan = plan_batches(
width=1024, height=1024, count=5000,
model="sdxl", dtype="fp16", vram_gb=24,
)
# BatchPlan(batch_size=9, num_batches=556, est_peak_gb=21.0, headroom_gb=3.0)slerp/lerpinterpolation between latents (slerp for noise, lerp for decoded-space blends — mixing these up is the classic mistake)- seed-stable noise generation independent of batch position
- latent → preview decode via the tiny TAESD approximator for cheap progress frames
Load an API-format workflow JSON, retarget nodes by class or title, and submit batches programmatically:
from dpu.comfy import Workflow
wf = Workflow.load("workflows/upscale_pass.json")
wf.set_input("KSampler", "seed", 42)
wf.set_input("CheckpointLoaderSimple", "ckpt_name", "sdxl_lightning_8step.safetensors")
for frame in frames:
wf.set_input("LoadImage", "image", frame)
wf.queue("http://127.0.0.1:8188")pip install -e .Requires Python 3.10+. torch is only needed for the latents module;
vram and comfy are dependency-free by design so they can run on the
farm scheduler, not just the GPU box.
Pipeline utilities should be boring. No wrapper classes around diffusers, no config framework, no plugin system. Functions in, dataclasses out, and every estimate annotated with the measurement it came from.
MIT