Repository navigation
SVG implementation for LTX 2 - #489
Open
jitendra-jalwaniya wants to merge 8 commits into
Open
jitendra-jalwaniya wants to merge 8 commits into
jitendra-jalwaniya wants to merge 8 commits into
Conversation
- Add SVG configuration options to ltx2_video.yml and ltx2_3_video.yml - Add dynamic SVG attention dispatching in LTX2Attention for self-attention - Propagate spatiotemporal_shape, layer indices, and timestep/step index in transformer blocks - Wire SVG configuration and step index into LTX2Pipeline diffusion loops - Include SVG configuration parameters in generate_ltx2 AOT cache metadata - Update LTX2BlockBenchmark with SVG attention configuration - Add comprehensive unit tests covering SVG config propagation and attention dispatch - Update documentation in docs/svg.md
There was a problem hiding this comment.
Code Review
This pull request integrates Sparse VideoGen (SVG) attention for LTX2 models on TPUs, including configuration propagation, routing logic, pipeline updates, and comprehensive unit tests. The feedback identifies potential TypeError crashes in ltx2_pipeline.py if optional SVG density, step, or layer parameters are explicitly configured as None, and provides robust suggestions to safely handle these cases.
xla_tpu_scoped_vmem_limit_kib was hardcoded to 32768 (TPU v6e) in LIBTPU_INIT_ARGS. Pick it from jax.devices()[0].device_kind instead (v6e: 32 MiB, v7x: 64 MiB) and pass it as a jax.jit compile option, since LIBTPU_INIT_ARGS is only read when jax.devices() initializes libtpu. nnx.jit has no compiler_options, so _forward now uses jax.jit over nnx.split state.
jitendra-jalwaniya
force-pushed
the
svg_ltx_no_rc2
branch
from
September 28, 2026 09:55
9ef5d46 to
c9fbddb
Compare
mbohlool
requested changes
Sep 29, 2026
mbohlool
left a comment
Collaborator
There was a problem hiding this comment.
This change is very big, would it be possible to break it into smaller PRs. we have strict guidelines for huge diffs (that probably creating with AI help).
…lock benchmark - Wrap svg_step_index in jnp.asarray(i, dtype=jnp.int32) in unrolled loop to avoid per-step AOT recompilation - Guard TPU scoped VMEM compiler option and compute per-device local_batch in LTX2BlockBenchmark - Use _cfg fallback uniformly for all optional SVG config attributes in create_sharded_logical_transformer - Move svg_attention import to top level in attention_ltx2.py - Add LTX-2 config example and update svg_spatial_density description in docs/svg.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR extends Sparse VideoGen (SVG) spatiotemporal attention support to LTX-2 (LTX2) video generation models on Cloud TPUs, building on the custom Ulysses/ring SVG kernel infrastructure introduced for Wan (PR #480).
Self-attention in LTX-2 transformer blocks dynamically profiles query tokens to choose between spatial and temporal attention patterns per head, skipping unneeded query–key interactions while executing through hardware-aligned local-band kernels on TPU. Sparse attention is opt-in (
use_svg_attention: True), disabled by default, and configurable across denoising steps, layers, and sparsity densities. Audio self-attention and cross-modal attention remain dense to preserve temporal and semantic grounding.In addition, several changes in this PR ensure robust support for LTX-2 inference on both TPU v6 (Trillium) and TPU v7, including capping tile search VMEM limits to 32 MiB on TPU v6, correcting custom block size fallbacks (
bkv_compute_in), enabling framewise VAE tiling, and accounting for CFG/STG batch scaling in block benchmarks.TPU v6 and TPU v7 Compatibility
This PR includes dedicated improvements to guarantee smooth execution across both TPU v6 and v7 architectures:
generate_ltx2.py, dynamically capstile_search_vmem_limit_bytesto 32 MiB on TPU v6 devices to prevent VMEM allocations from spilling into host memory during automatic block-size tuning.attention_flax.py, corrected_extract_custom_block_sizesso that omittedblock_kv_compute_invalues default directly tobkv_compute, preventing unoptimized compute tiles on TPU hardware.use_framewise_decodingwhen VAE tiling is activated to prevent HBM OOMs during long video decoding.ltx2_block_benchmark.py, properly scaled batch sizes (2× for CFG, 4× for CFG + STG) and normalized per-batch VMEM limits to match true runtime inference workloads.VABench Evaluation: SVG vs. Dense Attention
We evaluated SVG against dense attention on the Full VABench Benchmark suite (778 prompts across all 24 Easy/Hard bundles and 7 content categories) for LTX-2 synchronized text-to-audio-video (T2AV) generation at long sequence length (768 × 1280 × 241 frames,$N = 29,760$ video tokens, 10.04s @ 24 fps video + 24 kHz PCM audio) on 8× TPU v6e cores, followed by a 15-dimension VABench evaluation across 8× NVIDIA A100-80GB GPUs:
use_svg_attention=False,attention=ulysses_customuse_svg_attention=True,svg_spatial_density=0.25,attention=ulysses_custom1. TPU v6e-8 Generation Performance (
778 Videos @ 768 × 1280 × 241)2. 15-Dimension VABench Quality Highlights
Enabling SVG yields faster generation with zero quality regression, while improving audio-video synchronization and cross-modal alignment:
second_desyncsecond_lsaQwen2.5-Omni-7B):Full 15-Dimension VABench Comparison Table (
778 Prompts)first_dnsmossig_bak_ovr+p808)first_nisqafirst_audioboxsecond_viclipsecond_clapsecond_imagebindsecond_desyncsecond_lsaQwen2.5-Omni-7B)third_alignmentthird_audio_realitythird_visual_realitythird_expressivenessthird_artistryfourth_qa_audiofourth_qa_visionConfiguration Example
To enable SVG on LTX-2, add the following to
ltx2_video.ymlor override via CLI flags:Testing
Run the LTX-2 SVG unit tests from the repository root:
All existing Wan and LTX-2 unit tests continue to pass.
Note: This PR also includes minor
pyink==23.10.0formatting fixes inaot_cache.py,aot_cache_test.py,wan_pipeline.py, andsvg_attention_test.py(introduced in #480) because the CI Linter workflow runspyink src/maxdiffusion --checkacross theentire repo rather than only changed files.