From 9a5472cc8471b8b4c01404c393ff645dbe702dea Mon Sep 17 00:00:00 2001 From: zyfncg Date: Tue, 14 Dec 2021 20:14:00 +0800 Subject: [PATCH] fix memory leak problen of set_value op (#38098) * fix bug of set_value op * fix BumpInplaceVersion * polish some comments * revert change of full_like --- paddle/fluid/pybind/imperative.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/pybind/imperative.cc b/paddle/fluid/pybind/imperative.cc index bbbcf0d553d6a..05037d2a1b9dc 100644 --- a/paddle/fluid/pybind/imperative.cc +++ b/paddle/fluid/pybind/imperative.cc @@ -940,6 +940,11 @@ void BindImperative(py::module *m_ptr) { } }; + // NOTE(liym27): + // Increase the version of VarBase self because __setitem__ is an + // inplace operator for the VarBase self. + self->BumpInplaceVersion(); + // 1. Check argumnets bool parse_index = true; @@ -1107,10 +1112,6 @@ void BindImperative(py::module *m_ptr) { SetTensorFromPyArray(self_tensor, self_numpy, self_tensor->place(), false); } - // NOTE(liym27): - // Increase the version of VarBase self because __setitem__ is an - // inplace operator for the VarBase self. - self->BumpInplaceVersion(); }) .def("_getitem_index_not_tensor", [](std::shared_ptr &self, py::handle _index) {