Skip to content

[CPU] Tighten cache_indirection shape contract in MultiHeadAttention - #31634

Merged
Nenad Banfic (nenad1002) merged 2 commits into
mainfrom
nebanfic/multihead-attention-fix
Aug 5, 2026
Merged

[CPU] Tighten cache_indirection shape contract in MultiHeadAttention#31634
Nenad Banfic (nenad1002) merged 2 commits into
mainfrom
nebanfic/multihead-attention-fix

Conversation

@nenad1002

Copy link
Copy Markdown
Contributor

Description

[CPU] Tighten cache_indirection shape contract in MultiHeadAttention

Motivation and Context

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_indirection shape validation to require num_beams to evenly divide batch_beam_size, and to reject inconsistent dim-0 values.
  • Add CPU-negative tests for both MultiHeadAttention and DecoderMaskedMultiHeadAttention covering 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.

Comment thread onnxruntime/contrib_ops/cpu/bert/multihead_attention_helper.h Outdated
@nenad1002
Nenad Banfic (nenad1002) enabled auto-merge (squash) August 5, 2026 23:08
@nenad1002
Nenad Banfic (nenad1002) merged commit fbaee34 into main Aug 5, 2026
123 of 131 checks passed
@nenad1002
Nenad Banfic (nenad1002) deleted the nebanfic/multihead-attention-fix branch August 5, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants