From 01eddf125ca9b97ea4aa8d4bfb4e102056ec1c4a Mon Sep 17 00:00:00 2001 From: Zhen Wang Date: Thu, 7 Mar 2019 18:03:40 +0800 Subject: [PATCH] Not add graph copy construction method. test=develop --- paddle/fluid/framework/ir/graph.cc | 3 --- paddle/fluid/framework/ir/graph.h | 1 - paddle/fluid/pybind/ir.cc | 8 ++++---- python/paddle/fluid/framework.py | 5 ++++- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/paddle/fluid/framework/ir/graph.cc b/paddle/fluid/framework/ir/graph.cc index 38852eb7d0..0721ee230b 100644 --- a/paddle/fluid/framework/ir/graph.cc +++ b/paddle/fluid/framework/ir/graph.cc @@ -14,7 +14,6 @@ limitations under the License. */ #include #include -#include #include "paddle/fluid/framework/ir/graph.h" #include "paddle/fluid/framework/op_proto_maker.h" @@ -30,8 +29,6 @@ Graph::Graph(const ProgramDesc &program) : program_(program) { ResolveHazard(var_nodes); } -Graph::Graph(const Graph &o) : Graph(o.program_) {} - std::map> Graph::InitFromProgram( const ProgramDesc &program) { VLOG(3) << "block in program:" << program_.Size(); diff --git a/paddle/fluid/framework/ir/graph.h b/paddle/fluid/framework/ir/graph.h index 9c5dbc0455..cfd82dcb03 100644 --- a/paddle/fluid/framework/ir/graph.h +++ b/paddle/fluid/framework/ir/graph.h @@ -72,7 +72,6 @@ namespace ir { class Graph { public: explicit Graph(const ProgramDesc &program); - Graph(const Graph &o); virtual ~Graph() { for (auto &attr : attrs_) { diff --git a/paddle/fluid/pybind/ir.cc b/paddle/fluid/pybind/ir.cc index 160d8d05c0..298f976bc1 100644 --- a/paddle/fluid/pybind/ir.cc +++ b/paddle/fluid/pybind/ir.cc @@ -54,14 +54,13 @@ void BindGraph(py::module *m) { "The graph is a Directed Acyclic Single Static Assignment Graph, see " "`paddle::ir::Graph` for details.") .def(py::init()) - .def("__init__", - [](Graph &self, const Graph &other) { new (&self) Graph(other); }) .def("has", &Graph::Has) .def("get_int", &Graph::Get) .def("get_float", &Graph::Get) .def("get_double", &Graph::Get) .def("get_string", &Graph::Get) - .def("get_marked_nodes", &Graph::Get>) + .def("get_marked_nodes", &Graph::Get>, + return_value_policy::reference) .def("set", [](Graph &self, const std::string &attr_name, int attr) { return self.Set(attr_name, new int(attr)); }) .def("set", @@ -105,7 +104,8 @@ void BindGraph(py::module *m) { .def("retrieve_node", &Graph::RetrieveNode, return_value_policy::reference) .def("resolve_hazard", &Graph::ResolveHazard) - .def("origin_program_desc", &Graph::OriginProgram); + .def("origin_program_desc", &Graph::OriginProgram, + return_value_policy::reference); } void BindNode(py::module *m) { diff --git a/python/paddle/fluid/framework.py b/python/paddle/fluid/framework.py index 6cfc433d64..3c36eb6456 100644 --- a/python/paddle/fluid/framework.py +++ b/python/paddle/fluid/framework.py @@ -2006,10 +2006,13 @@ class IrGraph(object): """ Create a new and duplicated IrGraph. + Warns: + The method only clones the graph structure, not its attributes. + Returns: IrGraph: A new and duplicated graph. """ - g = core.Graph(self.graph) + g = core.Graph(self.graph.origin_program_desc()) return IrGraph(g, self._for_test) def is_test(self): -- GitLab