diff --git a/paddle/fluid/pybind/eager_method.cc b/paddle/fluid/pybind/eager_method.cc index e78e3bb106df028a6578e374495576f7ce437f54..6f49953ae8ae580d44495da7a0b48e462c859440 100644 --- a/paddle/fluid/pybind/eager_method.cc +++ b/paddle/fluid/pybind/eager_method.cc @@ -272,6 +272,7 @@ static PyObject* tensor_method_numpy(TensorObject* self, gpuMemcpyKind kind = cudaMemcpyDeviceToHost; #elif defined(PADDLE_WITH_HIP) gpuMemcpyKind kind = hipMemcpyDeviceToHost; + phi::DeviceContextPool::Instance().Get(self->tensor.place())->Wait(); #endif if (self->tensor.is_selected_rows()) { VLOG(6) << "Getting SelectedRows's numpy value"; @@ -341,6 +342,7 @@ static PyObject* tensor_method_numpy(TensorObject* self, #ifdef PADDLE_WITH_CUSTOM_DEVICE } else if (self->tensor.is_custom_device()) { eager_gil_scoped_release guard; + phi::DeviceContextPool::Instance().Get(self->tensor.place())->Wait(); if (self->tensor.is_selected_rows()) { VLOG(6) << "Getting SelectedRows's numpy value"; auto* selected_rows =