Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions torch_xla/csrc/aten_xla_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,12 +866,23 @@ AtenXlaType::convolution_backward_overrideable(

at::Tensor& AtenXlaType::copy_(at::Tensor& self, const at::Tensor& src,
bool non_blocking) {
XLATensor self_tensor = bridge::GetXlaTensor(self);
c10::optional<XLATensor> self_tensor = bridge::TryGetXlaTensor(self);
c10::optional<XLATensor> src_tensor = bridge::TryGetXlaTensor(src);
if (src_tensor) {
XLATensor::copy_(self_tensor, *src_tensor);

if (!src_tensor) {
XLA_CHECK(self_tensor);
self_tensor->SetTensor(CopyTensor(src, self.scalar_type()));
} else if (!self_tensor) {
// TODO: Is self_tensor good enough? I don't think so... therefore
// the hack below:
std::vector<at::Tensor> tensors = {src};
auto xla_tensors = bridge::XlaCreateTensorList(tensors);
// Hack in an overwrite of a const tensor.
at::Tensor t = CopyTensor(xla_tensors.front(), self.scalar_type());
const_cast<at::Tensor&>(self).unsafeGetTensorImpl()->shallow_copy_from(
t.getIntrusivePtr());
} else {
self_tensor.SetTensor(CopyTensor(src, self.scalar_type()));
XLATensor::copy_(*self_tensor, *src_tensor);
}
return self;
}
Expand Down