Colab Media Pipeline
Overview
Separate frozen rendering engines (render_images.py, render_videos.py) from dynamic storyboard inputs (tasks.json), and drive Colab through the bundled scripts/run_colab.py orchestrator.
Core rule: Once a project's engine scripts are frozen, agents ONLY edit tasks.json. Never rewrite model loading, quantization, aspect ratio, or style suffixes per run.
Agent-Driven Intake & Confirmation Checkpoints
The user should not need to memorize commands, flags, or setup order. Drive the workflow proactively:
- Auto-check project state first: Inspect
<project-dir>forrender_images.py,render_videos.py,requirements.txt,tasks.json, and runcolab sessions. - Confirm missing prerequisites before acting (ask concisely in one message, never guess):
- Engine missing or
MODEL_IDstillREPLACE_WITH_YOUR_*: Ask which image/video model, aspect ratio, and visual style to lock, then copy./templates/and freeze after a 1-shot smoke test. - Gated model needs
HF_TOKEN(e.g.,black-forest-labs/FLUX.1-*) andHF_TOKENis not set in the local environment: remind the user thatcolabCLI cannot read Colab Web UI Secrets — they must either accept the Hugging Face repo terms and provide a local ReadHF_TOKEN(auto-forwarded byrun_colab.pyor passed via--env HF_TOKEN=..., never hardcoded), or switch to an ungated public model (e.g.,SG161222/RealVisXL_V5.0) before provisioning a VM. - Stray active Colab session found in
colab sessions: Ask whether to stop or reuse it before starting a new VM. - Before spending Compute Units (CU): Confirm the shot count, mode (
images/videos), and GPU choice (l4default vsa100burst) if the user hasn't already specified them.
- Engine missing or
- Execute end-to-end once confirmed: Generate/update
tasks.json, runscripts/run_colab.py, verifyoutputs/+.meta.json, and confirmcolab sessionsis clean.
Project Layout
<project-dir>/
├── render_images.py # FROZEN: text-to-image engine (aspect ratio, steps, style suffix, L4/A100 VRAM)
├── render_image_edit.py # FROZEN: reference image edit / subject-swap engine (single-image & dual-ref)
├── render_videos.py # FROZEN: I2V model, fps, duration, VAE tiling, L4/A100 VRAM profile
├── requirements.txt # FROZEN: extra packages installed via `colab install -r`
├── tasks.json # DYNAMIC: the ONLY file agents edit per storyboard run
└── outputs/ # Pulled results (.png / .mp4) + .meta.json (seed & prompt log)
Starter templates live in ./templates/ (render_images.py, render_image_edit.py, render_videos.py, tasks.example.json, requirements.example.txt). Match the template to the task type:
- Text-to-image:
render_images.py - Reference image edit / person swap / character consistency:
render_image_edit.py(invoke with--mode images --script render_image_edit.py) - Image-to-video / reference video:
render_videos.py(or custom--script render_v2v.py)
Standard Execution Flow
- Inspect active sessions first: Run
colab sessions. Stop any forgotten idle session (colab stop -s <name>) before provisioning a new GPU. - Edit ONLY
tasks.json: Write scene-specificidandprompt(plus optionalseed,overwrite, or local reference paths:image,ref_image,ref_imageslist,start_frame,end_frame,video,ref_video,ref_videoslist,audio).run_colab.pyautomatically uploads any referenced local files to/content/<relative-path>. Do not repeat global style suffixes, aspect ratios, or negative prompts already locked in the engine. - Run via the orchestrator (
./scripts/run_colab.py):Use# Default: L4 (24GB) — fast, reliable, rarely 503s python <skill-dir>/scripts/run_colab.py --project-dir . --mode images --gpu l4 # Burst: A100 (40GB, never --high-mem) with 503 retry + automatic L4 fallback python <skill-dir>/scripts/run_colab.py --project-dir . --mode images --gpu a100 --retries 6 --retry-interval 25 # Reference image edit / subject swap (auto-uploads image / ref_image / ref_images) python <skill-dir>/scripts/run_colab.py --project-dir . --mode images --script render_image_edit.py --gpu l4 # Video / reference-driven pass (auto-uploads referenced local images/videos; use --script for custom engines like render_v2v.py) python <skill-dir>/scripts/run_colab.py --project-dir . --mode videos --gpu l4 # Pass secrets safely without writing to disk python <skill-dir>/scripts/run_colab.py --project-dir . --mode images --env HF_TOKEN=...--dry-runto preview exact commands. Use--keep/--reuse-sessiononly when iterating rapidly in the same session, and always runcolab stop -s <name>when done. - Verify locally: Confirm expected files and
.meta.jsonexist inoutputs/with non-zero size, and confirmcolab sessionsshows no stray running VM.
GPU Strategy (L4 Default, A100 Burst)
- Default to
--gpu l4(24GB): Provisions in seconds and rarely hits 503. Engines auto-detect VRAM (< 35GB) and enable quantization + CPU offload. - A100 bursts use standard 40GB (
--gpu A100without--high-mem): 80GB high-RAM pools 503 far more often. Retry every 20–30s (5–8 attempts) on503 Service Unavailable, then fall back toL4. - Never fall back to T4 for modern FLUX/Wan pipelines (OOM risk), and never request
--high-memon A100 in automated runs.
Colab CLI Gotchas (Hard Rules)
| Trap | Required Behavior |
|---|---|
colab exec default timeout is 30s | Always pass --timeout 0 for installs/model loads/rendering (run_colab.py enforces this). |
colab list does not exist | Use colab sessions. |
colab stop <name> fails | Always pass -s <name> (colab stop -s <name>). |
colab auth / colab drivemount / colab repl | Never call from an agent — they require an interactive TTY and hang. |
Colab Web UI Secrets (HF_TOKEN) | Not accessible from colab CLI (Secrets can only be fetched when running from the Colab UI). Pass via local HF_TOKEN env var or --env HF_TOKEN=.... |
colab upload / colab download | Always pass both local and remote /content/... paths. |
Running -f engine.py in Jupyter kernel | Do not upload engine.py manually (exec -f streams it). Engine scripts read env vars (PIPELINE_TASKS, PIPELINE_OUTPUT_DIR), not argparse on kernel sys.argv. |
| Session left running after error | Always wrap execution in try/finally: colab stop -s <name> (handled by run_colab.py). |
Red Flags — STOP and Fix
- Editing
render_images.pyorrender_videos.pyto change a prompt or "quick-fix" a storyboard run. - Running
colab exec -f ...without--timeout 0. - Putting
16:9,anamorphic lens, ornegative_promptinto everytasks.jsonentry when the engine locks style. - Leaving a Colab session running after a failed command.