diff --git a/paddle/fluid/framework/ir/graph.cc b/paddle/fluid/framework/ir/graph.cc index 38852eb7d06c5442a8d2fa2ddfb3228b5b8ec247..0721ee230b274af7d585086374611fa16626d4f2 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 9c5dbc0455f3317b5ed137118cf3c480de15ed9a..cfd82dcb0368c41631d5c37185ee782ab1cef85c 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 160d8d05c0a9501a884ea5c5bc1190e4d9663a1f..298f976bc1125f5163407c813cf84a716bf5c623 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 6cfc433d6485ff1fed43c8843ff48f3fa460c4ad..3c36eb64560a1b384e9bb52e4a7dee2c5f35a23c 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):