Repository navigation
【SCU】【Paddle Tensor 第二期 API 支持 0-size TensorNo.25、47】paddle.tensordot 支持 0-size Tensor - #70238
Merged
Merged
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
Contributor
Author
|
其中好像还会涉及到sum,这里在等这个PR合入:#70146 |
Comment on lines
+2010
to
+2039
| 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.")); |
Collaborator
There was a problem hiding this comment.
matmul_kernel如果仅修改PADDLE_ENFORCE_NE,是否能支持0-size Tensor?
Contributor
Author
There was a problem hiding this comment.
好像不太行欸,会提示:** On entry to DGEMM parameter number 8 had an illegal value
Comment on lines
+376
to
+377
| self.x_shape = [0, 5, 5, 5] | ||
| self.y_shape = [0, 5, 5, 5] |
Comment on lines
+2010
to
+2029
| 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; | ||
| } |
Collaborator
PolaKuma
marked this pull request as draft
December 18, 2024 14:18
PolaKuma
marked this pull request as ready for review
December 18, 2024 14:45
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.

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 计算会存在段错误,但是经过形状验证没问题,注释掉只保留形状验证就可以跑通了)