diff --git a/paddle/pybind/pybind.cc b/paddle/pybind/pybind.cc index a6b583821f261a9848153e7ba99295ec2dce106e..543dbb739e672a797719e9b226232f58929229bc 100644 --- a/paddle/pybind/pybind.cc +++ b/paddle/pybind/pybind.cc @@ -344,8 +344,12 @@ All parameter, weight, gradient are variables in Paddle. py::class_(m, "BlockDesc", "") .def("id", [](BlockDesc &self) { return self.idx(); }) .def("parent", [](BlockDesc &self) { return self.parent_idx(); }) - .def("append_op", [](BlockDesc &self) { return self.add_ops(); }) - .def("new_var", [](BlockDesc &self) { return self.add_vars(); }); + .def("append_op", + [](BlockDesc &self) { return self.add_ops(); }, + py::return_value_policy::reference) + .def("new_var", + [](BlockDesc &self) { return self.add_vars(); }, + py::return_value_policy::reference); py::class_(m, "VarDesc", "") .def(py::init<>())