This document is relevant for: Trn2, Trn3
AR-Diffusion in vLLM Omni Neuron#
Overview#
Autoregressive diffusion (AR-Diffusion) models generate a video chunk by chunk: each chunk of
latent frames is denoised in a few steps while attending to the key / value (K/V) history of the
chunks before it, and the clean chunk’s K/V are then committed to that history. vLLM-Omni runs
these models with ARDiffusionEngine and ARDiffusionModelRunner: a paged KV manager built on
vLLM’s KVCacheManager and a chunk-window manager (sink frames plus a sliding window), session
admission and eviction, stepwise execution and streaming output.
The plugin keeps all of that and replaces only what touches the device:
the physical pool: one pre-registered Neuron buffer, sliced into per-layer views that a model’s compiled graphs take as persistent inputs;
the pool size: exactly the admitted sessions’ requirement, within the HBM the weights leave (Neuron has no free-memory query);
the per-pass inputs the model reads: a per-head block table, the visible-history bounds and, on the commit pass, per-token update indices.
Upstream’s admission picks the sessions and sets the blocks; upstream’s manager allocates, evicts and commits blocks; the model reads the history through the block table and writes the commit inside its compiled graph. The runner is model-agnostic: a pipeline plugs in by declaring its KV geometry, binding the pool, and consuming the paged inputs (see Integrating a pipeline). LingBot-World-V2 is served on this path in real time (see LingBot-World-V2 on the AR-Diffusion runner).
Architecture#
AsyncOmni / serving
└─ ARDiffusionEngine (vLLM-Omni)
└─ NeuronDiffusionWorker, one process per rank
└─ NeuronARDiffusionModelRunner
├─ ARDiffusionModelRunner (upstream: sessions, LRU, stepwise binding)
├─ NeuronARDiffusionKVCache (plugin: upstream manager + admission)
│ └─ NeuronPagedKVPool (plugin: one backing buffer, per-layer K/V views)
└─ the AR-Diffusion pipeline (model: its DiT reads the paged inputs)
Runner selection#
An AR-Diffusion stage sets
engine_backend: vllm_omni.experimental.ar_diffusion.engine.ARDiffusionEngine, which declares
upstream’s ARDiffusionModelRunner. Before the worker builds its runner,
NeuronDiffusionWorker.init_device() replaces that runner with
NeuronOmniPlatform.get_ar_diffusion_model_runner_cls() (NeuronARDiffusionModelRunner). It
raises if the Neuron runner cannot be imported, or if an AR-Diffusion pipeline (upstream’s
SupportsARDiffusionPipeline) is loaded by the non-AR NeuronDiffusionModelRunner.
NeuronARDiffusionModelRunner#
The runner is upstream’s AR runner composed with the Neuron runner by the MRO
(NeuronARDiffusionModelRunner(ARDiffusionModelRunner, NeuronDiffusionModelRunner)), so the
model load (CPU-first, device transfer, Neuron compile) is the Neuron runner’s and everything
else is upstream’s. It overrides four upstream hooks:
Hook |
Neuron behavior |
|---|---|
|
The KV bound: the logical core’s HBM minus the resident weights (see KV sizing). |
|
Upstream’s validation and config resolution from the pipeline’s |
|
Sessions get |
|
Upstream’s warm-up rollout; a failed warm-up step fails the load. |
initialize_kv_cache() checks the geometry on the host, allocates the pool (NeuronARDiffusionKVCache), binds the views into the
pipeline through its bind_neuron_kv_cache() hook, and only then publishes the cache, its spec
and the session capacity on the runner. A failure publishes nothing, so the call can be
retried; a second call after success raises.
Integrating a pipeline#
A pipeline runs on this runner when it implements upstream’s SupportsARDiffusionPipeline
(as it would on GPU) and the plugin’s SupportsNeuronARDiffusionKV
(diffusion/ar_diffusion/capability.py), and reads its history from the Neuron pool:
Declare the KV geometry.
ar_diffusion_kv_cache_spec()returns upstream’sARDiffusionKVCacheSpec: layers, the rank’s local KV heads, head size, tokens per latent frame, frames per chunk, the sink and window frames, the KV branches, the session capacity, and the cross-attention and model-owned bytes per session that the KV state must hold. The block size istokens_per_frame; leavear_diffusion_kv_config.chunk_sizeunset (a different value is refused).Bind the pool.
bind_neuron_kv_cache(kv_cache)is required: the runner checks it before any allocation and raisesTypeErrorwithout it. It is called once after allocation, before the warm-up.kv_cache.pool.flat()gives the per-layer views(k_0, v_0, k_1, v_1, ...), which the model’s compiled graphs take as persistent inputs.Consume the paged inputs. Per pass, the pipeline calls
get_kv_caches(branch, seq_len=..., commit_current=...)on the session state bound bybind_ar_diffusion_state()and turns the contexts intoNeuronPagedInputswithpaged_inputs_from_contexts()(see Paged inputs). Denoise passes usecommit_current=False; the commit pass usescommit_current=True, writes the chunk’s K/V throughkv_cache_update_idxinside its graph, then callsmark_written_in_kernel()on the context andcommit_paged_context(branch)on the state.
The model’s attention reads the history through the per-head block table and masks it with the
bounds; paged_attention.key_pool_shape defines the K layout the pool is allocated in.
KV cache and pool#
NeuronARDiffusionKVCache#
NeuronARDiffusionKVCache subclasses upstream’s ARDiffusionKVCache. Upstream’s constructor
does the validation, the budget, session admission and the vLLM manager. Its storage
hook _allocate_storage() allocates a NeuronPagedKVPool instead of upstream’s
FlashAttention pools; upstream’s cross-attention caches and history staging are allocated by
upstream’s own code on the same device. The upstream entry points that read or write the
FlashAttention pools (key_cache, value_cache, write_chunk_kv) raise: the Neuron pool is
read by the model’s paged attention and written by its commit pass.
NeuronPagedKVPool#
One zeroed backing buffer [layers, 2, num_blocks * N * block * D], sliced into per-layer
views:
K in the model’s pool layout,
paged_attention.key_pool_shape(num_blocks, N, block, D)(token-major[num_blocks, N, block, D]by default; a model that streams another K layout changes only that function);V
[num_blocks, N, block, D], token-major.
N is the rank’s local KV heads. Block 0 is the manager’s null block (the padding target).
The pool pages one latent frame per block (block_size = tokens_per_frame), so the sink and
window bounds and the commit fall on block boundaries. Upstream’s paging_block_size() requires
a multiple of 16 tokens (the GPU paged kernels’ constraint), so it would page a 1,560-token frame
(832 x 480) in 16-token blocks. The Neuron paged attention takes any block size: it gathers
whole blocks into the history and tiles that independently of the block size. It needs the
sink and window bounds and the commit on block boundaries, which one frame per block
guarantees, with no rounding waste. For
example, a 40-layer DiT with 5 local KV heads of 128 and 1,560 tokens per frame has ~160 MB
blocks per rank.
KV sizing#
NeuronOmniPlatform.get_device_total_memory() reports one HBM stack and Neuron has no
free-memory query, so the runner bounds the KV state by the logical core’s HBM left after the
weights (diffusion/ar_diffusion/memory.py):
core_hbm = stack_hbm / get_logical_cores_per_hbm_stack() # half a stack at LNC 1
kv_limit = max(core_hbm - resident_weights, 0)
Upstream’s admission picks the sessions: up to the pipeline’s session_capacity within
ar_diffusion_kv_config.gpu_memory_fraction of the bound. The pool is then exactly those
sessions’ requirement, upstream’s own: every resident session’s sink plus window frames, one
in-flight chunk, two headroom frames and the scratch blocks, plus each session’s
cross-attention and model-owned state. The rest of the core’s HBM is left for the compiled
graphs; graphs that do not fit beside the pool fail the warm-up, and so the load. With 9 sink
and 9 window frames and 3-frame chunks, one session is 23 managed blocks (18 resident frames, a
3-frame chunk, 2 headroom) and 3 scratch blocks. A bound below one session fails at load with
an error that gives the bound and its terms.
The runner logs the sizing per rank (core HBM - weights - KV state = left for the graphs) and
prints each rank’s device HBM ([neuron-hbm], the runtime’s get_vnc_memory_stats) after load
and after the warm-up.
Paged inputs#
Per pass, NeuronARDiffusionKVState.get_kv_caches() returns upstream’s per-layer contexts over
a NeuronPagedForwardContext; paged_inputs_from_contexts() turns them into
NeuronPagedInputs, built on the host with fixed shapes so one compiled graph serves every
chunk:
Field |
Shape |
Content |
|---|---|---|
|
|
Per-head block ids ( |
|
|
|
|
|
Commit pass only: one pool slot per token and head (vLLM Neuron’s |
|
3 ints |
The bounds on the host, for a model’s host-side plan check before launch |
|
bool |
Every listed position is visible (the steady state), so a model may run an unmasked variant |
A denoise pass (commit_current=False) reads the history and writes nothing; upstream’s
scratch blocks are listed but never read. The commit pass writes the chunk’s K/V through
kv_cache_update_idx inside the compiled graph, and the pipeline calls
mark_written_in_kernel(). commit_paged_context() then runs upstream’s commit (advance,
evict) and fails closed if the commit pass did not write.
Constraints#
One sequence per forward (
max_num_seqs: 1, no request batching).Not supported on Neuron, and refused at load: noisy-KV (cell) pipelines, segmented KV, action / state scratch K/V, a prefill prefix, and first-block K/V sharing.
The model owns the K/V reads and writes: upstream’s FlashAttention pool accessors raise.
LingBot-World-V2 on the AR-Diffusion runner#
LingBot-World-V2 14B causal-fast (robbyant/lingbot-world-v2-14b-causal-fast-diffusers) is
served in real time over /v1/realtime/video on one trn2.48xlarge at LNC 1 with
NeuronLingBotWorldPipeline, registered under upstream’s LingBotWorldCausalDMDPipeline. Its
DiT (TP8 x CP8 on 64 cores) reads the paged inputs above; the ENCODE and DECODE work runs on
role workers on other cores beside it:
NeuronARDiffusionModelRunner (the DiT stage, 64 ranks)
└─ NeuronLingBotWorldPipeline (FULL role)
├─ LingBotDiTRuntime (text K/V, prep, denoise and commit graphs)
└─ LingBotAuxBackend
└─ LingBotRoleWorkers (one 16-rank world on cores 64-79, started by the executor)
├─ ENCODE (UMT5 TP16, 2 x 8 streaming condition encoder)
└─ DECODE (2 x 8 spatially-sharded streaming VAE decode)
The chunk loop on the stepwise interface#
NeuronLingBotWorldPipeline implements upstream’s stepwise interface (prepare_encode,
prepare_next_chunk, denoise_step, step_scheduler, post_decode) over LingBotDiTRuntime,
whose graphs are static: text K/V (once per prompt), chunk prep, the denoise pass and the commit
pass. A 6-chunk warm-up rollout at load runs into the steady state, so every graph in the
runtime’s expected_graph_keys() compiles before serving.
One chunk is 4 denoise passes and a commit pass. Each pass takes its paged inputs from the
session’s get_kv_caches() contexts (paged_inputs_from_contexts()): the denoise passes attend
over the history and the current chunk without committing it; the commit pass writes the
chunk’s K/V into the pool in graph, and the pipeline then calls mark_written_in_kernel() and
commit_paged_context(). Each pass graph starts with the previous step’s DMD update, so the
latent, the noise and the flow stay on the device, and there is one host sync per chunk.
Early frame emission. After chunk n’s sync, post_decode submits its latents to DECODE,
launches chunk n + 1’s first denoise passes that fit in the runtime’s in-flight budget
(free_launch_slots(); the same launches on every DiT rank), then waits for the decode and
returns chunk n’s frames. Each step returns its own chunk’s frames, one decode after its DiT.
Launching ahead needs the next chunk’s camera: with a recorded or scripted camera
(action_path, camera_action_script) the next chunk’s prep is prefetched; with live
session.interaction camera events the next pose is known only at the chunk boundary, so
nothing is launched early and the decode follows the DiT.
Encode, denoise and decode overlap#
The pipeline is role-aware through upstream’s DiffusionStageRole: ENCODE (UMT5 and the
streaming condition encoder), DENOISE (the DiT) and DECODE (the streaming VAE decode with each
session’s causal decoder state). The served stage runs the FULL role: the DiT, with the ENCODE
and DECODE role instances on role workers on their own cores. The stage executor
(LingBotWorldExecutor) starts the role workers with the DiT workers; DiT rank 0 calls them
through LingBotAuxBackend and broadcasts what the other DiT ranks need. Payloads use
upstream’s E/G/D names, keyed {request}_{stage}_{chunk}, over upstream’s
SharedMemoryConnector. One session is served at a time.
Per session and chunk, the work overlaps as follows:
Session open. ENCODE starts the session’s condition sequence. Every chunk’s image condition depends only on the source image, so the encoder runs ahead until its history reaches a fixed point (at most the session’s chunks), interleaved with the decodes on the same VAE; the prompt’s UMT5 encode runs once. The DiT waits for chunk 0’s condition and the prompt; later conditions are encoded ahead of their chunks.
Chunk
n. While the DiT computes chunkn, DECODE decodes chunkn - 1and ENCODE continues the condition sequence on the same cores; chunkn’s condition is ready before its prep.