diff --git a/paddle/fluid/pybind/imperative.cc b/paddle/fluid/pybind/imperative.cc index 080323bbc2541..00fe2c8da7eb0 100644 --- a/paddle/fluid/pybind/imperative.cc +++ b/paddle/fluid/pybind/imperative.cc @@ -970,6 +970,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; @@ -1137,10 +1142,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) {