[Kernels] Fix UInt32 overflow in flash attention benchmark FLOP count#6623
Open
gabrieldemarmiesse wants to merge 1 commit into
Open
[Kernels] Fix UInt32 overflow in flash attention benchmark FLOP count#6623gabrieldemarmiesse wants to merge 1 commit into
gabrieldemarmiesse wants to merge 1 commit into
Conversation
BEGIN_PUBLIC [Kernels] Fix UInt32 overflow in flash attention benchmark FLOP count The FLOP accounting in bench_kv_cache_ragged_flash_attention computed `4 * num_q_heads * (cache+seq) * seq * head_dim` entirely in UInt32 before casting to Int. At large shapes this intermediate exceeds 2^32 and wraps around, reporting a bogus throughput (e.g. exactly 0.0 GFLOPS/s when the product lands on a multiple of 2^32). Compute the product in Int so the FLOP count no longer overflows. Small (decode) shapes are unaffected; large (prefill) shapes now report correct throughput. END_PUBLIC Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Gabriel <[email protected]>
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.
Type of change
Motivation
What changed
bench_kv_cache_ragged_flash_attention computed 4 * num_q_heads * (cache+seq) * seq * head_dim in UInt32 before casting to Int. At large shapes this intermediate exceeds 2³² and wraps, reporting bogus throughput — e.g. a bs=8, seq=2048, cache=2048 prefill landed exactly on a multiple of 2³² and printed 0.0 GFLOPS/s.
Testing
After the fix the same shape reports ~529 TFLOP/s (~53% of H100 bf16 peak); decode shapes (small products, never overflowed) are unchanged.
Checklist
agreed-upon, or this is a trivial fix that does not need prior
approval
smaller PRs where possible (see
pull request sizes)
./bazelw run formatto format my changesAssisted-by:trailer in my commit message or this PR description (seeAI Tool Use Policy)
Assisted-by Claude