Add stable nrm2 for L2 normalization#12440
Conversation
|
failed..... @leezu , maybe my code is wrong, can you help me? |
|
Thanks for your contribution @TccccD |
|
@TccccD @leezu Please have a look at the CI build failure so we can proceed with the review. @sandeep-krishnamurthy Please change the label to pr-awaiting-testing |
|
@marcoabreu @lebeg @larroy Could you please help @TccccD with the test failures? |
|
I submitted it three times. The first time was successful, the next two times were other mistakes(Failed with error: 'there is no package called 'shiny''). I don't know why. |
|
@mxnet-label-bot update [pr-awaiting-review] |
|
LGTM. @apeforest @samskalicky for further comments/review |
|
In TBlob::reshape, it got different shape size. |
| }); | ||
| norm = F<mxnet::op::mshadow_op::square_root>(norm); | ||
| out = data / broadcast<0>(norm, out.shape_); | ||
| out = data / mshadow::expr::broadcast<0>(norm, out.shape_); |
There was a problem hiding this comment.
You are already using namespace mshadow::expr. The identifier is not necessary here.
There was a problem hiding this comment.
If I use
mxnet::op::ReduceAxesComputeImpl
it will got an error:
src/operator/./l2_normalization-inl.h:91:7: error: ‘ReduceAxesComputeImpl’ is not a member of ‘mxnet::op’
I think it may be because the L2_norm compilation order is before broadcast_reduce_op.h
So, I use
#include "./tensor/broadcast_reduce_op.h"
and this requires that I must use mshadow::expr:: again, otherwise conflicts will occur.
@apeforest
There was a problem hiding this comment.
IC, the reason is that in ./tensor/broadcast_reduce_op.h "broadcast" was used to define a namespace. Maybe this is where the conflict comes from.
|
@apeforest can you please check out latest response by @TccccD ? Thanks! |
| const std::vector<TShape> &in_shape) const override { | ||
| return{ ResourceRequest::kTempSpace }; | ||
| } | ||
|
|
There was a problem hiding this comment.
overall looks good, can you add a test for the failing test case that you mentioned in the issue.
There was a problem hiding this comment.
The main problem is that we don't know the cause of this problem. It is difficult to build a test case. @anirudh2290
There was a problem hiding this comment.
Can you just use the same one you reported in issue #11938?
There was a problem hiding this comment.
After carefully reading the code, I think this change is too hacky. The way you are using the ReduceAxesComputeImpl to hack around the mxnet_op::Kernel call is anti-pattern and will miss many optimization in the Kernel loop and cause more maintainence efforts down the road.
I suggest you follow the current Kernel and Map pattern in the existing code. You may refer to other operators for references. Thanks for your contribution.
|
There are pros and cons to both approaches. If @TccccD has to implement with Kernel::Launch approach he has to rely on mshadow reduce_with_axis and that is not very performant compared to the |
|
@ZhennanQin Could you please help to review this PR? Thanks! |
|
@apeforest @ZhennanQin ping for review |
|
Code change looks good to me. Do you need any help to apply this change to CPU implementation at https://github.com/apache/incubator-mxnet/blob/master/src/operator/l2_normalization.cc ? |
|
@TccccD - Can you please take look at @ZhennanQin comment, I think we are closer to getting this merged. Thanks for your contributions. |
|
@mxnet-label-bot update [pr-awaiting-response] |
|
@TccccD Thanks for the contribution! Could you please take a look into final few comments by @ZhennanQin |
|
I think the implementation of the CPU may not be related to the error, but I can try to implement one. |
|
@mxnet-label-bot add [Operator, pr-work-in-progress] |
|
@TccccD Any updates on the requested changes? |
|
@TccccD Could you please give an update? Thanks |
|
@TccccD Ping again. |
|
Sorry, I am no longer engaged in this work, can not take the time to achieve and improve this pr, now turn it off. |
Description
Call interface of the 2-norm (#11573) to, it got the same results as this method in three different modes and solve this problem #11938 ;
But I think my modifications may still be optimized,
please help me to optimize it. thanks!
@haojin2 @piiswrong @leezu @anirudh2290 @szha
I encountered some problems in rebase, so I opened a new pr. @leezu , the previous pr is #12287