Skip to content

feat(ltx2): run LTX-2 video self-attention on SageAttention when enabled - #9664

Merged
lstein merged 13 commits into
invoke-ai:mainfrom
Pfannkuchensack:feat/sage-attention-ltx2
Oct 16, 2026
Merged

lstein merged 13 commits into
invoke-ai:mainfrom
Pfannkuchensack:feat/sage-attention-ltx2

Conversation

@Pfannkuchensack

@Pfannkuchensack Pfannkuchensack commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Note

Stacked PR 7 of 8: merge after #9663. It targets main, so until the PRs before it merge, its diff also shows their commits and the merges that carry them forward. This PR's own changes are two commits, 9507eccfb6 (the scope) and b3c3e4300a (the audio result in the docs).

Summary

With attention_backend: sage, LTX-2 denoising enters the SageAttention scope from #9657. Its video self-attention runs on SageAttention; the audio attention is below the size threshold and the text cross-attention passes a mask, so both stay on PyTorch SDPA. The default auto is unchanged. The docs page lists LTX-2 under Supported models.

Related Issues / Discussions

Stacked on #9657 (SageAttention backend) and #9663, the PR before it.

QA Instructions

LTX-2.5 distilled int8, model loaded, three arms per seed as described in #9657:

1248×704, 121 frames
Step, default SDPA 5263 ms
Step, cuDNN-first SDPA 4726 ms
Step, SageAttention 4178 ms (−21 %)
Whole generation 72.0 → 63.4 s (−12 %)
Peak VRAM in the denoise scope unchanged
Per-frame LPIPS against default SDPA, median (cuDNN-first) 0.142 (0.090)
Flicker ratio against default SDPA 1.001
  • Per step, the 48 video self-attention calls run on SageAttention. Audio self-attention and the two audio–video cross-attentions (3 × 48) are below the size threshold, and the text cross-attention (2 × 48) passes a mask; all of these stay on SDPA. Dropping the text mask where it masks nothing is a possible follow-up.

  • Accuracy on real activations, every call of step 0 (130 calls): worst cosine 0.9993, relative L2 0.027.

  • Frames were compared per frame by LPIPS and by frame-to-frame flicker.

  • Audio. It reads the video through cross-attention, so it changes even though its own attention stays on SDPA. Measured with the code of this PR on 8 clips (4 prompts × 2 seeds, 1248×704, 121 frames; two prompts with clear sync events: four hand claps, a spoken sentence), against default SDPA, with cuDNN-first as the exact-kernel noise floor:

    SageAttention cuDNN-first (floor)
    Log-mel distance, median (max) 0.92 dB (1.58) 0.74 dB (1.36)
    Onset-envelope cosine, median 0.980 0.986
    Shift against the SDPA audio 0 ms in all 8 0 ms
    Loudness within ±0.2 dB within ±0.26 dB
    Clipping / silence none none

    Sync to the picture: on the clap and speech clips, motion and sound onsets correlate clearly (0.4–0.65), and the lag between them is identical in all three arms on every clip, so SageAttention does not move the sound against the picture. On the other two prompts there are no sync events to measure. Nobody listened to the clips; the numbers are the evidence.

  • At 1792×1024 all three arms ran out of memory on 24 GB without partial loading, so that size was not measured.

  • The timings and LPIPS come from the measurement prototype, which still used sageattn()'s default K smoothing; the selection feat(attention): add opt-in SageAttention backend for diffusion models #9657 ships is faster per call.

To try it: install SageAttention as the docs page from #9657 describes, set attention_backend: sage, restart and generate with LTX-2. The first generation logs SageAttention ... serves diffusion-model attention on cuda:0 (...) with the GPU and kernel name, and with log_level: debug every generation logs how many calls ran on SageAttention and why the others did not. With attention_backend: auto the output is bit-identical to main.

Checks: ruff clean; pytest tests/app/invocations passes with the whole stack applied (2090 passed). No call-site test was added: this change only enters the scope, whose behavior #9657 tests.

Review

Resolved: the audio was not compared at first. It now is (see QA), and the docs state the result.

Compatibility / Rollout

Merge after #9663. No API or persisted-state change; only attention_backend: sage behaves differently.

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Meaningful regression coverage added / updated where needed; obsolete tests/code removed
  • Persisted-state and API changes include required migrations / compatibility validation
  • Relevant performance/efficiency opportunities considered; material claims have evidence
  • Material review findings resolved and relevant checks rerun
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

With `attention_backend: sage`, SDXL denoising and tiled multi-diffusion enter the SageAttention scope; SD1.5 and SD2 do not.
RTX 4090: 4.4 s → 4.2 s at 1024², 19.6 s → 16.1 s at 2048², peak VRAM unchanged; a blind review judged no image worse.
With `attention_backend: sage`, LTX-2 denoising enters the SageAttention scope; video self-attention qualifies, while the masked text cross-attention and the short audio attention keep SDPA.
RTX 4090, LTX-2.5 distilled int8 at 1248×704, 121 frames: 72.0 s → 63.4 s, peak VRAM unchanged, no added flicker.
@github-actions github-actions Bot added python PRs that change python files invocations PRs that change invocations backend PRs that change backend files services PRs that change app services python-tests PRs that change python tests docs PRs that change docs labels Oct 3, 2026
The audio reads the video through cross-attention; against PyTorch's attention it changed no more than an exact kernel swap does, with no shift against the picture and the same loudness (8 clips, fixed seeds, clap and speech prompts included).
@Pfannkuchensack
Pfannkuchensack marked this pull request as ready for review October 12, 2026 20:44

@JPPhoto JPPhoto left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now fixed, thanks:

  • invokeai/app/invocations/ltx2/ltx2_denoise.py:620: the scope wraps joint denoising; invokeai/backend/ltx2/denoise.py:693 feeds both modalities through the transformer and uses both predictions. Changing video self-attention can therefore alter audio through cross-modal attention, despite audio attention itself staying on SDPA. The PR says its QA did not compare audio. Effect: Sage-enabled video/audio generations may produce degraded or desynchronized sound. Likelihood: normal when Sage is enabled for LTX-2. Recovery: set attention_backend: auto. Test: compare decoded audio quality and A/V sync against SDPA on fixed-seed clips; document the result in docs/src/content/docs/configuration/Optimization/sage-attention.mdx.

@JPPhoto
JPPhoto self-requested a review October 15, 2026 11:13

@JPPhoto JPPhoto left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

@lstein
lstein enabled auto-merge October 16, 2026 14:25
@lstein
lstein disabled auto-merge October 16, 2026 15:50
@lstein
lstein merged commit 6af5a65 into invoke-ai:main Oct 16, 2026
22 of 23 checks passed
lstein added a commit that referenced this pull request Oct 16, 2026
> [!NOTE]
> Stacked PR 8 of 8: merge after #9664. It targets `main`, so until the
PRs before it merge, its diff also shows their commits and the merges
that carry them forward. This PR's own changes are two commits,
[`cd6e58c52d`](Pfannkuchensack@cd6e58c)
(the scope) and
[`3d1a8b49f0`](Pfannkuchensack@3d1a8b49f0)
(the A14B measurements in the docs).

## Summary

With `attention_backend: sage`, Wan 2.2 denoising ("Denoise - Wan 2.2"
and "Denoise Video - Wan 2.2") enters the SageAttention scope from
#9657, so its eligible attention calls run on SageAttention. Everything
else stays on PyTorch SDPA, and the default `auto` is unchanged. The
docs page lists Wan 2.2 under Supported models.

## Related Issues / Discussions

Stacked on #9657 (SageAttention backend) and #9664, the PR before it.
Related: #9529, which asks for SageAttention to speed up Wan 2.2 A14B at
1280×720 on a 24 GB GPU. This PR does not close it: at that size a 24 GB
GPU is already full with PyTorch's attention, and SageAttention made it
slower (see QA). #9831 tracks that, together with Wan's missing
working-memory estimate.

## QA Instructions

Wan 2.2 TI2V-5B GGUF Q8 through "Denoise Video - Wan 2.2", model loaded,
three arms per seed as described in #9657:

|  | 1280×704, 121 frames |
| --- | --- |
| Step, default SDPA | 10419 ms |
| Step, cuDNN-first SDPA | 7890 ms |
| Step, SageAttention | 6358 ms (−39 %) |
| Whole generation | 380.9 → 247.9 s (−35 %) |
| Peak VRAM in the denoise scope | unchanged |
| Per-frame LPIPS against default SDPA, median (cuDNN-first) | 0.104
(0.079) |
| Flicker ratio against default SDPA | 0.998 |

- All 120 attention calls per step ran on SageAttention, including the
text cross-attention with 512 text tokens; none fell back.
- Accuracy on real activations, every call of step 0 (120 calls): worst
relative L2 0.076, in the text cross-attention; the heads with low
cosine there contribute almost nothing (output norm 0.08 against a
median of 5.7).
- **Wan 2.2 T2V A14B** (GGUF Q4_K_M, both experts, 4-step Lightning LoRA
V1.1, 81 frames, partial loading on, `device_working_mem_gb: 10`, which
A14B needs on 24 GB without SageAttention too, see #9831), denoising
only:

  | | Default SDPA | SageAttention | Peak VRAM |
  | --- | --- | --- | --- |
  | 832×480 | 121.5 s | 60.9 s (−50 %) | 18.0 / 18.1 GB |
  | 1280×720 | 293 s | 662 s (+126 %) | 24.1 / 24.0 GB |

At 1280×720 the GPU is already full with SDPA; SageAttention's quantized
copies (~1.2 GB more than SDPA per call) push it over, and Windows moves
memory to shared system memory instead of raising out-of-memory, so its
fallback never triggers. The docs row states both results.
- **"Denoise - Wan 2.2" (image):** TI2V-5B at 1280×704 compresses each
image to 880 tokens, below the 1536-token threshold, so all 2400 calls
of a measured generation stayed on SDPA.
- The timings and LPIPS come from the measurement prototype, which still
used `sageattn()`'s default K smoothing; the selection #9657 ships is
faster per call.

To try it: install SageAttention as the docs page from #9657 describes,
set `attention_backend: sage`, restart and generate with Wan 2.2. The
first generation logs `SageAttention ... serves diffusion-model
attention on cuda:0 (...)` with the GPU and kernel name, and with
`log_level: debug` every generation logs how many calls ran on
SageAttention and why the others did not. With `attention_backend: auto`
the output is bit-identical to `main`.

Checks: ruff clean; `pytest tests/app/invocations` passes with the whole
stack applied (2090 passed). No call-site test was added: this change
only enters the scope, whose behavior #9657 tests.

## Review

No material findings for this call site. Remaining: Wan 2.2 A14B at
1280×720 on a 24 GB GPU is slower with SageAttention (#9831).

## Compatibility / Rollout

Merge after #9664. No API or persisted-state change; only
`attention_backend: sage` behaves differently.

## Checklist

- [x] _The PR has a short but descriptive title, suitable for a
changelog_
- [ ] _Meaningful regression coverage added / updated where needed;
obsolete tests/code removed_
- [ ] _Persisted-state and API changes include required migrations /
compatibility validation_
- [x] _Relevant performance/efficiency opportunities considered;
material claims have evidence_
- [x] _Material review findings resolved and relevant checks rerun_
- [x] _Documentation added / updated (if applicable)_
- [ ] _Updated `What's New` copy (if doing a release after this PR)_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.0.0 backend PRs that change backend files docs PRs that change docs invocations PRs that change invocations python PRs that change python files python-tests PRs that change python tests services PRs that change app services

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants