-
Notifications
You must be signed in to change notification settings - Fork 5.9k
【SCU】【Paddle Tensor 第二期 API 支持 0-size TensorNo.25、47】paddle.tensordot 支持 0-size Tensor #70238
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
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
|
其中好像还会涉及到sum,这里在等这个PR合入:#70146 |
| if (x.numel() == 0 || y.numel() == 0) { | ||
| auto x_dims = x.dims(); | ||
| auto y_dims = y.dims(); | ||
| if (transpose_x) { | ||
| std::swap(x_dims[x_dims.size() - 1], x_dims[x_dims.size() - 2]); | ||
| } | ||
| if (transpose_y) { | ||
| std::swap(y_dims[y_dims.size() - 1], y_dims[y_dims.size() - 2]); | ||
| } | ||
| std::vector<std::int64_t> out_dims(x_dims.size() - 1 + y_dims.size() - 1); | ||
| for (int64_t i = 0; i < x_dims.size() - 1; ++i) { | ||
| out_dims[i] = x_dims[i]; | ||
| } | ||
| for (int64_t i = 1; i < y_dims.size(); ++i) { | ||
| out_dims[x_dims.size() - 1 + i - 1] = y_dims[i]; | ||
| } | ||
| out->Resize(phi::make_ddim(out_dims)); | ||
| ctx.template Alloc<T>(out); | ||
| return; | ||
| } | ||
| PADDLE_ENFORCE_GE( | ||
| common::product(x.dims()), | ||
| 0, | ||
| common::errors::InvalidArgument( | ||
| "The dims of Input(X) should be greater than or equal to 0.")); | ||
| PADDLE_ENFORCE_GE( | ||
| common::product(y.dims()), | ||
| 0, | ||
| common::errors::InvalidArgument( | ||
| "The dims of Input(Y) should be greater than or equal to 0.")); |
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.
matmul_kernel如果仅修改PADDLE_ENFORCE_NE,是否能支持0-size Tensor?
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.
好像不太行欸,会提示:** On entry to DGEMM parameter number 8 had an illegal value
| self.x_shape = [0, 5, 5, 5] | ||
| self.y_shape = [0, 5, 5, 5] |
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.
是否有其他形状组合?
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.
已补充
| if (x.numel() == 0 || y.numel() == 0) { | ||
| auto x_dims = x.dims(); | ||
| auto y_dims = y.dims(); | ||
| if (transpose_x) { | ||
| std::swap(x_dims[x_dims.size() - 1], x_dims[x_dims.size() - 2]); | ||
| } | ||
| if (transpose_y) { | ||
| std::swap(y_dims[y_dims.size() - 1], y_dims[y_dims.size() - 2]); | ||
| } | ||
| std::vector<std::int64_t> out_dims(x_dims.size() - 1 + y_dims.size() - 1); | ||
| for (int64_t i = 0; i < x_dims.size() - 1; ++i) { | ||
| out_dims[i] = x_dims[i]; | ||
| } | ||
| for (int64_t i = 1; i < y_dims.size(); ++i) { | ||
| out_dims[x_dims.size() - 1 + i - 1] = y_dims[i]; | ||
| } | ||
| out->Resize(phi::make_ddim(out_dims)); | ||
| ctx.template Alloc<T>(out); | ||
| return; | ||
| } |
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.
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.
已补充,也可以过单测的
HydrogenSulfate
left a comment
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

PR Category
User Experience
PR Types
Others
Description
针对


array_api_tests/test_linalg.py::test_linalg_tensordot单测,按照api-array-compat标准,为 tensordot(matmul) 函数添加 0-size tensor 支持,添加后可跑通array-api-tests的如下测试(忽略result_type报错;其次直接跑 _test_tensordot_stacks 计算会存在段错误,但是经过形状验证没问题,注释掉只保留形状验证就可以跑通了)