Skip to content
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

Animations for Flash Attention, Flash Attention2, and Standard Attention #736

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ def flash_attn_with_kvcache(
To see how these functions are used in a multi-head attention layer (which
includes QKV projection, output projection), see the MHA [implementation](https://github.com/Dao-AILab/flash-attention/blob/main/flash_attn/modules/mha.py).

## FlashAttention and FlashAttention2 Animations

Explore the inner workings of attention mechanisms with this animated series! These visualizations illustrate the implementation of three attention algorithms, Standard Attention, Flash Attention, and Flash Attention 2. For short sequences, the animations provide an intuition for the algorithms. As the sequence length increases, it becomes evident that, asymptotically, both Flash Attention and Flash Attention 2 exhibit superior IO performance.

| Sequence Length | Standard Attention | Flash Attention | Flash Attention 2 |
| --- | -------- | -------- | -------- |
| Short | <a href="https://www.youtube.com/watch?v=-EF-KIscwJw"> <img src="https://img.youtube.com/vi/-EF-KIscwJw/0.jpg" alt="Standard Attention on Short Sequence Length" width="200" height="auto"> </a> | <a href="https://www.youtube.com/watch?v=cq3jQ-Bbmzs"> <img src="https://img.youtube.com/vi/cq3jQ-Bbmzs/0.jpg" alt="Flash Attention on Short Sequence Length" width="200" height="auto"> </a> | <a href="https://www.youtube.com/watch?v=fevDHL1scYE"> <img src="https://img.youtube.com/vi/fevDHL1scYE/0.jpg" alt="Flash Attention 2 on Short Sequence Length" width="200" height="auto"> </a> |
| Medium | <a href="https://www.youtube.com/watch?v=82czr_lbkpk"> <img src="https://img.youtube.com/vi/82czr_lbkpk/0.jpg" alt="Standard Attention on Medium Sequence Length" width="200" height="auto"></a>| <a href="https://www.youtube.com/watch?v=KLWn1cZQE64"> <img src="https://img.youtube.com/vi/KLWn1cZQE64/0.jpg" alt="Flash Attention on Medium Sequence Length" width="200" height="auto"> </a> | <a href="https://www.youtube.com/watch?v=gvTNH2k3iGk"> <img src="https://img.youtube.com/vi/gvTNH2k3iGk/0.jpg" alt="Flash Attention 2 on Medium Sequence Length" width="200" height="auto"> </a> |
| Long | <a href="https://www.youtube.com/watch?v=ofetLDziJfo"> <img src="https://img.youtube.com/vi/ofetLDziJfo/0.jpg" alt="Standard Attention on Long Sequence Length" width="200" height="auto"> </a> | <a href="https://www.youtube.com/watch?v=rGt7jGbAnOQ"> <img src="https://img.youtube.com/vi/rGt7jGbAnOQ/0.jpg" alt="Flash Attention on Long Sequence Length" width="200" height="auto"> </a> | <a href="https://www.youtube.com/watch?v=ySOZtZblhK4"> <img src="https://img.youtube.com/vi/ySOZtZblhK4/0.jpg" alt="Flash Attention 2 on Long Sequence Length" width="200" height="auto"> </a> |


## Changelog

### 2.0: Complete rewrite, 2x faster
Expand Down