[PyTorch Core] MTIA supports arbitrary strides (#157883)

Summary:
Currently, on MTIA the following case will return false

```
options.device().supports_as_strided()
```
As a result, whenever moving a tensor from CPU to MTIA, strides will not be preserved ([see here](e5edd013ab/aten/src/ATen/native/TensorConversions.cpp (L351))). This is a primary reason why deserializing tensors from .pt files will be contiguous.

Reviewed By: egienvalue, andyanwang

Differential Revision: D77843224

Pull Request resolved: https://github.com/pytorch/pytorch/pull/157883
Approved by: https://github.com/albanD, https://github.com/andyanwang
This commit is contained in:
Simon Mahns
2025-07-11 18:54:21 +00:00
committed by PyTorch MergeBot
parent b0556110e5
commit b487003182

View File

@ -160,7 +160,7 @@ struct C10_API Device final {
/// Return true if the device supports arbitrary strides.
bool supports_as_strided() const noexcept {
return type_ != DeviceType::IPU && type_ != DeviceType::XLA &&
type_ != DeviceType::Lazy && type_ != DeviceType::MTIA;
type_ != DeviceType::Lazy;
}
/// Same string as returned from operator<<.