-
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
Get OpProtos in Python #2864
Get OpProtos in Python #2864
Conversation
* 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`
|
||
namespace py = pybind11; | ||
namespace pd = paddle::framework; | ||
|
||
USE_OP(add_two); |
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.
这个后面是不是会专门放一个地方?
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.
是的。可以单独放一个.cc里面,而且那个.cc应该也可以是编译器生成的。
python/paddle/v2/optimizer.py
Outdated
@@ -26,6 +24,8 @@ def __impl__(): | |||
|
|||
self.__opt_conf_proto__ = config_parser_utils.parse_optimizer_config( | |||
__impl__) | |||
if swig_api is None: |
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.
下面这部分修改是另外一个问题?
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.
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)) |
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.
if this str()
method the way to fix the Unicode problem?
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.
Yep.
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!
lazy import all SWIG library of Paddle. Otherwise, the glog, gflags
are imported twice in a same Python process.
protobuf, it is need be cast to
str
before use them.OpProtos