Repository navigation
metal : add BF16 variant of the tensor API flash attention kernel - #30491
Merged
Merged
Conversation
ggerganov
reviewed
Oct 14, 2026
ggerganov
approved these changes
Oct 15, 2026
1 task done
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.
Overview
Follow-up to #29570 (#29570 (review)): add a BF16 variant of the tensor API FLASH_ATTN_EXT kernel, used with
-ctk bf16 -ctv bf16under the same conditions and thresholds as the F16 one.The kernel is templated on the Q/K/V/P type. Scores and output are still accumulated in
float: with abfloatP*V destination (BF16 += BF16 x BF16) the speed is the same and the KLD at 32K is ~100x higher (last row below). The tensor kernel and its F16/BF16 instances are now inkernels/fa_tensor.metal, which is only built intoggml-tensor.metallib, so the BF16 instances need noGGML_METAL_HAS_BF16guard.Additional information
M5 Pro (20-core GPU), master vs PR:
test-backend-ops -o FLASH_ATTN_EXT: 4978/4978, with new BF16 cases for head sizes 128, 192/128, 512, 576/512 and large logits (only 64 and 72 were covered).default.metallibhas no BF16 FA kernels).-fa off -ctk f32 -ctv f32half)bfloatP*V destinationRequirements