Refactor FP16 softmax buffer size into testable helper; replace expensive regression test#27829
Closed
Copilot wants to merge 3 commits intoedgchen1/fix_attention_softmax_overflowfrom
Closed
Refactor FP16 softmax buffer size into testable helper; replace expensive regression test#27829Copilot wants to merge 3 commits intoedgchen1/fix_attention_softmax_overflowfrom
Copilot wants to merge 3 commits intoedgchen1/fix_attention_softmax_overflowfrom
Conversation
Co-authored-by: edgchen1 <18449977+edgchen1@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/onnxruntime/sessions/9c8c83e9-86ca-4f72-bc68-d5f8d113160d
…etection comment Co-authored-by: edgchen1 <18449977+edgchen1@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/onnxruntime/sessions/9c8c83e9-86ca-4f72-bc68-d5f8d113160d
Copilot
AI
changed the title
[WIP] [WIP] Address feedback on fix CPU attention overflow issue PR
Refactor FP16 softmax buffer size into testable helper; replace expensive regression test
Mar 24, 2026
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.
Description
Addresses reviewer feedback on #27822: the regression test for the FP16 softmax integer overflow was allocating multi-GB buffers and running a ~2.1B-element attention computation, making it unsuitable for CI.
attention.h— extractdetail::Fp16SoftmaxTempBufferBytes:SafeInt<size_t>(n) * d * sizeof(float)computation (the exact fix for the overflow bug) in a single, directly testable unitattention.cc—ComputeAttentionSoftmaxInplace<MLFloat16>:detail::Fp16SoftmaxTempBufferBytes(N, D)for the allocation size instead of an inlineSafeIntexpressionattention_op_test.cc— replaceAttentionCpuFp16SoftmaxLargeDimensions:AttentionCpuFp16SoftmaxBufferSizeNoOverflowcalls the helper directly with N=D=46341 (same dimensions that triggered the original int32 overflow) and asserts the result equalsN * D * sizeof(float)— no tensor allocation, no op execution, runs in microsecondssystem_info.hdependencysizeof(void*) < 8), asserts thatSafeIntcorrectly throws onsize_toverflowMotivation and Context
The original regression test exercised correctness of the full attention path at huge dimensions, but the real bug was a single integer overflow in the buffer size calculation. Isolating that calculation into a helper makes the regression test fast, reliable, and directly tied to the fixed code.
Original PR: #27822
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.