-
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
Feature/polish py low level api #3546
Feature/polish py low level api #3546
Conversation
Wrap them into Network class. A low level API for NetOp and Operator
6d6180d
to
cb7d39d
Compare
paddle/framework/operator.cc
Outdated
for (auto& output : op_proto->outputs()) { | ||
if (output.duplicable()) { // If outputs is duplicable, do not set | ||
// default output | ||
continue; |
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.
Why don't duplicable outputs need default name?
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.
Because for duplicable outputs, it could be [0,*]
outputs. It could be 0 output on purpose.
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.
I rewrite these code and add more comments
paddle/framework/operator.cc
Outdated
// Set Default output name, if it is not set | ||
if (outs.empty()) { | ||
outs.push_back(type_ + "@GENERATE_OUTPUT@" + | ||
std::to_string(gUniqId.fetch_add(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.
When will an output have an empty name?
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.
I think there are very few operators that could have an output and that output could be empty.
class TestNetwork(unittest.TestCase): | ||
def test_all(self): | ||
net = Network() | ||
out = net.add_two(X="A", Y="B") |
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.
Here, I'm entangled in how to expose the API better.
@Canpio @Superjom
Should our network expose
net.add_two(...)
net.mul(...)
or just simple
net.create_and_add_op("add_two", ...)
net.create_and_add_op("mul", ...)
The second way will avoid dynamic method generating by __getattr__
, but make user write more characters. Also, caffe2, tf, keras are using mul(...)
.
Personally, I think create_and_add_op('mul', ...)
is better because it make our code simpler.
There is a similar issue before #3198 . So, should we change to create_and_add_op("mul", ...)
?
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.
or just net.add_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.
Both net.add_op('mul', ...)
and net.mul(...)
are enabled now.
感谢您给PaddlePaddle贡献代码。由于Paddle V1/V2版本已不再维护,相关代码也已从develop分支上删除,因此关闭您的PR,欢迎您向Paddle最新版-Fluid贡献代码。 |
This is the third step of issue #3520. Please review PR #3538
A
create_and_add_op
method is added toNetOp
in PyBind, and wrap that method and NetOp into classNetwork
.You can use
to create and add operator into Network object.