Repository navigation
Add Sparse VideoGen attention for Wan on TPUs - #480
Merged
copybara-service[bot] merged 1 commit intoSep 24, 2026
Merged
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements Sparse VideoGen (SVG) attention on TPUs for Wan in MaxDiffusion, introducing modules for routing, token placement, and kernel execution. The review feedback highlights several critical issues to address: potential TypeError and AttributeError crashes in the pipeline and attention configuration logic, possible NaN propagation bugs in the attention kernels when all keys are masked out, a missing divisibility check in the Pallas partial kernel, and opportunities to optimize compilation by statically checking step_index.
Perseus14
reviewed
Sep 15, 2026
Perseus14
left a comment
Collaborator
There was a problem hiding this comment.
Added some minor comments. PTAL
Perseus14
previously approved these changes
Sep 21, 2026
jitendra-jalwaniya
previously approved these changes
Sep 21, 2026
Collaborator
|
@Ravi-VK Please squash the commits |
mbohlool
requested changes
Sep 21, 2026
Ravi-VK
dismissed stale reviews from jitendra-jalwaniya and Perseus14
via
September 22, 2026 11:39
74f46de
Ravi-VK
force-pushed
the
svg-head-local-pr-clean
branch
from
September 22, 2026 11:39
446bd95 to
74f46de
Compare
jitendra-jalwaniya
requested review from
jitendra-jalwaniya
and removed request for
jitendra-jalwaniya
September 22, 2026 11:42
jitendra-jalwaniya
approved these changes
Sep 22, 2026
Ravi-VK
force-pushed
the
svg-head-local-pr-clean
branch
from
September 22, 2026 12:10
74f46de to
fa7c1ba
Compare
Implement opt-in SVG attention for Wan inference with per-head spatial and temporal routing, head-local token layouts, and TPU sparse-attention kernels. Round sparse support to hardware tiles while preserving the approximate pair budget, retain valid support for every query, and use a padding-only cleanup path for sequence tails. Add configuration and scheduling controls, distributed inference integration, cache and unsupported-mode guards, AOT cache identity handling, documentation, and CPU/TPU regression coverage.
Ravi-VK
force-pushed
the
svg-head-local-pr-clean
branch
from
September 22, 2026 12:46
fa7c1ba to
db8c0cd
Compare
mbohlool
approved these changes
Sep 23, 2026
copybara-service
Bot
merged commit Sep 24, 2026
389fff5
into
AI-Hypercomputer:main
15 of 16 checks passed
This was referenced Sep 28, 2026
jitendra-jalwaniya
added a commit
that referenced
this pull request
Oct 12, 2026
Expose Sparse VideoGen (SVG) attention for LTX-2 end to end. SVG is off
by default and only active when use_svg_attention is set and
svg_spatial_density < 1.0 (svg_attention_enabled()).
- ltx2_pipeline.py: pass the denoising step index (svg_step_index)
through both the scanned and unscanned diffusion loops. Only add svg_*
keys to the transformer attention_config when SVG is active; otherwise
pass {"use_svg_attention": False}, so unused SVG settings never reach
the model graph. Reject SVG combined with CFG cache or MagCache only
when SVG is active. svg_num_layers defaults to 48.
- ltx2_video.yml, ltx2_3_video.yml: add all SVG options (disabled by
default) and svg_flash_block_sizes for the sparse kernel tiling, and
expose enable_vae_tiling / enable_vae_slicing (already read by
generate_ltx2.py) for command-line override. The Wan-only
svg_{high,low}_noise_density settings are not used by LTX-2.
- generate_ltx2.py: key the AOT cache on SVG settings, including those in
the transformer attention_config, only when SVG is active.
- docs/svg.md: SVG-on-TPU documentation for Wan and LTX-2, with its
figures (docs/images/svg/, taken unchanged from PR #480), a copyable
LTX-2 example and a note on profiler_steps vs the SVG window.
- Tests: config propagation, density-1.0 fallback, svg_step_index
forwarding, svg_attention_enabled(), AOT cache identity, and a
real-model check that the AOT graph signature is identical across
unused svg_* overrides and at svg_spatial_density=1.0.
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.
Video diffusion processes long sequences of video tokens across many denoising steps, making self-attention expensive. Sparse attention reduces this cost by skipping interactions that contribute little to the output.
This PR introduces an opt-in sparse attention implementation for MaxDiffusion: Sparse VideoGen (SVG) for Wan on TPUs. SVG samples a few queries to choose a spatial or temporal pattern for each head, then computes only the selected mask. Density and active steps/layers are configurable, and SVG is disabled by default.
See SVG.md for an illustrated explanation, configuration examples, and profiling instructions.
The implementation rounds sparse boundaries to hardware tiles, approximately preserving the attention-pair budget. Selected interior tiles share one mask-free kernel; only tiles touching sequence padding need validity masks.
The feature is organized into six commits:
A review follow-up adds configuration and shape guards, a static inactive-step shortcut, and regression tests.
Wan2.2 720p results on TPU v6e-8, using 81 frames and 40 denoising steps:
Timings are medians of three warm runs against same-node optimized fixed-M dense controls. PSNR uses FFmpeg’s aggregate YUV metric against dense outputs.
In an earlier evaluation using the moderate SVG policy, Wan2.2 at 720p retained 98.1% of the dense baseline’s mean VBench dimension score across a 31-prompt, 16-dimension screening subset.
SVG supports inference through the custom Ulysses/ring backends; training, Animate, external masks, periodic support, chunked Ulysses, CFG cache, and MagCache are unsupported.