mirror of
https://github.com/Comfy-Org/comfy-kitchen.git
synced 2026-11-04 23:37:42 +00:00
[GH-ISSUE #177] int8_attention: masked path costs ~1.8x unmasked, and a request for optional return_lse #55
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/comfy-kitchen#55
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @shootthesound on GitHub (Sep 14, 2026).
Original GitHub issue: https://github.com/Comfy-Org/comfy-kitchen/issues/177
We run banded attention over long MiniMax H3 videos: the sequence is a packed
[text | refs | audio | video]layout of up to ~266k rows, and each block of queries attends only to the keys inside a time window around it. Windows overlap, and the edge of each window carries a raised-cosine fade — a per-key additive bias,0.0across the core and falling tolog(1e-4)across the skirt. So every call passes anattn_maskof shape[1, 1, 1, K]: one value per key, constant across heads and queries.The measurement
4096 queries × 33,600 keys, 56 heads of 128, bf16 in, RTX 5090. Two runs, both shown:
[1,1,1,K][1,1,1,K][1,1,1,K][1,1,Q,K](expanded)[1,1,1,K]For contrast, the same bias costs
F.scaled_dot_product_attention1.05–1.21× on the same shapes. So masked int8 is still comfortably faster than masked SDPA — it just gives back about half of its advantage.Two things we noticed, offered as observations rather than a diagnosis, since we have not looked inside the kernel:
[1,1,1,K]and[1,1,Q,K]are indistinguishable, so the stride-0 view does not appear to be exploited today.Question 1
Is ~1.8× the expected cost of the masked path, or is there a cheaper route we are missing for the common "one additive bias per key, shared across heads and queries" case? That shape seems likely to recur — sliding-window and banded attention, ALiBi-style position biases, and soft-edged local attention all produce it.
Question 2: would you consider
return_lseonint8_attention?The reason is specific. The natural way to avoid the masked path is to split each window in two — the core with no mask, the skirt with one — and merge the partial softmaxes. Measured on the same shapes, that would be worth 1.38–1.41×:
But merging two softmaxes exactly requires each call's log-sum-exp, and
int8_attentionreturns only the output. The online-softmax normaliser already exists inside the kernel; an optional flag to write it out would make this exact rather than approximate.We would rather not approximate it — this path is quality-sensitive — so for now we take the masked cost.
sageattnexposesreturn_lsefor comparison, though it takes noattn_mask, so neither library can do the split alone today.Happy to test any branch on a 5090 against a real workload and report back.
Repro
Environment
comfy-kitchen0.2.31 · RTX 5090, driver 616.86 · torch 2.9.1+cu130 · Python 3.10 · Windows 11