-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Feature/clone op #3522
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
Feature/clone op #3522
Conversation
* Clone method will create a new object instance, which is as same as itself. * This is the first step to remove shared_ptr for OperatorBase
paddle/framework/operator.h
Outdated
| // You can also use | ||
| // using PARENT_CLASS::PARENT_CLASS; | ||
| // to use parent's constructor. | ||
| #define DEFINE_OP_CTOR(CLS, PARENT_CLS) \ |
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.
DEFINE_OP_CREATOR 还是 DEFINE_OP_CONSTRUCTOR 的简写?
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. Change it to DEFINE_OP_CONSTRUCTOR
| op->Run(scope, cpu_device_context); | ||
| } | ||
|
|
||
| class OperatorClone : public paddle::framework::OperatorBase { |
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.
这个是当成一个普通 op ,train 跑起来的时候去run吗? 感觉没必要直接写就行了吧
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.
这是测试一下Clone返回的结果对不对。只是一个单测。
| }; | ||
|
|
||
| class RecurrentGradientOp final : public framework::OperatorBase { | ||
| class RecurrentGradientOp : public framework::OperatorBase { |
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.
这个是 final吧,如果继承,可以继承 RecurrentGradientAlgorithm
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.
因为注册Op的时候会插入新的Clone函数,这样用户开发Kernel的时候就不需要关注Clone的逻辑了。
所以注册进OpRegistry的Op,不能是Final的。
Make code more clearer
Fit google C++ style
|
|
||
| // Return a new operator instance, which is as same as this. | ||
| // Use unique_ptr to prevent caller forget to delete this pointer. | ||
| virtual std::unique_ptr<OperatorBase> Clone() const = 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.
https://google.github.io/styleguide/cppguide.html#Ownership_and_Smart_Pointers
In google C++ style, says
Prefer to use std::unique_ptr to make ownership transfer explicit.
Superjomn
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
| std::string type_; | ||
| // NOTE: in case of OpGrad, inputs_ contains: | ||
| // I (Inputs) | ||
| // I (Inputs)opear |
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.
typo?
Fix #3521