cpu: introduce chunking for flash attention#16829
Merged
ggerganov merged 1 commit intoggml-org:masterfrom Oct 30, 2025
Merged
Conversation
Factor out the core FA loop into flash_atten_f16_one_chunk and add an outter loop on top that handles the chunks.
Member
Author
|
@slaren this one as well along with the matmul chunking |
Member
|
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
Member
|
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
|
Anico2
added a commit
to Anico2/llama.cpp
that referenced
this pull request
Jan 15, 2026
Factor out the core FA loop into flash_atten_f16_one_chunk and add an outter loop on top that handles the chunks.
blime4
referenced
this pull request
in blime4/llama.cpp
Feb 5, 2026
Factor out the core FA loop into flash_atten_f16_one_chunk and add an outter loop on top that handles the chunks.
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
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).
Details
I'm going to submit a couple more related PRs:
chunk_size = nrows / (n_threads * 4)for the Repack MatMuls.