-
Notifications
You must be signed in to change notification settings - Fork 13.5k
cpu: introduce chunking for flash attention #16829
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
Conversation
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
Factor out the core FA loop into flash_atten_f16_one_chunk and add an outter loop on top that handles the chunks.
|
@slaren this one as well along with the matmul chunking |
|
On a 13900k this also has an overall positive effect on performance when using a high number of threads.
|
slaren
approved these changes
Oct 30, 2025
|
M4 Max results: CMAKE_OPTS="-DGGML_METAL=OFF -DGGML_BLAS=OFF" ./scripts/compare-commits.sh master pr/16829 test-backend-ops -o FLASH_ATTN_EXT -b CPU
|
pockers21
pushed a commit
to pockers21/llama.cpp
that referenced
this pull request
Oct 31, 2025
Factor out the core FA loop into flash_atten_f16_one_chunk and add an outter loop on top that handles the chunks.
pockers21
pushed a commit
to pockers21/llama.cpp
that referenced
this pull request
Oct 31, 2025
Factor out the core FA loop into flash_atten_f16_one_chunk and add an outter loop on top that handles the chunks.
pockers21
pushed a commit
to pockers21/llama.cpp
that referenced
this pull request
Oct 31, 2025
Factor out the core FA loop into flash_atten_f16_one_chunk and add an outter loop on top that handles the chunks.
pockers21
pushed a commit
to pockers21/llama.cpp
that referenced
this pull request
Oct 31, 2025
Factor out the core FA loop into flash_atten_f16_one_chunk and add an outter loop on top that handles the chunks.
pockers21
pushed a commit
to pockers21/llama.cpp
that referenced
this pull request
Oct 31, 2025
Factor out the core FA loop into flash_atten_f16_one_chunk and add an outter loop on top that handles the chunks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A very simple dynamic Flash Attention chunking that splits the work into
n_threads * 4chunks.This helps on platforms with significant performance difference between the CPU cores (ie big.LITTLE, boosted cores, etc) and it helps under heavy CPU load. Very similar to what MatMul and MatMul-ID chunking already does.
Flash Attention is a relatively small part of the overall profile so the end-to-end token rate is not affected that much but if I run it in isolation I see a nice bump in performance on the Gen5.
Also tested on the M4 Pro where I don't see any performance changes on the unloaded system but the loaded system is a different story.
Here are some more details with additional instrumentation that measures how many chunks each thread processed and how long it took.
You can see how under load some threads process more chunks in about the same amount of time on the M4 Pro.
On the Gen5 you can see that one of the cores crunches through many more chunks than the other cores.
The picture is similar on the Gen4 (8-Elite).
I'm going to submit a couple more related PRs:
chunk_size = nrows / (n_threads * 4)for the Repack MatMuls.