Skip to content

[Fix] CommReduce could handle 0-dim data#19683

Open
flashmouse wants to merge 1 commit into
apache:mainfrom
flashmouse:issue-18676
Open

[Fix] CommReduce could handle 0-dim data#19683
flashmouse wants to merge 1 commit into
apache:mainfrom
flashmouse:issue-18676

Conversation

@flashmouse
Copy link
Copy Markdown

@flashmouse flashmouse commented Jun 8, 2026

This PR try to fix #19676 , allow CommReduce handle 0-dim data correctly.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes a crash when reducing a 0-dimensional (scalar) tensor by returning its identity instead of throwing an error, and adds a corresponding regression test. The reviewer pointed out that when ndim == 0 and atleast1d is true, the output tensor should be expanded to at least 1-dimensional (e.g., shape [1]) using topi::expand_dims rather than returning the 0-dimensional identity directly.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +187 to +189
if (ndim == 0) {
return topi::identity(data, data->op->name + "_red", kCommReduce);
}
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.

medium

When ndim == 0 and atleast1d is true, the output tensor should be at least 1-dimensional (i.e., shape [1]). However, returning topi::identity directly ignores the atleast1d flag and returns a 0-dimensional tensor. We should wrap the identity tensor with topi::expand_dims if atleast1d is enabled.

Suggested change
if (ndim == 0) {
return topi::identity(data, data->op->name + "_red", kCommReduce);
}
if (ndim == 0) {
auto identity = topi::identity(data, data->op->name + "_red", kCommReduce);
return atleast1d ? topi::expand_dims(identity, 0, 1) : identity;
}

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.

[Bug] InternalError "Cannot reduce a 0 dim Tensor" when compiling a reduction over a 0-D (scalar) tensor

1 participant