
Why MAGI-1's 24-frame causal chunking breaks standard ComfyUI diffusion graphs
Most technical artists arriving at Sand.ai's open-source ecosystem bring muscle memory built on standard bidirectional video diffusion models such as Wan 2.2 or LTX-Video. In a standard ComfyUI video graph, you allocate an empty 3D latent tensor sized to the entire clip duration—say 81 frames at 480×832—attach a single positive/negative CLIP or T5 conditioning tuple, and let a KSampler denoise every frame simultaneously with full bidirectional temporal attention. Every frame attends forward and backward to every other frame at the exact same noise level.
Sand.ai's live Apache 2.0 MAGI-1 architecture (both the 24B base checkpoint and the 4.5B distilled variant) operates on a fundamentally different inference primitive: chunk-wise causal autoregressive diffusion. Instead of denoising an entire five-second block at once, MAGI-1 divides video time into fixed 24-frame chunks (exactly one second at 24fps). Earlier chunks sit at lower noise levels—or fully clean latent states—while newer chunks enter the pipeline at high noise. Attention across chunks is strictly causal: chunk N reads historical spatial-temporal keys and values from chunks 0 through N-1, but historical chunks never attend forward to future frames.
Inside ComfyUI, this architectural shift changes how node execution, caching, and prompting behave. A vanilla KSampler expects a static latent batch and destroys intermediate attention state once sampling finishes. A MAGI-compliant custom sampler node maintains a rolling KV-cache buffer across chunk iterations, accepts a per-chunk prompt array so directors can trigger camera turns or blocking changes every 24 frames, and streams clean latent slices straight into a tiled 3D VAE decoder before allocating the next chunk. Treating MAGI-1 like a monolithic 120-frame diffusion tensor either triggers immediate CUDA out-of-memory crashes or strips away its signature streaming prompt control.
It is equally vital to separate MAGI-1 from the second generation. Sand.ai's August 2026 Apache 2.0 MAGI-2 Preview (114B total / ~6B active Flow MoE) and November 2026 flagship MAGI-2 (480B 8-head Latent MoE, cloud API only as of December 2, 2026) replace MAGI-1's silent 24-frame causal pipeline with a unified single-stream audio-video transformer running natively at 25fps. In ComfyUI today, that means maintaining two distinct local graph topologies—causal chunk streaming for 24 GB MAGI-1 4.5B workstations, and native Flow MoE loaders such as Colnb83/comfyui-magi2-native for 96 GB NVFP4 Preview hardware—while routing 30-second dialogue masters to cloud API nodes.
| Model Family | Weights Status | Temporal Paradigm | ComfyUI Sampler Behavior | Native Audio & Max Length |
|---|---|---|---|---|
| MAGI-1 4.5B Distilled | Live (Apache 2.0) | 24-frame causal autoregressive chunks | Rolling KV-cache; 8 steps, CFG 1.0; per-chunk prompts | Silent only · 4–24s chunk-extended |
| MAGI-1 24B Base | Live (Apache 2.0) | 24-frame causal autoregressive chunks | Rolling KV-cache; 32–64 steps, CFG 7.5; multi-GPU or offload | Silent only · 4–24s chunk-extended |
| MAGI-2 Preview (114B) | Live (Apache 2.0) | Flow MoE (114B total / ~6B active) | Colnb83 native loader; NVFP4 ~71.8 GB on 96 GB GPU | Preview audio-video · 10s hard cap |
| Wan 2.2 (Neutral Benchmark) | Live (Apache 2.0) | Fixed-window bidirectional diffusion | Single monolithic KSampler pass over 81-frame latent | Silent base (shares VAE ecosystem with Preview) |
| MAGI-2 Flagship (480B) | Cloud Live · Open Drop TBA | 8-head Latent MoE (~28B active) | Hybrid ComfyUI API bridge today; 8×H100 FP8 once open | Full 25fps dialogue/foley · 4–30s + 20 Refs |
KV-cache streaming, sliding-window pruning, and chunk memory budgets
The silent killer of long MAGI-1 generations in ComfyUI is unbounded KV-cache accumulation. Because every 24-frame chunk appends new spatial-temporal key and value tensors into transformer attention memory, leaving the cache uncapped causes VRAM usage to climb like a staircase on every second of footage. On a 24 GB RTX 4090 running 4.5B distilled FP8 weights (~5.2 GB transformer footprint after keeping norms and embeddings in BF16), the first 24-frame chunk at 480×832 feels deceptively comfortable around 11–13 GB peak VRAM. By chunk 5 or 6, however, full historical KV retention pushes activation and cache buffers past 22 GB and triggers PyTorch allocator thrashing right before VAE decode.
Production ComfyUI workflows solve this through two deliberate cache controls: sliding-window context truncation and FP8 KV-cache quantization. Keeping the most recent 2 to 3 clean chunks (48 to 72 frames of temporal history) plus an optional anchor keyframe slice preserves camera velocity, lighting exposure, and subject wardrobe while flattening VRAM growth into a steady plateau. Anything older than 3 chunks is evicted from GPU HBM or pinned asynchronously to system DDR5 RAM if your custom node supports host-cache paging.
Equally important is lifecycle separation between the T5-XXL text encoder and the causal video backbone. T5-XXL in BF16 consumes ~9.5 GB of VRAM on its own—or ~5.1 GB in FP8. Your ComfyUI graph must evaluate ALL per-chunk prompt embeddings upfront in a single conditioning pass, immediately offload T5 to system RAM (or clear CUDA cache via a FreeMemory / UnloadModel node), and only then mount the MAGI-1 DiT weights and KV-cache onto the GPU. Keeping T5 resident while sampling chunk 4 wastes nearly a third of an RTX 4090's memory ceiling for zero compute benefit.
- Encode all chunk prompts in one upfront T5 pass, then unload T5 from VRAM before invoking the causal chunk sampler.
- Cap active KV-cache history to 2–3 recent chunks (sliding_window_2_chunks or sliding_window_3_chunks) on 24–32 GB GPUs.
- Enable tiled 3D VAE decoding (tile_size 512, overlap 64, temporal_size 16) so final RGB reconstruction never spikes VRAM after chunk sampling succeeds.
- Avoid pushing MAGI-1 4.5B directly to native 1080p on 24 GB cards; generate clean 480p or 720p base chunks first and apply dedicated spatial upscaling or hand off keyframes to flagship 480B Cloud.
Per-chunk prompt transitions & distilled 4.5B vs. base 24B sampler settings
The genuine creative superpower of MAGI-1's causal chunk architecture is mid-shot direction without hard jump cuts. Because each 24-frame chunk conditions on its own text embedding while inheriting pixel-consistent motion physics from the previous chunk's clean KV state, directors can script evolving camera beats across a 6-to-12 second continuous shot. A classic ComfyUI mistake is writing completely unrelated scene descriptions into adjacent chunks—changing an interior bar into a sunny rooftop between chunk 1 and chunk 2—which forces the causal attention layer to fight its own cached spatial geometry and produces melting smear transitions.
Instead, structure chunk schedules using an invariant anchor prefix plus a delta action clause. Keep lighting temperature, focal length, subject wardrobe, and environment locked identically across every chunk prompt, and mutate only the physical action, gaze shift, or camera move per 24-frame boundary. For example, chunk 0 establishes the locked 50mm tungsten frame and subtle inhale; chunk 1 introduces the hand setting down a glass; chunk 2 initiates a slow push-in toward the doorway; chunk 3 resolves on the silhouette stepping through.
Sampler calibration differs sharply between the two live Apache 2.0 MAGI-1 checkpoints. The 4.5B distilled checkpoint was specifically trained with CFG distillation baked into its weights. Feeding it a traditional CFG of 6.0 or 7.5 doubles compute latency AND blows out skin texture into posterized high-contrast artifacts. Lock distilled 4.5B strictly to cfg = 1.0 with 8 denoising steps per chunk (12 steps maximum for dense foliage or water ripples). By contrast, the 24B base checkpoint requires classic classifier-free guidance—typically cfg = 7.5 across 32 to 64 steps per chunk—delivering visibly tighter object permanence and smoother fluid dynamics at roughly 6× to 10× higher compute cost.
| GPU & Target Model | Resolution / FPS | Steps / CFG | KV-Cache / Precision | Expected Wall-Clock (4s) |
|---|---|---|---|---|
| RTX 4090 24 GB · MAGI-1 4.5B Distilled | 832×480 @ 24fps | 8 steps · CFG 1.0 | FP8 E4M3 · Sliding 2 chunks + Tiled VAE | ~2.5–3.8 min (silent) |
| RTX 5090 32 GB · MAGI-1 4.5B Distilled | 1280×720 @ 24fps | 8–12 steps · CFG 1.0 | FP8/BF16 · Sliding 3 chunks + Tiled VAE | ~2.0–3.2 min (silent) |
| 1× H100 80 GB · MAGI-1 24B Base | 1280×720 @ 24fps | 32–48 steps · CFG 7.5 | FP8/BF16 · Full 4-chunk KV resident | ~3.0–5.5 min (silent) |
| RTX PRO 6000 96 GB · MAGI-2 Preview 114B | 720p–1080p @ 25fps | Flow schedule · 25–30 steps | Community NVFP4 (~71.8 GB) + 64 GB RAM | ~6–12 min (10s max) |
Copyable ComfyUI starter blueprint & CUDA allocator tuning
Below is a clean starter blueprint reflecting the exact node stages required for MAGI-1 chunk-autoregressive generation in ComfyUI: FP8 checkpoint mounting with aggressive text-encoder offload, four-chunk prompt scheduling, causal KV-cache sampling, and tiled 3D VAE decoding. Because community wrappers evolve node class names across releases, map the parameter values (`chunk_frames`, `kv_cache_mode`, `steps_per_chunk`, `cfg`, and tiled VAE overlaps) directly onto whichever verified MAGI-1 or Colnb83/comfyui-magi2-native wrapper release you install.
{
"last_node_id": 6,
"last_link_id": 6,
"metadata": {
"model": "sand-ai/MAGI-1 4.5B Distilled FP8 (Verified Live Apache 2.0)",
"note": "Illustrative ComfyUI graph blueprint — verify node names against your installed wrapper"
},
"nodes": [
{
"id": 1,
"type": "MagiModelLoader",
"widgets_values": [
"magi-1/4.5B_distill_fp8_e4m3fn.safetensors",
"fp8_e4m3fn",
"sdpa_flash_attn_2"
]
},
{
"id": 2,
"type": "T5TextEncoderLoader",
"widgets_values": [
"t5xxl_fp8_e4m3fn.safetensors",
"offload_after_encode"
]
},
{
"id": 3,
"type": "MagiChunkPromptScheduler",
"inputs": { "clip": [2, 0] },
"widgets_values": [
"0: 35mm medium close-up, rain-streaked jazz bar window, warm tungsten key light, subject glances down at brass watch",
"1: same 35mm tungsten lighting, subject slowly lifts chin toward camera as rain streaks soften background neon",
"2: subtle 50mm dolly push-in, warm lamp catch-light tracks across cheekbones, calm deliberate breath",
"3: hold frame steady, slight rack focus toward misty street glass behind shoulder"
]
},
{
"id": 4,
"type": "MagiCausalSampler",
"inputs": { "model": [1, 0], "chunk_conditioning": [3, 0] },
"widgets_values": {
"width": 832,
"height": 480,
"chunk_frames": 24,
"num_chunks": 4,
"steps": 8,
"cfg": 1.0,
"kv_cache_window": 2,
"first_frame_strength": 1.0,
"seed": 884210
}
},
{
"id": 5,
"type": "VAEDecodeTiled",
"inputs": { "samples": [4, 0], "vae": [1, 2] },
"widgets_values": [512, 64, 16, 8]
},
{
"id": 6,
"type": "VHS_VideoCombine",
"inputs": { "images": [5, 0] },
"widgets_values": {
"frame_rate": 24,
"format": "video/h264-mp4",
"crf": 17,
"save_output": true
}
}
]
}OOM mitigation flags & the hybrid ComfyUI-to-MagiAI Cloud director handoff
Even with FP8 quantization and sliding KV-cache windows, PyTorch memory fragmentation frequently causes spurious CUDA OOM errors right at the boundary between chunk 3 and tiled VAE decoding. Setting `PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True` (on Linux CUDA 12.4+) allows PyTorch's caching allocator to coalesce fragmented blocks instead of requesting redundant 2 GB arenas. Pair that with `--reserve-vram 1.5` so your desktop compositor or display server does not collide with chunk activation peaks on single-GPU Windows and Linux workstations.
Just as critical is knowing where local ComfyUI stops being productive. Local MAGI-1 4.5B gives you unlimited, zero-cost silent camera blocking and framing experiments on an RTX 4090 or RTX 5090—making it ideal for locking your opening keyframe, lens geometry, and rough motion choreography. The moment your project needs 1080p @ 25fps delivery, synchronized single-stream spoken dialogue, foley acoustics, or 20-slot Omni-Reference cast consistency across 15 to 30 continuous seconds, pushing a local 24 GB rig hits a brick wall. Export your best local ComfyUI start frame (and optional closing keyframe) directly into MagiAI Studio's 480B Image-to-Video or Omni-Reference pipeline for a 4-second 40-credit audition before committing to the full master.
#!/usr/bin/env bash
set -euo pipefail
# Prevent PyTorch block fragmentation during multi-chunk KV-cache + tiled VAE transitions
export PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True,max_split_size_mb:256"
export CUDA_MODULE_LOADING="LAZY"
# Recommended for 24 GB RTX 4090 / 32 GB RTX 5090 running MAGI-1 4.5B FP8
python main.py \
--listen 127.0.0.1 \
--port 8188 \
--fp8_e4m3fn-unet \
--fp8_e4m3fn-text-enc \
--reserve-vram 1.5 \
--preview-method latent2rgbHonest Hybrid Pattern: Local ComfyUI Plates + Flagship 480B Cloud Audio-Video
Use local ComfyUI to craft pixel-exact 16:9 or 9:16 start/end keyframes and silent MAGI-1 4.5B motion pre-vis for $0 marginal cost. When you need 1080p 25fps dialogue lip-sync, 20 Omni-References, and 30-second continuity on flagship 480B MAGI-2, hand those plates to MagiAI Studio at 10 credits/second ($0.08–$0.12/s) with zero 8×H100 setup.
Troubleshooting & field fixes
Expand any failure mode below for root-cause analysis and deterministic fixes.
CUDA Out of Memory triggers reliably at Chunk 3 or Chunk 4 despite Chunk 1 succeeding
Root cause: Unbounded causal KV-cache retention keeps appending key/value attention states across every 24-frame chunk while T5-XXL text encoder weights remain pinned in GPU VRAM.
Resolution: Force T5-XXL offload immediately after upfront prompt encoding, cap causal KV-cache history to 2 sliding chunks (48 frames), set PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True, and drop base resolution to 832×480 on 24 GB cards.
MAGI-1 4.5B Distilled outputs look burnt, posterized, or jittery with neon halo edges
Root cause: Running the distilled 4.5B checkpoint with base-model CFG guidance (5.0–7.5) double-amplifies guidance vectors that are already distilled into the checkpoint weights.
Resolution: Lock CFG strictly to 1.0 and keep sampling between 8 and 12 steps per chunk for 4.5B distilled. Reserve CFG 6.5–7.5 and 32–64 steps exclusively for the non-distilled 24B base weights.
Visible exposure pop or subject wardrobe morph occurs exactly every 24 frames (1.0 second)
Root cause: Adjacent chunk prompts contradict established scene lighting or omit invariant visual anchors, causing causal attention to reconcile conflicting text tokens against prior clean frames.
Resolution: Repeat an identical scene-anchor prefix (lens, lighting temperature, wardrobe, location) in every chunk prompt and alter only the incremental camera or subject beat across chunk boundaries.
Sampling finishes 100%, then ComfyUI crashes or outputs solid black frames during VAE decode
Root cause: Decoding 96+ frames through a 3D video VAE in a single monolithic pass spikes peak VRAM by 6–10 GB; mismatched BF16/FP16 VAE precision on older drivers can also produce NaN tensors.
Resolution: Switch to VAEDecodeTiled (spatial tile 512, overlap 64, temporal tile 16, temporal overlap 8) and run the video VAE in BF16 or FP32 rather than FP16.
Generated MAGI-1 MP4 plays smoothly in ComfyUI VHS preview but contains zero audio track
Root cause: April 2025's open-weights MAGI-1 (both 4.5B and 24B) is a video-only silent model by design; unified single-stream audio-video synthesis was introduced in MAGI-2.
Resolution: Pair MAGI-1 footage with external foley/TTS in post, or pass your ComfyUI start frame into MagiAI Studio's live flagship 480B MAGI-2 Image-to-Video workflow for native 25fps lip-synced dialogue and foley.