Repository navigation
feat(krea2): run Krea-2 attention on SageAttention when enabled - #9662
Merged
lstein merged 12 commits intoOct 16, 2026
Merged
Conversation
With `attention_backend: sage`, Qwen-Image denoising enters the SageAttention scope. RTX 4090, Qwen-Image 2512 GGUF Q4_K_M: 78.8 s → 73.5 s at 1024², 208.9 s → 150.3 s at 2048², peak VRAM unchanged; a blind review judged no image worse.
With `attention_backend: sage`, Krea-2 denoising enters the SageAttention scope unless INVOKE_KREA2_SDPA_BACKEND pins a PyTorch kernel. RTX 4090, Krea-2 Turbo GGUF Q4_K_M: 11.5 s → 11.0 s at 1024², 42.7 s → 36.2 s at 2048², peak VRAM unchanged; a blind review judged no image worse.
This was referenced Oct 3, 2026
Pfannkuchensack
marked this pull request as ready for review
October 12, 2026 20:44
lstein
enabled auto-merge
October 16, 2026 13:13
lstein
added a commit
that referenced
this pull request
Oct 17, 2026
> [!NOTE] > Stacked PR 6 of 8: merge after #9662. 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 change is one commit, [`1968eb9c58`](Pfannkuchensack@1968eb9). ## Summary With `attention_backend: sage`, SDXL denoising and SDXL tiled multi-diffusion enter the SageAttention scope from #9657, so eligible attention calls run on SageAttention, including ControlNets that run inside the loop. SD1.5 and SD2 do not enter it: SD1.5's head sizes (40, 80, 160) never qualify, and SD2 is unmeasured. With `attention_type: sliced`, SDXL's attention does not go through SDPA, so nothing changes there. The default `auto` is unchanged. The docs page lists SDXL under Supported models and notes the sliced case. ## Related Issues / Discussions Stacked on #9657 (SageAttention backend) and #9662, the PR before it. ## QA Instructions SDXL, model loaded, three arms per seed as described in #9657: | | 1024² | 2048² | | --- | --- | --- | | Step, default SDPA | 134 ms | 631 ms | | Step, cuDNN-first SDPA | 135 ms | 579 ms | | Step, SageAttention | 126 ms (−6 %) | 496 ms (−21 %) | | Whole generation | 4.4 → 4.2 s (−5 %) | 19.6 → 16.1 s (−18 %) | | Peak VRAM in the denoise scope | unchanged | unchanged | | LPIPS against default SDPA, median (cuDNN-first) | 0.027 (0.015) | 0.014 (0.006) | - At 1024², 10 of the 140 attention calls per UNet pass qualify: the 4096-token self-attention of the outer blocks. The 1024-token self-attention of the inner blocks and all 77-token text cross-attention are below the break-even and stay on SDPA. At 2048² the inner blocks qualify too. - Blind side-by-side review: 7 of 8 pairs equal, 1 judged better with SageAttention. - Accuracy on real activations, every call of step 0 (10 calls): cosine 1.0000, relative L2 0.003. - The timings, LPIPS and blind review 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 SDXL. 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 scope first opened for every UNet base, including the unmeasured SD2; it now opens for SDXL only. ## Compatibility / Rollout Merge after #9662. 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)_
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.
Note
Stacked PR 5 of 8: merge after #9661. 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 change is one commit,482e7f348f.Summary
With
attention_backend: sage, Krea-2 denoising enters the SageAttention scope from #9657, so its eligible attention calls run on SageAttention; its grouped-query attention (48 query and 12 K/V heads) runs natively, without expanding K/V. WhileINVOKE_KREA2_SDPA_BACKENDpins a PyTorch kernel for measurement, the scope stays closed so the pinned kernel is what runs. The defaultautois unchanged. The docs page lists Krea-2 under Supported models.Related Issues / Discussions
Stacked on #9657 (SageAttention backend) and #9661, the PR before it.
QA Instructions
Krea-2 Turbo GGUF Q4_K_M, model loaded, arms as described in #9657:
To try it: install SageAttention as the docs page from #9657 describes, set
attention_backend: sage, restart and generate with Krea-2. The first generation logsSageAttention ... serves diffusion-model attention on cuda:0 (...)with the GPU and kernel name, and withlog_level: debugevery generation logs how many calls ran on SageAttention and why the others did not. Withattention_backend: autothe output is bit-identical tomain.Checks: ruff clean;
pytest tests/app/invocationspasses 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: with
INVOKE_KREA2_SDPA_BACKENDset, SageAttention served the calls the override was meant to measure; the scope now stays closed while it is set.Compatibility / Rollout
Merge after #9661. No API or persisted-state change; only
attention_backend: sagebehaves differently.Checklist
What's Newcopy (if doing a release after this PR)