-
Couldn't load subscription status.
- Fork 287
[Example] Optimize sink attention forward via swizzled layout and report benchmark results #885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
025d172
Enhance attention sink examples with swizzled layout and performance …
Rachmanino 7f90f4d
Add README for Attention Sink example with algorithm details and benc…
Rachmanino 3d8cb7e
Update README.md for Attention Sink example to include link to Triton…
Rachmanino 7e75150
Update examples/attention_sink/README.md
Rachmanino 5ddcd7f
Update examples/attention_sink/example_gqa_sink_fwd_bhsd_wgmma_pipeli…
Rachmanino 08c0bf8
typo
Rachmanino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Attention Sink | ||
|
|
||
| We compare with an optimized version of the official Triton implementation at [here](https://github.com/openai/gpt-oss/blob/main/gpt_oss/triton/attention.py). | ||
|
|
||
|
|
||
| ## Algorithm | ||
| ### Forward | ||
| The only change from vanilla FlashAttention is that `sinks` should be taken into consideration in the softmax, which requires an extra rescaling at the epilogue stage. | ||
|
|
||
| ### Backward | ||
| Based on detailed mathematical derivation, interestingly, the backward computation process of `dQ`, `dK`, `dv` is almost identical to that in vanilla FlashAttention, except for that the specific meanings of `lse` differ. We only need to compute `dsinks` additionally, which is given by: | ||
|
|
||
| $$ | ||
| dsink_h=-\sum_{b}\sum_{q}P_{b, h, q}Delta_{b, h, q} | ||
| $$ | ||
|
|
||
| where $P_{b, h, q}$ is the proportion of $sink_h$ in the softmax in the $b$-th block, $h$-th head and $q$-th query(row). | ||
|
|
||
| ## Benchmark of forward process | ||
|
|
||
| ### Benchmark Environment | ||
| - **Hardware**: NVIDIA H800 | ||
| - **CUDA version**: 12.9 | ||
| - **Triton Version**: 3.4.0 | ||
|
|
||
| ### Results | ||
|
|
||
| - dtype=float16 | ||
| - batch_size=1, heads=64, kv_heads=8 (the setting of GPT-OSS-120B) | ||
| - Full attention is adopted. | ||
|
|
||
| | SEQ_LEN | headdim | Triton TFLOPs | TileLang TFLOPs | Speedup | | ||
| |---------|---------|---------------|----------------------|---------| | ||
| | 2048 | 64 | 231.55 | **277.07** | 1.20x | | ||
| | 2048 | 128 | 313.55 | **393.98** | 1.26x | | ||
| | | | | | | | ||
| | 4096 | 64 | 272.17 | **337.30** | 1.24x | | ||
| | 4096 | 128 | 356.35 | **461.54** | 1.30x | | ||
| | | | | | | | ||
| | 8192 | 64 | 289.93 | **353.81** | 1.22x | | ||
| | 8192 | 128 | 392.18 | **482.50** | 1.23x | | ||
| | | | | | | | ||
| | 16384 | 64 | 299.52 | **377.44** | 1.26x | | ||
| | 16384 | 128 | 404.64 | **519.02** | 1.28x | | ||
|
|
||
| > The backward performance will be further optimized via fine-grained manual pipelining of FA3 in the tilelang kernel. |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.