[CPU] Tighten cache_indirection shape contract in MultiHeadAttention - #31634
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens the CPU input validation contract for cache_indirection in the contrib-domain MultiHeadAttention helper logic, and adds regression tests to ensure inconsistent batch_beam_size/num_beams shapes are rejected early.
Changes:
- Strengthen
cache_indirectionshape validation to requirenum_beamsto evenly dividebatch_beam_size, and to reject inconsistent dim-0 values. - Add CPU-negative tests for both
MultiHeadAttentionandDecoderMaskedMultiHeadAttentioncovering the “batch_beam_size not divisible by num_beams” case. - Improve the diagnostic error message for the dim-0 mismatch case to include the relevant dimensions and
batch_beam_size.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| onnxruntime/test/contrib_ops/multihead_attention_op_test.cc | Adds a CPU failure test for inconsistent cache_indirection shape when batch_beam_size % num_beams != 0. |
| onnxruntime/test/contrib_ops/decoder_masked_multihead_attention_op_test.cc | Adds the analogous CPU failure test for DecoderMaskedMultiHeadAttention. |
| onnxruntime/contrib_ops/cpu/bert/multihead_attention_helper.h | Tightens CheckCacheIndirection validation and updates the dim-0 mismatch error message. |
Nenad Banfic (nenad1002)
enabled auto-merge (squash)
August 5, 2026 23:08
Tianlei Wu (tianleiwu)
approved these changes
Aug 5, 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
[CPU] Tighten cache_indirection shape contract in MultiHeadAttention
Motivation and Context