-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make elementwise_op supporting scalar input Y
#7593
Make elementwise_op supporting scalar input Y
#7593
Conversation
… dev_elementwise_max_min
… dev_elementwise_max_min
// y is a scalar | ||
auto extended_dims = framework::vectorize(x_dims); | ||
extended_dims.push_back(1); | ||
x_dims = framework::make_ddim(extended_dims); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, axis
should be x->dims().size()
, otherwise, it is wrong.
So I think this section of the code should be like this:
int axis = ctx.Attr<int>("axis");
axis = (axis == -1 ? x_dims.size() - y_dims.size() : axis);
if (y_dims.size() == 1 && y_dims[0] == 1) {
// y is a scalar
axis = x_dims.size();
auto extended_dims = framework::vectorize(x_dims);
extended_dims.push_back(1);
x_dims = framework::make_ddim(extended_dims);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite agree with that. If the axis
is inconsistent with the actual data shape, the code shall give an error instead of modifying axis
in silence. Because we can never know which one is wrong, the axis
or the data shape.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR is large. I think it's better to split Thanks @JiayiFeng, for the support that argument Y can be a scalar. |
@gongweibao |
solve #7568