From 70fb27f391b2fe32b2fb2cd360ae559dd3466804 Mon Sep 17 00:00:00 2001 From: risemeup1 <515586620@qq.com> Date: Wed, 28 Aug 2024 18:13:21 +0000 Subject: [PATCH] fix to_tensor bug --- paddle/fluid/pybind/tensor_py.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/pybind/tensor_py.h b/paddle/fluid/pybind/tensor_py.h index dd5bd7f1d91c4d..b49584b50962af 100644 --- a/paddle/fluid/pybind/tensor_py.h +++ b/paddle/fluid/pybind/tensor_py.h @@ -398,7 +398,7 @@ void SetTensorFromPyArrayT( self->ResetHolderWithType(holder, framework::TransToPhiDataType(type)); } else { auto dst = self->mutable_data(place); - std::memcpy(dst, array.data(), array.nbytes()); + std::memcpy(dst, array.data(), array.size()*sizeof(T)); } } else if (paddle::platform::is_xpu_place(place)) { #ifdef PADDLE_WITH_XPU @@ -427,10 +427,10 @@ void SetTensorFromPyArrayT( // IPU does not store Tensor data, Tensor will be created on CPU if (!self->initialized()) { auto dst = self->mutable_data(place); - std::memcpy(dst, array.data(), array.nbytes()); + std::memcpy(dst, array.data(), array.size()*sizeof(T)); } else { auto dst = self->mutable_data(self->place()); - std::memcpy(dst, array.data(), array.nbytes()); + std::memcpy(dst, array.data(), array.size()*sizeof(T)); } } #else @@ -473,7 +473,7 @@ void SetTensorFromPyArrayT( } else if (paddle::platform::is_cuda_pinned_place(place)) { auto dst = self->mutable_data(place); - std::memcpy(dst, array.data(), array.nbytes()); + std::memcpy(dst, array.data(), array.size()*sizeof(T)); } else { PADDLE_THROW(platform::errors::InvalidArgument( "Incompatible place type: Tensor.set() supports "