Skip to content

Conversation

@huangxu96
Copy link
Contributor

@huangxu96 huangxu96 commented Sep 26, 2021

PR types

New features

PR changes

Others

Describe

Add python interface of subgraph: 1. all_sub_graphs() 2. get_sub_graph(idx)

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@huangxu96 huangxu96 force-pushed the subgraph_python_interface branch from a0f6bcc to 4167ec4 Compare September 26, 2021 12:32
@huangxu96 huangxu96 force-pushed the subgraph_python_interface branch from c30e49b to 7c029dd Compare September 27, 2021 09:26
nodes) #这里 all nodes 不为空,所以可以作量化Pass
transform_pass.apply(sub_graph)
print("Done quant pass applied ")
return all_sub_graphs
Copy link
Contributor

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)
Copy link
Contributor

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 *) {});
Copy link
Contributor

Choose a reason for hiding this comment

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

[](Graph *) {}是为了防止外部析构?不能直接返回裸指针么?

Copy link
Contributor Author

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都析构一次。后面加了注释对这个的解释。

Copy link
Contributor

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?

@huangxu96 huangxu96 force-pushed the subgraph_python_interface branch 3 times, most recently from ea88f67 to e0c55cc Compare September 28, 2021 12:47
@huangxu96 huangxu96 force-pushed the subgraph_python_interface branch from e0c55cc to 69b73e6 Compare September 28, 2021 12:50
zhhsplendid
zhhsplendid previously approved these changes Sep 29, 2021
Copy link
Member

@zhhsplendid zhhsplendid left a comment

Choose a reason for hiding this comment

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

LGTM

@huangxu96 huangxu96 force-pushed the subgraph_python_interface branch from 0fc1236 to b2a088e Compare September 29, 2021 09:27
Copy link
Member

@zhhsplendid zhhsplendid left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@zhiqiu zhiqiu left a 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 *) {});
Copy link
Contributor

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?

@zhhsplendid zhhsplendid merged commit a29ff4c into PaddlePaddle:develop Oct 8, 2021
huangxu96 added a commit to huangxu96/Paddle that referenced this pull request Dec 17, 2021
Add python interface of subgraph: 1. all_sub_graphs() 2. get_sub_graph(idx)
lanxianghit pushed a commit that referenced this pull request Dec 21, 2021
Add python interface of subgraph: 1. all_sub_graphs() 2. get_sub_graph(idx)
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