memory: Add more exclusion criteria to pinned read (#13067)

This commit is contained in:
rattus 2026-03-19 10:03:20 -07:00 committed by GitHub
parent 6589562ae3
commit ab14541ef7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -39,7 +39,10 @@ def read_tensor_file_slice_into(tensor, destination):
if (destination.device.type != "cpu" if (destination.device.type != "cpu"
or file_obj is None or file_obj is None
or threading.get_ident() != info.thread_id or threading.get_ident() != info.thread_id
or destination.numel() * destination.element_size() < info.size): or destination.numel() * destination.element_size() < info.size
or tensor.numel() * tensor.element_size() != info.size
or tensor.storage_offset() != 0
or not tensor.is_contiguous()):
return False return False
if info.size == 0: if info.size == 0: