Implement flash decoding
Open
@bdevorem is already working on this.
Since Sep 29, 2025.
- Dominant language
- C++
- Stars
- 333
- Forks
- 150
- Avg merge
- 4d 19h
- Merged PRs (30d)
- 54
Description
Implement flash decoding as described here: https://pytorch.org/blog/flash-decoding/
We have attention operators grouped like this:
Q -> [B, M, k]
K -> [B, k, N]
V -> [B, N, D]
S = dot(Q, K)
P = softmax(S)
O = dot(P, V) # [B, M, D]
To do flash decoding we will need to add another batch dimension for each group we want to split, and then do:
Q -> [B, G, M, k] # G is a broadcasted dimension
K -> [B, G, k, N/G]
V -> [B, G, N/G, D]
# first kernel
S = dot(Q, K)
P = softmax(S, axis=-1)
L = LSE(S) # [B, G, M, 1]
O' = dot(P, V) # [B, G, M, D]
# second kernel
scale = softmax(L, axis=1) # [B, G, M, 1]
R = mul(O', broadcast(scale)) # [B, G, M, D]
O = sum(R, axis=1) # [B, 1, M, D]
We will probably do this directly in the fuse_attention pass after we have done the initial attention grouping.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.