Amazon Science Amazon ★ 115 6 min

A kernel-centric path to real-time video generation on Trainium

🔗 https://www.amazon.science/blog/a-kernel-centric-path-to-real-time-video-generation-on-trainium

📌 【Amazon 硬體工程】即時影片生成的 Trainium Kernel 最佳化之路

TL;DR:Amazon與Reactor合作,用kernel最佳化法解決Trainium上自回歸擴散模型即時生成影片的效能瓶頸。

想像一段互動式串流影片生成,如果有一幀晚了幾毫秒才送達,使用者體驗立刻崩壞。這正是即時互動影片生成模型必須面對的鐵律:生成速度必須跑贏播放時間軸,慢一步就是失敗。

🤔 從世界模型到自回歸擴散影片

2018年,1990年首度提出「世界模型」這個機器學習概念的 Jürgen Schmidhuber,與 David Ha 合著論文,描述一種能「萃取空間與時間中有用表徵」的預測性世界模型。八年過去,隨著巨量訓練資料集、變分自編碼器(VAE)、擴散模型與transformer的結合,今日的世界模型已能把文字、圖片、聲音、影片轉為潛在空間,用來建構並維持能預測狀態變化、回應動作的沉浸式世界模型,並在機器人、交通、氣候模擬、遊戲開發、科學模擬與設計原型中扮演關鍵角色。

Reactor是一個讓開發者、設計師與研究者部署、使用並規模化即時互動AI模型的平臺。共同創辦人暨CTO Bryce Schmidtchen談到,關鍵在於「即時性、低延遲,以及儘可能有效率地做到規模化」,效率涵蓋從如何在晶片(此處是Trainium)上排程推論,到如何盡量把每次forward pass打包到極致。Reactor的全球佈局讓挑戰更嚴峻:需要在世界各地數百個叢集間,讓GPU吐出的每個像素不經過Kubernetes層層跳轉就送上網路,同時銜接支援多種codec、解析度的串流網路,並串接跨語言的API與SDK。

Amazon Neuron Science團隊的principal applied scientist Jun Wu觀察到,影片生成正從產生固定長度的短影片,演進到無限長度或動態長度的影片。要在這種長度下生成高品質畫面,催生了autoregressive diffusion models的興起:這類模型結合大型語言模型式的next-token prediction,與擴散模型的迭代精煉,讓使用者的一次鍵盤輸入能被模型吸收為輸入,並根據前一個生成的影格,正確決定下一步動作或下一個場景。Wu表示,今天多數互動式影片生成模型都採用這種做法。

🧩 鎖定 Rolling Forcing,拆解三大 kernel 難題

Wu與同事Mason Fu、Lingfan Yu與已投入即時互動影片生成超過18個月的Reactor團隊合作,選定Rolling Forcing模型作為autoregressive diffusion影片生成在Trainium上的代表性工作負載,原因是它能穩定生成高品質的30秒影片,且模型體積相對較小。真正的難處不在畫質,而在於它必須即時運行:不同於傳統影片生成先離線算完整段影片再回傳,Rolling Forcing這類模型是串流式的,每一幀生成後立即被消費、展示給使用者或回饋成下一次輸入,晚到的一幀就會打斷體驗。

Wu指出,高品質生成擴散模型的挑戰在於序列很長,需要大量記憶體;Rolling Forcing模型雖小,序列長度卻很大。「小模型、長序列、硬性幀率下限」這個組合,正是即時生成之所以嚴苛的原因。Rolling Forcing能達到每秒16幀的標準播放速率,也因此滿足了延遲要求,而Trainium的角色就是提供足夠效能與記憶體,撐住這個長序列工作負載,在16fps以上做到真正即時生成,而非事後才產出好畫面。

兩個團隊因此採取kernel-centric、由下而上的開發方式,目標是讓開發者更容易上手,並聚焦三個對通用編譯器而言特別棘手、且在每次forward pass都會重複發生的挑戰:動態形狀(dynamic shapes)、不尋常的記憶體存取模式、以及繁重的cache管理。動態形狀的部分,一方面源自場景本身的變化,例如鏡頭從投手獨自站在投手丘,幾秒內拉遠帶出所有球員甚至數千名觀眾;另一方面,即時影片生成採用連續滑動視窗(sliding window)不斷生成並淘汰影格,導致attention長度在每次forward pass間都不一樣,且每個視窗還包含denoising與cache清理兩個不同階段,讓靜態編譯變得困難。

除了滑動KV cache的複製,影片生成工作負載還包含rotary position embeddings(RoPE)與attention transpose這類記憶體存取模式高度特定於此工作負載的運算,讓通用編譯器難以充分最佳化。以RoPE為例,在影片生成中必須處理高度、寬度、時間三個軸,而不是LLM中僅有的單一位置軸;Wu解釋,這種3D旋轉嵌入會在最內層維度交錯奇偶元素,若照通用方式編譯,會產生大量瑣碎的小型資料搬移。

💡 由下而上的意義:把編譯器搞不定的細節交給 kernel

這三個挑戰之所以值得用kernel-centric的方式處理,是因為它們不是一次性的成本,而是每次forward pass都會重複出現。在其他工作負載上可能只是微不足道的延遲,放進16fps的即時生成節奏裡,卻會不斷累積成明顯的延遲失敗。與其等待通用編譯器慢慢追上,直接下放到kernel層手動最佳化,才能真正撐住即時性的要求。

🎯 實務啟示

對想在Trainium或其他客製化AI加速器上部署autoregressive diffusion、即時影片生成模型的工程師而言,這篇文章點出三個該優先檢視的效能熱點:動態序列長度、非典型記憶體存取模式(尤其是3D RoPE)、以及KV cache管理。這些問題在通用編譯器上很難被妥善處理,值得優先評估是否需要投入客製kernel。

🔗 來源

#Trainium #WorldModels #VideoGeneration #DiffusionModels #AWS #AIInfrastructure #KernelOptimization #AutoregressiveModels #RealTimeAI #MachineLearning

原始資料 Amazon Science · 收集於 2026-09-25
來源原標題
A kernel-centric path to real-time video generation on Trainium
機構
Amazon
原始連結
https://www.amazon.science/blog/a-kernel-centric-path-to-real-time-video-generation-on-trainium

摘要原文

In 2018, Jürgen Schmidhuber — who in 1990 was the first person to propose world models as a machine learning concept — published a paper with David Ha. They wrote about “a predictive world model” which could “extract useful representations of space and time” and use that to train agents to drive, among other things. The growth in the capability and real-world applications of world models in the eight years since that seminal paper is staggering. The emergence of massive training datasets, paired with variational autoencoders, and both diffusion and autoregressive transformers enable today’s world models to convert text, images, audio, and video inputs into latent space that is used to build and maintain breathtaking, immersive world models which can predict state changes and respond to actions. These models have vital and expanding roles in robotics, transport, climate modeling, video game development, scientific simulation, and design prototyping. The sharp increase in the power and potential of world models has been accompanied by an increased need for hardware and infrastructure capable of supporting them. That is a challenge that Bryce Schmidtchen, co-founder and chief technology officer of Reactor, is well acquainted with. “It's about real time, it's about low latency, and it's about doing that as efficiently as you can at scale,” Schmidtchen observed. Reactor is a platform that allows developers, designers, and researchers to deploy, use, and scale real-time interactive AI models. “Efficiency means everything from how you schedule the inference on the given chip, in our case Trainium, to how you think about maximally bin packing every forward pass of the model.” The challenge of efficiency is made even more acute by Reactor’s global presence. “We think about GPU clusters in terms of regions — we have hundreds all over the world. The latent that turns into a pixel that comes off the GPU needs to be able to get to the network without hopping around through Kubernetes. And you need to do this in a way where it doesn't matter if it's a well-supported cluster or bare metal in a closet. “And then,” Schmidtchen continued, “you need to tie this to world-class networking and media streaming that supports different codecs, different resolutions, and allows that to connect to APIs and SDKs across different languages that can support all different types of applications.” The global reach of AWS already helps Reactor to achieve many of its goals. “Everything they have at the inference layer, the level of scale that we're able to achieve in different regions is what makes a platform of this scale possible and reliable,” Schmidtchen observed. Now, a recent collaboration between Reactor and the Amazon Neuron Science team has forged a path to even greater efficiency for world models. This is a look at the optimization strategy those teams pursued, and how that laid the foundation for future models to achieve real-time capability on Trainium. The rise of autoregressive diffusion models “The Neuron Science team explores new techniques for generative AI model enablement optimization,” explained Jun Wu, a principal applied scientist on the Neuron team. “This might be a new model architecture or new algorithm for optimization or a new way to generate and optimize the code for running those models on Trainium. We identify opportunities to build a prototype and make it feasible to be ported to the production pipeline.” The team spotted one such opportunity around the usage of diffusion models in video generation. “We noticed an evolution from generating shorter, fixed-length videos to infinite-length or dynamic-length videos,” Wu explained. “Generating high-quality video frames at those lengths gave rise to the usage of autoregressive diffusion models.” Those types of models, which combine the sequential next-token prediction found in large language models with the iteration and refinement of diffusion models, are essential for users who want to generate video where they can navigate the generated environment. “Autoregressive diffusion means a user keystroke can be absorbed as input to the model and, conditioned on the previously generated video frame, the model can correctly decide the next move or the next scene,” Wu observed. “Most of the interactive video generation models we are seeing today are using this.” Wu and his team, Mason Fu and Lingfan Yu, both senior applied scientists, saw a chance to optimize how those models are deployed for real-time video generation on Trainium, and saw the opportunity to do this in collaboration with Reactor. “We had been working on real-time video and interactive video generation for over 18 months at that point,” Schmidtchen noted. The teams considered various video generation techniques and aligned on utilizing Rolling Forcing, citing both its ability to consistently generate high-quality 30-second videos and its relative size. The hard part with these models isn't quality, it's that they have to run in real time. Unlike traditional video generation, which renders a full clip offline and returns it later, models like Rolling Forcing are streaming. Each frame is generated and immediately consumed, shown to a user or fed back in as the next input. That is how developers and customers actually use them, and a frame that arrives late breaks the experience, because generation has to stay ahead of the playback timeline. “High-quality generation diffusion models pose the challenge of a very long sequence, which requires a lot of memory consumption,” Wu explained. “Rolling Forcing is relatively small, but its sequence length is very large.” That combination of a small model, a very long sequence, and a hard frame-rate floor is what makes real time so demanding. Rolling Forcing's ability to generate 16 frames per second, the standard for video playback, meant it also met latency requirements. This is where Trainium adds value, bringing the performance and memory to sustain that long-sequence workload at speed and deliver real-time generation above 16 fps rather than merely producing good frames eventually. So the teams set about enabling Rolling Forcing, as a proxy for autoregressive diffusion video generation on Trainium. A developer-friendly approach The Neuron Science and Reactor teams adopted a kernel-centric, bottom-up methodology aimed at making life easier on developers. They focused on three challenges — dynamic shapes, unusual memory access patterns, and heavy cache management — that real-time video generation poses for generic compilers. Each of those challenges recurs on every forward pass, so what might be an insignificant delay on other workloads can compound into latency failures in real-time video generation. For example, the challenges posed by dynamic shapes are partly rooted in the shifting nature of scenes in real-time video generation: Imagine a shot showing a pitcher, alone on the mound, that pans out to show the other players and then thousands of fans in the stands, all within seconds. Real-time video generation also involves frames which are generated and evicted in a continuous sliding-window process. “This means attention lengths vary across forward passes, and there are two distinct passes per window: denoising, then cache cleanup,” Wu said. “All of that makes static compilation hard.” In addition to sliding KV cache copies, video generation workloads contain operations — rotary position embeddings (RoPE) and attention transposes — whose memory access patterns are workload-specific, making them challenging for any general-purpose compiler to fully optimize. For example, in video generation RoPE must contend with three axes (height, width, and time) rather than the single position it accounts for in LLMs. “The 3D rotary embedding interleaves odd and even elements along the innermost dimension, producing many tiny data transfers when compiled generically,” Wu explained.

由 claude-code/sonnet 自動生成