[Bugfix] Ensure tensors are contiguous during serialisation (#18860)

Signed-off-by: Lukas Geiger <lukas.geiger94@gmail.com>
This commit is contained in:
Lukas Geiger 2025-05-29 11:05:20 +01:00 committed by GitHub
parent 24d0ef8970
commit 0b1447f890
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -158,8 +158,8 @@ class MsgpackEncoder:
self, obj: torch.Tensor
) -> tuple[str, tuple[int, ...], Union[int, memoryview]]:
assert self.aux_buffers is not None
# view the tensor as a 1D array of bytes
arr = obj.flatten().view(torch.uint8).numpy()
# view the tensor as a contiguous 1D array of bytes
arr = obj.flatten().contiguous().view(torch.uint8).numpy()
if obj.nbytes < self.size_threshold:
# Smaller tensors are encoded inline, just like ndarrays.
data = msgpack.Ext(CUSTOM_TYPE_RAW_VIEW, arr.data)