-
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
Local response normalize. #4426
Conversation
paddle/operators/lrn_op.cc
Outdated
public: | ||
LRNOpMaker(framework::OpProto *proto, framework::OpAttrChecker *op_checker) | ||
: OpProtoAndCheckerMaker(proto, op_checker) { | ||
AddInput("X", "The first input of lrn op"); |
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.
Personally, I think only "the first/second input of X" is not a good comment.
#4314
fc op
has a good comment style. https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/operators/fc_op.cc#L123
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
The comments still do not follow our comment style in our doc: https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/operators/name_convention.md Please take fc_op as an example. |
paddle/operators/lrn_op.cc
Outdated
PADDLE_ENFORCE_EQ(x_dim.size(), 4, "Input(X)'rank of LRNOp should be 4."); | ||
|
||
ctx.Output<Tensor>("Out")->Resize(x_dim); | ||
ctx.Output<Tensor>("mid_out")->Resize(x_dim); |
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 update to the latest code.
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.
paddle/operators/lrn_op.cc
Outdated
)DOC"); | ||
|
||
AddOutput("Out", "(Tensor)The output of lrn op"); | ||
AddOutput("mid_out", R"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.
Not follow the name convention.
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.
paddle/operators/lrn_op.cc
Outdated
: OpProtoAndCheckerMaker(proto, op_checker) { | ||
AddInput("X", R"DOC( | ||
(Tensor)Input of lrn op.It must be a 4 rank tenor with NCHW format. | ||
)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.
(Tensor) The input of LRN operator. It must be a 4D tenor with NCHW format.
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.
paddle/operators/lrn_op.cc
Outdated
(Tensor)Input of lrn op.It must be a 4 rank tenor with NCHW format. | ||
)DOC"); | ||
|
||
AddOutput("Out", "(Tensor)The output of lrn op"); |
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.
(Tensor) The output of LRN operator, which is also the 4D tensor with NCHW format.
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.
paddle/operators/lrn_op.cc
Outdated
|
||
auto x_dims = ctx.Input<Tensor>("X")->dims(); | ||
auto *x_g = ctx.Output<framework::Tensor>(framework::GradVarName("X")); | ||
x_g->Resize(x_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.
Need to update to the latest code.
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.
and also used in backward process. | ||
)Doc"); | ||
|
||
AddAttr<int>("n", R"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.
n -> size
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.
GPU的实现, 最好复用kernel: https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/function/CrossMapNormalOpGpu.cu
现在这样的循环对于GPU来说效率低。
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.
我增加了一个ISSUE,并且写到了layer port中,新开PR解决这个问题吧!
#5066
paddle/operators/lrn_op.cc
Outdated
.SetDefault(0.0001) | ||
.GreaterThan(0.0); | ||
|
||
AddAttr<float>("beta", R"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.
alpha
, beta
, k
这些float类型的参数,觉得最好也用模板来写,可以参考:https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/operators/dropout_op.cc#L40
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.
self.check_output() | ||
|
||
def test_check_grad_normal(self): | ||
self.check_grad(['X'], 'Out', max_relative_error=0.12) |
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.
如果max_relative_error
过大,可以尝试double测试~
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.
Fix #4425