Taking Trainium3 to the Track: Generating Videos with LTX-2.5

Generating a 10‑second video with LTX‑2.5 on AWS Trainium3 took ~22 s after extensive tensor‑ and sequence‑parallel optimizations, showing the hardware’s promise for high‑resolution diffusion video generation.

Taking Trainium3 to the Track: Generating Videos with LTX-2.5

Introduction

In a month‑long partnership with AWS, we got access to a Trainium3 instance (trn3.48xlarge, 64 NeuronCores). After a week of testing Hugging Face models, we decided to push the hardware to its limits by generating full‑length videos with LTX‑2.5 – a diffusion model that creates video and sound together. The result: a 10‑second, 2048×1024 clip rendered in 22‑23 seconds on half the machine, comparable to Lightricks’ own API and far faster than our initial attempts.

---

Two Goals: Usability and Performance

  1. Usability – We wanted to move beyond the toy examples that come with the model and build a short film from a script‑like JSON storyboard. Each shot contains a rich prompt (style, motion, camera, lighting, sound) and optional chaining keys (`from`, `to`) that preserve subjects across cuts.
  2. Performance – The target was to approach or beat the numbers advertised by LTX‑2.5’s online API (23.7 s for a 10‑second 1080p clip). Since CUDA baselines were unavailable, the API served as the reference point.

---

How the Pipeline Works

The film is defined as a list of shots: ```json [ {"name":"dream","prompt":"Style: cinematic…","seed":3}, {"name":"nap","prompt":"Style: cinematic…","seed":1,"to":{"shot":"iceberg","frames":9}}, {"name":"iceberg","prompt":"Style: cinematic…"}, {"name":"shake","prompt":"Style: cinematic…","from":{"shot":"iceberg","frames":25}} ] ```

  • Chaining – `to` makes a shot end on the first frames of a later shot; `from` starts a shot from the last frames of an earlier one, ensuring visual continuity.
  • Pose‑to‑pose vs. straight‑ahead – We built the seal film pose‑to‑pose, creating the payoff shot first (the iceberg) and then aligning surrounding shots to it.
  • Diffusers pipelines – Three pipelines share LTX‑2.5’s weights:

`LTX2Pipeline` – generates shots from prompts alone. `LTX2ConditionPipeline` – handles shots that start/end on existing frames. * `LTX2LatentUpsamplePipeline` – upsamples latents ×2 before the final diffusion steps.

  • Film assembly – ~160 lines of Python read the JSON, order shots, trim, caption, sync audio, and stitch everything together.

---

Running on Trainium3: From Failure to Success

First Attempt (no parallelism)

  • Model split across 4 cores, but the transformer still didn’t fit.
  • 10‑second clip at 960×544 took 5 min 20 s wall‑time; only ~45 s ran on the NeuronCores.

Optimized Run (TP‑4 × SP‑8)

  • Tensor parallelism (TP‑4) – split transformer weights across four cores.
  • Sequence parallelism (SP‑8) – split video tokens across eight cores, giving a total of 32 cores per clip.
  • Result: 10‑second clip at 2048×1024 in 22‑23 s wall‑time, with 15 s spent on the NeuronCores.

Key Optimizations

| Problem | Work‑around | Gain | |---|---|---| | Transformer too large for a single core | Custom attention processor + tensor split | Runs on 4 cores | | Text encoder on CPU bottleneck | Run encoder only on rank 0, broadcast results | 205 s → 7.5 s | | Memory fragmentation | Pack parameters into ≤1 GiB buffers | 22.96 GiB → 10.2 GiB | | Inefficient attention kernels | Align sequence length to multiples of 128 | 4.3 s → 3.0 s per step | | CPU‑only video decode | Decode on NeuronCores, share frames via shared memory | 357 s → 1.6 s | | Thread contention across ranks | Pin rank 0 threads, cap others | Prompt encode 7.4 s → 3.3 s | | Padding tokens processed unnecessarily | Encode only actual prompt tokens | 3.4 s → 1.4 s |

---

Lessons Learned

  • Both host and device matter – Host‑side optimizations (thread pinning, memory packing) yielded a 35× reduction in overall time, while device‑side parallelism cut NeuronCore compute from 45 s to 15 s.
  • Sequence parallelism is the workhorse – It allowed us to use 32 of the 64 cores for a single clip, making high‑resolution generation feasible.
  • Graph size dictates feasibility – Large transformer graphs fail to load; always test on CPU first to verify shape compatibility.
  • Upstream fixes are coming – Open issues in `diffusers` aim to integrate tensor and context parallelism, which will simplify many of the manual workarounds we applied.

---

Practical Takeaways

If you plan to run diffusion video models on Trainium3:

  1. Plan for tensor parallelism – Split large transformer weights early.
  2. Leverage sequence parallelism – Distribute video tokens across many cores to maximize utilization.
  3. Optimize the host – Reduce CPU bottlenecks (prompt encoding, decoding, thread contention) before chasing more hardware tricks.
  4. Validate graph sizes – Use a CPU run to ensure the shapes you need will load on the NeuronCores.
  5. Watch the ecosystem – Upcoming `diffusers` updates will likely remove many custom patches.

With these strategies, Trainium3 can deliver near‑real‑time, high‑resolution video generation, turning a powerful inference accelerator into a creative studio tool.

Source

Read original source

Why we picked this

Video generation with LTX-2.5 involves a new AI model, core AI content.

← Back to all articles