diff --git a/paddle/fluid/pybind/eager_method.cc b/paddle/fluid/pybind/eager_method.cc index f4a373824b162b..89f37ca9c7d75a 100644 --- a/paddle/fluid/pybind/eager_method.cc +++ b/paddle/fluid/pybind/eager_method.cc @@ -1414,7 +1414,7 @@ static PyObject* tensor_method_set_underline_tensor(TensorObject* self, if (self->tensor.is_dense_tensor()) { auto* dst_tensor = static_cast(self->tensor.impl().get()); - if (self->tensor.has_allocation() && + if (self->tensor.has_allocation() && self->tensor.initialized() && !dst_tensor->meta().is_contiguous() || !src_tensor->meta().is_contiguous()) { VLOG(8) << "set_tensor() method , src or dst tensor is not contiguous"; diff --git a/paddle/phi/api/lib/tensor_method.cc b/paddle/phi/api/lib/tensor_method.cc index 149cbc3b56beb3..2f7d54eaa05e00 100644 --- a/paddle/phi/api/lib/tensor_method.cc +++ b/paddle/phi/api/lib/tensor_method.cc @@ -198,7 +198,8 @@ void Tensor::copy_(const Tensor &src, return; } #endif - if(is_dense_tensor() && has_allocation() && src.is_dense_tensor()) { + if(is_dense_tensor() && has_allocation() && + initialized() && src.is_dense_tensor()) { auto dst_tensor = static_cast(impl_.get()); auto src_tensor = std::static_pointer_cast(src.impl_); if(!dst_tensor->meta().is_contiguous() ||