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

add remove_var from c++ end #9607

Merged
merged 1 commit into from
Apr 4, 2018
Merged

add remove_var from c++ end #9607

merged 1 commit into from
Apr 4, 2018

Conversation

luotao1
Copy link
Contributor

@luotao1 luotao1 commented Apr 3, 2018

paddle/fluid/pybind/protobuf.cc:101:  Is this a non-const reference? If so, make const or use a pointer: T &self  

[runtime/references] [2]
paddle/fluid/pybind/protobuf.cc:110:  Is this a non-const reference? If so, make const or use a pointer: py::module &m  

[runtime/references] [2]
paddle/fluid/pybind/protobuf.cc:154:  Is this a non-const reference? If so, make const or use a pointer: py::module &m  

[runtime/references] [2]
paddle/fluid/pybind/protobuf.cc:215:  Is this a non-const reference? If so, make const or use a pointer: py::module &m  

[runtime/references] [2]
paddle/fluid/pybind/protobuf.cc:266:  Is this a non-const reference? If so, make const or use a pointer: py::module &m  

[runtime/references] [2]
paddle/fluid/pybind/protobuf.cc:130:  Add #include <tuple> for tuple<>  [build/include_what_you_use] [4]
paddle/fluid/pybind/protobuf.cc:304:  Add #include <string> for string  [build/include_what_you_use] [4]
Done processing paddle/fluid/pybind/protobuf.cc

@luotao1 luotao1 requested a review from typhoonzero April 3, 2018 14:37
@wangkuiyi
Copy link
Collaborator

I don't understand why do we need remove_op and remove_var? In my mind, the ProgramDesc is constructive -- built by adding ops and vars from nothing.

@luotao1 luotao1 mentioned this pull request Apr 4, 2018
@luotao1
Copy link
Contributor Author

luotao1 commented Apr 4, 2018

@wangkuiyi Sorry for the description of background. The motivation is that we want to fuse batch normalization during inference, and we need an inference transpiler to implement it. As we need to remove batch_norm ops and unused variables from ProgramDesc, we need remove_op and remove_var methods. Please refer to #9629 for details.

@Xreki Xreki added the 预测 原名Inference,包含Capi预测问题等 label Apr 4, 2018
Copy link
Contributor

@typhoonzero typhoonzero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, this PR LGTM.

@@ -96,6 +97,8 @@ class BlockDesc {
*/
void RemoveOp(size_t s, size_t e);

void RemoveVar(const std::string &name) { vars_.erase(name); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for myself: sync_with_cpp already add sync removed vars in previous PR.

@@ -200,13 +202,19 @@ void BindBlockDesc(py::module &m) {
return self.FindVarRecursive(name);
},
py::return_value_policy::reference)
.def("remove_var",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I began to think our previous design of XXXDesc maybe a wrong design. When we need to manipulate the ProgramDesc proto message, we have to write corresponding c++ implementation, then expose it to pybind, and sync the python holders of the c++ side objects, this makes the code complicated and not simple enough.

When comes with transpilers which need to add, cut, remove operators, variables, and blocks in the ProgramDesc, we must be very careful that the c++ side object reference may have already deleted.

A simpler way is to manipulate the ProgramDesc proto message directly in python, and give it to the c++ executor. For performance, python is slow indeed, but if we only use it in compile time and transpile time, it won't affect the total training performance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wangkuiyi @reyoung can you please take a look at the above comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @typhoonzero. It is so difficult for add, cut, insert, remove operators, variables, and blocks in the ProgramDesc for writing a transpiler, I must change sync_with_cpp method in framework.py at the same time.

Related PR: refine sync_with_cpp when remove ops or remove vars #9600

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed need some rethink

@luotao1 luotao1 merged commit 5eb9cec into PaddlePaddle:develop Apr 4, 2018
@luotao1 luotao1 deleted the remove_var branch April 4, 2018 09:42
@Xreki Xreki added this to Basic Usage (DONE) in Inference Framework Apr 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
预测 原名Inference,包含Capi预测问题等
Projects
No open projects
Inference Framework
Basic Usage (DONE)
Development

Successfully merging this pull request may close these issues.

None yet

5 participants