Skip to content

Commit

Permalink
Copy input tensors before async transfer (#5830)
Browse files Browse the repository at this point in the history
* Copy input tensors before transfer

* clone tensors before passing them to test case

* formatting

* Update test_utils.py
  • Loading branch information
will-cromar authored and bhavya01 committed Apr 22, 2024
1 parent 47b1950 commit d39e51b
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions torch_xla/csrc/runtime/tensor_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ class AtenSource : public TensorSource {
at::ScalarType target_torch_type = TorchTypeFromXlaType(primitive_type());
if (target_torch_type != tensor.type().scalarType()) {
TORCH_LAZY_COUNTER("AtenSourceDowncasts", 1);
tensor_ = std::move(tensor.to(target_torch_type).contiguous());
} else {
tensor_ = std::move(tensor.contiguous());
}
tensor_ = std::move(tensor.to(target_torch_type, /*non_blocking=*/false,
/*copy=*/true, at::MemoryFormat::Contiguous));
}

const void* data() const override { return tensor_.const_data_ptr(); }
Expand Down

0 comments on commit d39e51b

Please sign in to comment.