Sage3 adds 2.3x slowdown on SD1.5 - Comfyui 0.21.1+
- Dominant language
- Python
- Stars
- 133k
- Forks
- 15.7k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 158
Description
### Custom Node Testing
- [x] I have tried disabling custom nodes and the issue persists (see [how to disable custom nodes](https://docs.comfy.org/troubleshooting/custom-node-issues#step-1%3A-test-with-all-custom-nodes-disabled) if you need help)
### Expected Behavior
skip behaviour
### Actual Behavior
## Results (SD1.5, 768×768; ms, from `/history` execution timestamps)
| sampler / steps | model-evals | no-sage | v1 | sage3 | **sage3 wasted per image** |
|---|---|---|---|---|---|
| euler / 10 | 10 | 845 | 1192 | 2384 | **+1.5 s** |
| euler / 20 | 20 | 1525 | 2134 | 4496 | **+3.0 s** |
| euler / 40 | 40 | 2536 | 3905 | 8800 | **+6.3 s** |
| dpmpp_2m / 20 | 20 | 1547 | 2134 | 4528 | **+3.0 s** |
| dpm_2 / 20 | 40 | 2583 | 3798 | 8501 | **+5.9 s** |
Overhead is constant **per model-eval** — v1 ≈ +31 ms, sage3 ≈ +150 ms — so it scales with eval count,
not the sampler (`dpm_2`@20 = 40 evals ≈ euler@40). "+150 ms" is per eval, not per image: a 20-step
image loses ~3 s, and across a session this is **minutes to hours wasted for zero quality difference**.
### Steps to Reproduce
(workflow img)
Launch with `--use-sage-attention3`, run any SD1.5 ckpt at 768×768 / 20 steps; observe per-call
`Error running SageAttention3 …` and ~2.3× slowdown vs no sage. Measured single-instance, model pre-
warmed, unique seed per run, same-seed outputs pixel-identical across backends.
ComfyUI 0.21.1 (Windows portable, `--windows-standalone-build`) · torch 2.11.0+cu130 · `sageattn3`
1.0.0 · `sageattention` 1.0.6 · Python 3.13.12 · RTX 5090 · Windows 10 Pro 10.0.19045.
### Debug Logs
```powershell
Error running sage attention: headdim should be in [64, 96, 128]., using pytorch attention instead.
```
### Other
## Cause
`comfy/ldm/modules/attention.py`, on **every** attention call for an unsupported head_dim:
- **sage3** does the full q/k/v reshape+contiguous copies, *then* attempts the kernel (raises), *then*
`logging.error(...)`, *then* falls back — repeated every call, never cached.
- **sage1** fails on a cheap early head_dim check (~5× less overhead), but also retries+logs every call.
## Fix
1. Bail to PyTorch up front when `head_dim ∉ {64,96,128}`, before the reshape/copies and kernel attempt.
2. Cache the failure per head_dim so it stops retrying and logging on every call.
Either helps; together they restore _no-sage_ diffusion speed
## Prior art
[#7352](https://github.com/Comfy-Org/ComfyUI/issues/7352) (closed — added the fallback but not caching;
post-close comments note the remaining slowdown/spam) · [commit e471c726](https://github.com/Comfy-Org/ComfyUI/commit/e471c726e57b3854e0dd47efe0e7c53a28703dbb) (the partial fix) · [PR #11026](https://github.com/Comfy-Org/ComfyUI/pull/11026) (added `attention3_sage`; no head_dim bailout / no caching).
Related, not fixes: [#6733](https://github.com/Comfy-Org/ComfyUI/issues/6733) (closed precursor —
the head_dim assertion crash) · [#11706](https://github.com/Comfy-Org/ComfyUI/issues/11706) (open —
sage3 CLI exposure) · [PR #11571](https://github.com/Comfy-Org/ComfyUI/pull/11571) (open — sage3 patch
node + warning) · [PR #9047](https://github.com/Comfy-Org/ComfyUI/pull/9047) (closed — early sage3 attempt).
_No open issue covers the per-call slowdown._
Contributor guide
Assessment
This issue has not been assessed yet.