diff --git a/paddle/fluid/pybind/imperative.cc b/paddle/fluid/pybind/imperative.cc index 080323bbc25419c6e88f84f6b28fc025233e1ce6..00fe2c8da7eb0517fb8ac10b6c8b45e3330b28ef 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) {