-
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
Enhance reduce op #10708
Enhance reduce op #10708
Conversation
} | ||
int ndim = context.Input<Tensor>("X")->dims().size(); | ||
int rdim = context.Attr<std::vector<int>>("dim").size(); | ||
HANDLE_DIM(6, 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.
Seems we can simplify codes here by employing boost/preprocessor
, please refer to https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/fluid/operators/expand_op.h#L31, however, it will decrease the readability.
range :math:`[-rank(input), rank(input))`. If :math:`dim < 0`, | ||
the dimension to reduce is :math:`rank + dim`. | ||
range :math:`[-rank(input), rank(input))`. If :math:`dim[i] < 0`, | ||
the dimension to reduce is :math:`rank + dim[i]`. |
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.
Need to give the examples when len(dim) > 1 in following Examples
doc.
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.
Done. Thx.
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.
paddle/fluid/operators/reduce_op.h
Outdated
if (keep_dim && x_rank > 1) { | ||
dims_vector.erase(dims_vector.begin() + dim); | ||
dims = framework::make_ddim(dims_vector); | ||
int DEL_FLAG = -2; |
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.
const int kDelFlag = -2;
https://google.github.io/styleguide/cppguide.html#Constant_Names
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.
Fixed. Thx.
@@ -126,5 +133,67 @@ def test_check_grad(self): | |||
self.check_grad(['X'], 'Out') | |||
|
|||
|
|||
## reduction in multi dims | |||
class TestMeanOpM(OpTest): |
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.
TestMeanOpM -> TestReduceMeanOpMultiAxises or TestReduceMeanOpMultiDims?
Same as follows.
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.
Done. Thx.
1. Rename unitest function. 2. Rename const variable.
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.
HANDLE_DIM(3, 2); | ||
HANDLE_DIM(3, 1); | ||
HANDLE_DIM(2, 1); | ||
HANDLE_DIM(1, 1); |
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.
reduce_op现在编译特别慢,GPU模式下等了快5分钟才编译完这个op。请问是不是138行-153行支持的维度太多了呢?能否把维度5和6删去,这样就从15种减少到6种了。
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.
@panyx0718 merge 个pr减少支持的纬度: #11113
一起看看#11029 |
No description provided.