Skip to content

About

Free text-to-video: a model-agnostic harness that orchestrates open ComfyUI video models (MiniMax H3 Turbo) across free GPU backends, with cost guardrails that keep the free tiers free.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Free Text-to-Video

A model-agnostic harness for running open ComfyUI video models on free GPU tiers — with a local control panel and a cost-safety layer so the "free" actually holds.

Reference model pack: MiniMax H3 Turbo (joint audio + video, 4-step).

The interesting part isn't the model. It's everything around it:

  • a transport-agnostic pipeline that runs unchanged on two very different backends,
  • a dual-backend orchestrator (--backend lightning | modal) with a live local UI,
  • and a cost-safety layer that keeps an $0.09 clip from quietly turning into a $50 bill.

Why "free" needs tooling

Combining the free tiers genuinely gets you hundreds of clips a month — but only if you treat the free credits as a budget. The failure mode is boring and expensive: an orphaned ComfyUI server counts as activity, so a studio never auto-sleeps and keeps an A100 billing at $2.19/hr. At that rate, ~14 idle hours burn Modal's entire monthly grant.

Every guardrail in this repo exists for that reason.


What "free" really means

Measured from this project's own ledger (h3gen-costs.jsonl). Baseline job: 5 s · 768×448 · 4 steps (turbo).

Per-clip cost

Job Lightning (A100) Modal (A100-80GB)
5 s · 4 steps (turbo) ~1.0 credit ~$0.05–0.10
10 s · 4 steps ~1.3 credits ~$0.16
5 s · 8 steps ~1.3 credits ~$0.16

(Modal is time-billed, so the number moves with cold vs warm: a warm container renders in ~$0.05, a cold one — boot + weight load — lands nearer ~$0.09.)

Monthly budget

Grant Resets 5 s clips / mo 10 s clips / mo
Lightning free tier 1st of month, non-cumulative ~14 ~11
Modal Starter ($30) monthly ~290–500 ~190
Combined ~300–500 ~200

The catches (say these out loud)

  • Non-cumulative. Unused free credits do not roll over. Use them or lose them.
  • Only free if the GPU stops. Idle billing is the whole problem; that's what the preflight, orphan guard, and stop-on-idle logic are for.
  • Grants and limits change. Both are Starter/free-plan offerings, not contracts.
  • These numbers are 768×448. Higher resolution or more steps scale cost roughly with sampling work — 768p+/8-step clips cost multiples of the table above.
  • Lightning is the slow pool (~11 min/clip, plus manual credit top-ups and studio cycling); Modal is the fast pool (~2 min/clip). The harness picks per render.

Headline result: same job, two backends

Lightning AI Modal
Ready state cold studio boot (~8 min fixed) container + volume (~24 s warm)
5 s render, end-to-end ~11 min ~2 min 07 s
Cost ~1.0 credit ~$0.05 (render)

Modal cold-start, measured (modal_spike.py):

Step Time Note
Volume read (41 GiB) 50.3 s 0.88 GB/s — storage-bound
Host → VRAM 46.0 s ~0.9 GB/s — not PCIe-bound
ComfyUI boot 14.0 s to /system_stats

The lesson: for giant weights, the bottleneck is disk → VRAM throughput, not PCIe. That's why a persistent Modal volume + a warm container beats a fresh Lightning studio by ~5×.


Architecture

                    ┌─────────────────────────────┐
   prompt / images  │  webapp.py  (FastAPI, :8777) │  live log, cost meter, gallery
   ───────────────► │  static/    (HTML/CSS/JS)    │
                    └──────────────┬──────────────┘
                                   │  spawns
                                   ▼
                    ┌─────────────────────────────┐
                    │  h3gen.py  (orchestrator)    │  --backend lightning | modal
                    │  preflight · ledger · guard  │
                    └───────┬──────────────┬───────┘
             lightning      │              │      modal
                    ┌───────▼──────┐ ┌─────▼────────┐
                    │ Lightning    │ │ modal_app.py │  A100-80GB, volume-mounted
                    │ Studio (A100)│ │ @app.cls     │  weights staged once
                    └───────┬──────┘ └─────┬────────┘
                            └──────┬───────┘
                                   ▼
                    ┌─────────────────────────────┐
                    │  h3_pipeline.py  (model pack)│  transport-agnostic:
                    │  ComfyUI graph + frame math  │  zero backend imports
                    └─────────────────────────────┘
  • h3_pipeline.py knows nothing about Lightning or Modal — only ROOT (overridable via H3_ROOT).
  • h3gen.py and modal_app.py are two thin transports over that same pipeline.
  • webapp.py is transport-agnostic too: it just streams whichever backend h3gen runs.

Quickstart

Modal (fast path)

uv tool install modal
modal setup                                     # browser auth

# first run stages ~41 GiB of weights onto the volume (one time)
modal run modal_app.py --warm

# render — note: NO `--` separator (Modal 1.6.1 passes flags through)
modal run modal_app.py --prompt "a hummingbird hovering by a red flower, slow motion" --out bird

Lightning (second pool)

python h3gen.py --prompt "…" --duration 5          # cold A100 studio
python h3gen.py --credits-only                     # teamspace + org balances
python h3gen.py --top-up 15                        # move org pool → teamspace

Local control panel

~/.local/share/uv/tools/lightning-sdk/bin/python webapp.py
# → http://127.0.0.1:8777

Toggle Lightning | Modal per render. The estimate switches between credits and USD, and Lightning-only controls dim out when Modal is selected.


Model packs (the model-agnostic seam)

The orchestration, both backends, and the entire UI are model-agnostic. The only file that knows the model is h3_pipeline.py, which combines:

  1. a ComfyUI workflow graph (build_workflow),
  2. the weight manifest (which files, from where),
  3. a little frame math (H3 needs length = 17k + 5, dims divisible by 32, min 5 s).

Making it a true multi-model tool is one refactor away — split that file into a pack:

packs/<name>/
  workflow.json     # the ComfyUI graph
  models.json       # HF repo + files + sizes
  params.json       # generic params → node inputs
  frame_math.py     # optional

The harness already speaks the generic contract: prompt, width, height, duration, steps, seed, first_frame, last_frame, turbo_lora, lora_strength. H3 is just pack #1.


Repo layout

File Role
h3gen.py Orchestrator: credits, cost model, ledger, orphan guard, --backend
h3_pipeline.py Model pack: ComfyUI graph + frame math (transport-agnostic)
modal_app.py Modal backend: image, volume, @app.cls, render/batch
modal_spike.py Cold-start measurement harness (the numbers above)
webapp.py Local FastAPI control panel
static/ Panel front-end (no build step)
minimax_h3_turbo_kaggle.ipynb Canonical notebook reference for the pipeline

Cost guardrails

  • Pre-flight estimate — predicts credits/minutes before booting a GPU.
  • Orphan guard — a pidfile + ps check so a lost job can't keep billing untracked.
  • Stop-on-idle — SIGINT to the process group runs the pipeline's finally, which stops the studio. A hard SIGKILL fallback exists for emergencies.
  • Ledger — every run logs estimated vs actual so the cost model stays calibrated.

Roadmap

  • Extract the model-pack contract (above) so non-H3 models plug in.
  • Per-user auth on the panel (it's localhost-only today for a reason).
  • CPU-memory snapshots on Modal (the right optimization once weight-load dominates).

Notes before publishing

  • Do not commit weights or secrets. The 5 H3 weight files (~41 GiB) come from Comfy-Org/MiniMax-H3 and are downloaded at runtime. Keep ~/.modal.toml, HF tokens, and any Lightning keys out of the repo.
  • Licensing: ComfyUI is GPL-3.0; check the MiniMax-H3 weight license and attribute the Kaggle notebook you started from.
  • ComfyUI is pinned (651ca296a73cd21c12a57eb8741d52e40dc6528f); huggingface-hub is pinned >=1.31.0,<2.0 (2.x breaks ComfyUI's CLIPTokenizer).

License

MIT — see LICENSE. Third-party components (ComfyUI, MiniMax H3 weights, the Lightning SDK, Modal) are not included and keep their own licenses — see NOTICE.md.

About

Free text-to-video: a model-agnostic harness that orchestrates open ComfyUI video models (MiniMax H3 Turbo) across free GPU backends, with cost guardrails that keep the free tiers free.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages