Skip to content
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

Closed

Conversation

reyoung
Copy link
Collaborator

@reyoung reyoung commented Aug 17, 2017

This is the third step of issue #3520. Please review PR #3538
A create_and_add_op method is added to NetOp in PyBind, and wrap that method and NetOp into class Network.

You can use

net = Network()
net.add_two(...)
net.mul(...)

to create and add operator into Network object.

@reyoung reyoung force-pushed the feature/polish_py_low_level_api branch from 6d6180d to cb7d39d Compare August 17, 2017 10:59
for (auto& output : op_proto->outputs()) {
if (output.duplicable()) { // If outputs is duplicable, do not set
// default output
continue;
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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

// 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)));
Copy link
Collaborator

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?

Copy link
Collaborator Author

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")
Copy link
Collaborator Author

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", ...) ?

Copy link
Member

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()

Copy link
Collaborator Author

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.

@reyoung reyoung mentioned this pull request Aug 18, 2017
@luotao1
Copy link
Contributor

luotao1 commented Feb 1, 2019

感谢您给PaddlePaddle贡献代码。由于Paddle V1/V2版本已不再维护,相关代码也已从develop分支上删除,因此关闭您的PR,欢迎您向Paddle最新版-Fluid贡献代码。
Thanks for contributing to PaddlePaddle! Since V1/V2 will not be maintained anymore, and related codes have been deleted from develop branch as well, we close this PR. Welcome to contribute to Fluid——the latest version of PaddlePaddle.

@luotao1 luotao1 closed this Feb 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants