[TRTLLM-13371][perf] LTX-2 FA4: enable split-KV heuristic (num_splits=0) for low-occupancy cross-attn#15399
Conversation
…=0) for low-occupancy cross-attn The FA4 backend hardcoded num_splits=1 (one CTA per Q-tile x head). LTX-2's small-Q/large-KV audio cross-attn (video->audio: Q=126 audio tokens, K=15360 video tokens, head_dim=64) then launches only ~num_heads CTAs — a single SM wave that leaves most of B200's 148 SMs idle and is bound by each CTA's long K-reduction latency, so it does not scale with Ulysses. Passing num_splits=0 enables FA4's built-in split-KV (Flash-Decoding) heuristic: it splits the KV reduction across idle SMs and combines the partials via LSE. This cuts v2a cross-attn from ~120us to ~16us at 8-GPU Ulysses (~7x) and lets it scale, while being a no-op (heuristic returns 1 split) whenever the grid already saturates the SMs, so self-attn and large-Q paths are unchanged. The split-KV combine is LSE-weighted and numerically equivalent, so there is no precision impact. Signed-off-by: Yiyun Lu <55233584+luyiyun1021@users.noreply.github.com>
a3b006e to
0df59a9
Compare
📝 WalkthroughWalkthrough
ChangesFlashAttention 4 split-KV parameter
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsStopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a Comment |
|
/bot run --disable-fail-fast |
|
PR_Github #55442 [ run ] triggered by Bot. Commit: |
|
PR_Github #55442 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
/bot run --disable-fail-fast |
|
PR_Github #55651 [ run ] triggered by Bot. Commit: |
|
PR_Github #55652 [ run ] triggered by Bot. Commit: |
|
PR_Github #55651 [ run ] completed with state |
|
PR_Github #55652 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #55691 [ run ] triggered by Bot. Commit: |
|
PR_Github #55691 [ run ] completed with state |
…=0) for low-occupancy cross-attn (NVIDIA#15399) Signed-off-by: Yiyun Lu <55233584+luyiyun1021@users.noreply.github.com>
Description
The visual-gen FlashAttention-4 backend (
flash_attn4.py) called_flash_attn_fwd(...)with the library defaultnum_splits=1— one CTA per (Q-tile × head). For LTX-2's small-Q / large-KV audio cross-attn (video→audio: Q=126 audio tokens, K=15360 video tokens, head_dim=64) that launches only ~num_headsCTAs: a single SM wave that leaves most of a B200's 148 SMs idle and is bound by each CTA's long K-reduction, so it does not scale with Ulysses.This one-line change passes
num_splits=0, enabling FA4's built-in split-KV (Flash-Decoding) heuristic: it splits the KV reduction across the idle SMs and combines the partials via LSE. The heuristic returns 1 split whenever the grid already saturates the SMs, so self-attn and other large-Q paths are a no-op (unchanged). The split-KV combine is LSE-weighted and algebraically equivalent to the unsplit softmax, so there is no precision impact — only float re-association noise.Test Coverage
Kernel microbench (single attention, B200, µs, mean over 50 iters)
Real LTX-2 shapes, per Ulysses rank (uly N → 32/N heads/rank, video full seq 15360, audio 126, text 1024).
cuDNN pad= audio padded >128 to leave the SM80 fallback (the alternative fix);FA4 ns=1= current library default (no split, i.e. not passingnum_splits);FA4 ns=0= this PR (auto split-KV heuristic).Ulysses=1 (32 heads/rank):
Ulysses=2 (16 heads/rank):
Ulysses=4 (8 heads/rank):
num_splits=0collapses the v2a bottleneck by 3.1× / 5.3× / 7.5× (124.6→40.8 / 123.6→23.3 / 123.7→16.5 µs at uly 1/2/4) — well below both cuDNN variants — modestly helps audio_text, and stays within noise (no-op) on every large-Q path (video_self/text, a2v, audio_self) where the grid already saturates the SMs. No regression.End-to-end LTX-2
Single-stage, 768×1280, 121 frames, 40 steps, guidance 4.0, B200, min-of-4 timed runs. FA4 backend with
num_splits=0vs the current VANILLA (cuDNN SDPA) default backend:num_splits=0The gain is largest at 8-GPU Ulysses, where the v2a cross-attn's non-scaling hurts the cuDNN path most. The change flips a single existing kernel argument to the library's auto-heuristic (no new code path); correctness is covered by the existing visual-gen LTX-2 attention/Ulysses unit tests under
tests/unittest/_torch/visual_gen/, and the split-KV combine is LSE-exact.PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.