Brifing

Optimizing Real-Time Video Generation on Trainium Chips

How Reactor and Amazon Neuron achieved sub-2ms latency for autoregressive diffusion models

Amazon Science3 min

1World models evolution

Since Schmidhuber's 2018 paper on predictive world models, the field has advanced dramatically through massive datasets and transformer architectures. Modern models now process text, images and video into latent spaces for applications ranging from robotics to game design. This progress creates intense hardware demands, particularly for real-time applications where latency under 16ms per frame is critical for interactive experiences.

2Reactor's global challenge

The Reactor platform serves developers needing real-time AI worldwide, with hundreds of GPU clusters across regions. Their CTO emphasizes three non-negotiable requirements: real-time performance, low latency, and efficiency at scale. This demands optimization from chip-level scheduling to global network routing, ensuring generated pixels reach users without Kubernetes hops, whether from cloud clusters or bare metal installations.

3Autoregressive diffusion shift

Video generation has evolved from fixed-length clips to infinite streams, requiring new model architectures. Autoregressive diffusion models combine LLM-style token prediction with diffusion refinement, allowing user inputs to dynamically alter subsequent frames. This enables navigable generated environments but introduces strict latency constraints - each keystroke must influence the next frame within 62.5ms to maintain 16fps playback.

4Rolling Forcing advantages

The teams selected Rolling Forcing for its balance of quality and size, consistently producing 30-second HD clips. Unlike batch processing, it streams frames immediately after generation - a necessity for interactivity where late frames break immersion. However, its small model size belies extreme memory demands from long sequences (23,400 query tokens attending to 32,760 context tokens), making real-time execution challenging.

5Three core bottlenecks

Real-time generation poses unique compiler challenges: dynamic shapes from scene transitions, irregular memory patterns from operations like 3D-RoPE, and intensive cache management. Each forward pass must handle sliding window attention across height, width and time dimensions while maintaining frame-rate. Generic compilers struggle with these workload-specific patterns, often introducing millisecond delays that compound catastrophically at 16fps.

6Neuron Kernel Interface

NKI provided hardware-level control, letting developers replace bottlenecks with custom kernels. This reduced 3D-RoPE processing from 5s to 1.8ms and layer cache copies from 23ms to 1.9ms. The NKI-Dev-Suite agent generated working kernels immediately, cutting memory use from OOM to 11GB. Such precision is critical when each millisecond determines whether generation stays ahead of playback.

7Hybrid sharding solution

The 12-head attention architecture didn't divide cleanly across Trainium's 8-core chips. Pure tensor parallelism required wasteful padding, while sequence parallelism risked breaking frame boundaries. Their hybrid approach splits heads across 4 cores and sequences across 2, maintaining mathematical correctness and data locality. This achieved an 8.25x speedup in the VAE decoder through spatial W-axis sharding.

8Model structure optimizations

Rolling Forcing's two-phase execution (diffusion then cache update) created hardware underutilization, as the lighter cache phase couldn't fill cores after sharding. By batching shared components and only splitting divergent paths, the team improved chip saturation. This is particularly impactful on Trainium's 128-core instances, where small partitions lead to stranded capacity.

9Real-time achievements

The optimizations enabled first-run success generating real-time video on Trainium, with all frames meeting the 16fps threshold. The pipeline maintained quality while reducing memory consumption by 60% compared to eager-mode execution. Critically, these techniques generalize beyond Rolling Forcing to any autoregressive diffusion model requiring interactive latency.

10Production implications

The solution demonstrates that real-time generation is achievable when optimization spans from kernel math to global distribution. Reactor's platform now benefits from sub-2ms kernel execution, while Amazon's Neuron team has created reusable patterns for interactive AI. Their work establishes that hardware-aware design can overcome the memory-compute tradeoffs that previously limited diffusion models to offline rendering.

Original article: Amazon Science — Optimizing Real-Time Video Generation on Trainium Chips