Skip to content

Commit c62a1e3

Browse files
【stride】fix copy_, set_value when dst is nullptr canot use stridecopy (#74447)
* fix * fix * fix
1 parent 489fc16 commit c62a1e3

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

paddle/fluid/pybind/eager_method.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ static PyObject* tensor_method_set_underline_tensor(TensorObject* self,
14141414
if (self->tensor.is_dense_tensor()) {
14151415
auto* dst_tensor =
14161416
static_cast<phi::DenseTensor*>(self->tensor.impl().get());
1417-
if (self->tensor.has_allocation() &&
1417+
if (self->tensor.has_allocation() && self->tensor.initialized() &&
14181418
!dst_tensor->meta().is_contiguous() ||
14191419
!src_tensor->meta().is_contiguous()) {
14201420
VLOG(8) << "set_tensor() method , src or dst tensor is not contiguous";

paddle/phi/api/lib/tensor_method.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ void Tensor::copy_(const Tensor &src,
198198
return;
199199
}
200200
#endif
201-
if(is_dense_tensor() && has_allocation() && src.is_dense_tensor()) {
201+
if(is_dense_tensor() && has_allocation() &&
202+
initialized() && src.is_dense_tensor()) {
202203
auto dst_tensor = static_cast<phi::DenseTensor*>(impl_.get());
203204
auto src_tensor = std::static_pointer_cast<phi::DenseTensor>(src.impl_);
204205
if(!dst_tensor->meta().is_contiguous() ||

0 commit comments

Comments
 (0)