Skip to content

Conversation

justinchuby
Copy link
Contributor

@justinchuby justinchuby commented Oct 3, 2025

Updated enforcement conditions to allow any dimensional tensor with a single element according to the ONNX spec.

Fix #26218 Fix #26265

Updated enforcement conditions to allow any dimensional tensor with a single element according to the ONNX spec.
Copy link
Contributor

@Copilot Copilot AI left a comment

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 relaxes the previous restriction that the ConstantOfShape "value" attribute must be a 1-D tensor of size 1, aligning behavior with the ONNX spec allowing any shape as long as it contains exactly one element.

  • Removed hard enforcement of dims_size()==1 and dims()[0]==1
  • Added a comment indicating intent to allow any dimensional single-element tensor

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Signed-off-by: Justin Chu <[email protected]>
@justinchuby justinchuby changed the title Allow any dimensional tensor for ConstantOfShape Allow all single-element tensors as value for ConstantOfShape Oct 6, 2025
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
snnn
snnn previously approved these changes Oct 8, 2025
Copy link
Member

@snnn snnn left a comment

Choose a reason for hiding this comment

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

LGTM!

@snnn
Copy link
Member

snnn commented Oct 8, 2025

I agree with the suggestion to use a range-based for loop. Since we are using C++17, a range-based for loop would be more modern and readable than std::accumulate for calculating the product of dimensions.

For example:

int64_t size = 1;
for (auto dim : t_proto_p->dims()) {
    size *= dim;
}

This is also in line with suggestions from other reviewers.

Signed-off-by: Justin Chu <[email protected]>
snnn
snnn previously approved these changes Oct 8, 2025
yuslepukhin
yuslepukhin previously approved these changes Oct 9, 2025
Copy link
Member

@yuslepukhin yuslepukhin left a comment

Choose a reason for hiding this comment

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

:shipit:

Signed-off-by: Justin Chu <[email protected]>
edgchen1
edgchen1 previously approved these changes Oct 9, 2025
Signed-off-by: Justin Chu <[email protected]>
Copy link
Member

@yuslepukhin yuslepukhin left a comment

Choose a reason for hiding this comment

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

:shipit:

@justinchuby justinchuby merged commit 81ff69b into main Oct 9, 2025
92 checks passed
@justinchuby justinchuby deleted the justinchu/any-dim branch October 9, 2025 21:55
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.

Implement begin() and end() for struct int64s ConstantOfShape on scalar input

4 participants