-
Notifications
You must be signed in to change notification settings - Fork 5.9k
add python interface of sub_graph #36120
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 python interface of sub_graph #36120
Conversation
|
Thanks for your contribution! |
a0f6bcc to
4167ec4
Compare
c30e49b to
7c029dd
Compare
| nodes) #这里 all nodes 不为空,所以可以作量化Pass | ||
| transform_pass.apply(sub_graph) | ||
| print("Done quant pass applied ") | ||
| return all_sub_graphs |
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.
这里返回后main_graph应该就被析构了,而sub_graphs其实只是main_graph的一个成员。
| # loss = linear_fc(3) | ||
| # opt = fluid.optimizer.Adam(learning_rate=0.001) | ||
| # opt.minimize(loss) | ||
| core_graph = core.Graph(main_program.desc) |
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.
我觉得main_graph应该是传入而非函数内部创建,临时变量出作用域后就会被析构,python应该也不例外
| return_value_policy::reference) | ||
| .def("sub_graph_size", &Graph::SubGraphsSize) | ||
| .def("get_sub_graph", [](Graph &self, int i) { | ||
| return std::shared_ptr<Graph>(self.GetSubGraph(i), [](Graph *) {}); |
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.
[](Graph *) {}是为了防止外部析构?不能直接返回裸指针么?
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.
这个是防止double free,目的是让该指针在python析构,不然会在C++和python都析构一次。后面加了注释对这个的解释。
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.
Does return_value_policy::reference work for that?
ea88f67 to
e0c55cc
Compare
e0c55cc to
69b73e6
Compare
zhhsplendid
left a comment
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
abaf4cd to
0fc1236
Compare
0fc1236 to
b2a088e
Compare
zhhsplendid
left a comment
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
zhiqiu
left a comment
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
| return_value_policy::reference) | ||
| .def("sub_graph_size", &Graph::SubGraphsSize) | ||
| .def("get_sub_graph", [](Graph &self, int i) { | ||
| return std::shared_ptr<Graph>(self.GetSubGraph(i), [](Graph *) {}); |
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.
Does return_value_policy::reference work for that?
Add python interface of subgraph: 1. all_sub_graphs() 2. get_sub_graph(idx)
PR types
New features
PR changes
Others
Describe
Add python interface of subgraph: 1. all_sub_graphs() 2. get_sub_graph(idx)