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

Get OpProtos in Python #2864

Merged
merged 4 commits into from
Jul 15, 2017

Conversation

reyoung
Copy link
Collaborator

@reyoung reyoung commented Jul 14, 2017

  • PyBind and SWIG of paddle cannot be load in a single Python process,
    lazy import all SWIG library of Paddle. Otherwise, the glog, gflags
    are imported twice in a same Python process.
  • Note that all PyBind11 return C++ std::string as an unicode. For
    protobuf, it is need be cast to str before use them.
  • Add unit test for Get OpProtos

* PyBind and SWIG of paddle cannot be load in a single Python process,
  lazy import all SWIG library of Paddle. Otherwise, the glog, gflags
  are imported twice in a same Python process.
* Note that all PyBind11 return C++ std::string as an unicode. For
  protobuf, it is need be cast to `str` before use them.
* Add unit test for Get `OpProtos`
@reyoung reyoung requested a review from jacquesqiao July 14, 2017 07:08
@reyoung reyoung changed the title Feature/op creation methods Get OpProtos in Python Jul 14, 2017

namespace py = pybind11;
namespace pd = paddle::framework;

USE_OP(add_two);
Copy link
Member

Choose a reason for hiding this comment

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

这个后面是不是会专门放一个地方?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

是的。可以单独放一个.cc里面,而且那个.cc应该也可以是编译器生成的。

@@ -26,6 +24,8 @@ def __impl__():

self.__opt_conf_proto__ = config_parser_utils.parse_optimizer_config(
__impl__)
if swig_api is None:
Copy link
Member

Choose a reason for hiding this comment

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

下面这部分修改是另外一个问题?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is a bug. Done.

protostrs = core.get_all_op_protos()
ret_values = []
for pbstr in protostrs:
op_proto = op_proto_pb2.OpProto.FromString(str(pbstr))
Copy link
Member

Choose a reason for hiding this comment

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

if this str() method the way to fix the Unicode problem?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep.

Copy link
Member

@jacquesqiao jacquesqiao left a comment

Choose a reason for hiding this comment

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

LGTM!

@reyoung reyoung merged commit 1faf5e0 into PaddlePaddle:develop Jul 15, 2017
@reyoung reyoung deleted the feature/op_creation_methods branch July 15, 2017 09:02
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.

2 participants