Use dynamic shape storage in BeamSearch ExpandBuffer - #32009
Merged
Akshay Sonawane (apsonawane) merged 1 commit intoAug 13, 2026
Merged
Conversation
Akshay Sonawane (apsonawane)
requested review from
Tianlei Wu (tianleiwu)
and
a lite review from Copilot
August 12, 2026 05:35
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 12, 2026 05:35
View session
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
August 12, 2026 05:37
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the CPU generation helper’s ExpandBuffer implementation to handle tensors with rank > 4 by switching from a fixed-size dimension array to a dynamically sized TensorShapeVector, and adds a unit test to validate the new behavior in Beam Search test coverage.
Changes:
- Refactor
GenerationCpuDeviceHelper::ExpandBufferto build the expanded shape from a dynamically sizedTensorShapeVector. - Add a new test
ExpandBufferSupportsRankGreaterThanFourto verify shape expansion for 5D inputs. - Include
generation_device_helper.hin the Beam Search test to accessExpandBuffer.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
onnxruntime/contrib_ops/cpu/transformers/generation_device_helper.cc |
Replaces fixed dims[4] shape storage with a dynamic TensorShapeVector to support high-rank tensors in ExpandBuffer. |
onnxruntime/test/contrib_ops/beam_search_test.cc |
Adds a focused unit test ensuring ExpandBuffer correctly expands the batch dimension for rank > 4 tensors. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ti-Tai Wang (titaiwangms)
approved these changes
Aug 13, 2026
Akshay Sonawane (apsonawane)
deleted the
fix/beamsearch-expandbuffer-dynamic-shape
branch
August 13, 2026 17:52
This was referenced Sep 10, 2026
Open
This was referenced Sep 14, 2026
Open
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.
This pull request improves the
ExpandBufferfunction in the generation device helper to better support tensors with rank greater than four, and adds a new test to verify this behavior. The main changes are as follows:Support for high-rank tensors in
ExpandBuffer:ExpandBufferimplementation ingeneration_device_helper.ccto use a dynamicTensorShapeVectorinstead of a fixed-size array, allowing support for input tensors with more than four dimensions.Testing enhancements:
ExpandBufferSupportsRankGreaterThanFour, tobeam_search_test.ccto ensure thatExpandBuffercorrectly handles tensors with rank greater than four.generation_device_helper.hin the test file.