Skip to content

Commit

Permalink
fix to_tensor bug (#67795)
Browse files Browse the repository at this point in the history
  • Loading branch information
risemeup1 authored Aug 29, 2024
1 parent 6267a2b commit 94c6682
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions paddle/fluid/pybind/tensor_py.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ void SetTensorFromPyArrayT(
self->ResetHolderWithType(holder, framework::TransToPhiDataType(type));
} else {
auto dst = self->mutable_data<T>(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
Expand Down Expand Up @@ -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<T>(place);
std::memcpy(dst, array.data(), array.nbytes());
std::memcpy(dst, array.data(), array.size()*sizeof(T));
} else {
auto dst = self->mutable_data<T>(self->place());
std::memcpy(dst, array.data(), array.nbytes());
std::memcpy(dst, array.data(), array.size()*sizeof(T));
}
}
#else
Expand Down Expand Up @@ -473,7 +473,7 @@ void SetTensorFromPyArrayT(

} else if (paddle::platform::is_cuda_pinned_place(place)) {
auto dst = self->mutable_data<T>(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 "
Expand Down

0 comments on commit 94c6682

Please sign in to comment.