Disable pinning check when loading sparse tensors (#154638)

Disables pinning check as unnecessary and to fix https://github.com/pytorch/pytorch/issues/153143 when loading sparse tensor from external storage with sparse tensor invariants check enabled.

Fixes https://github.com/pytorch/pytorch/issues/153143 .

For FC, to be landed two weeks after https://github.com/pytorch/pytorch/pull/154617, see https://github.com/pytorch/pytorch/pull/154617#issuecomment-2919643612.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/154638
Approved by: https://github.com/amjames, https://github.com/ngimel
This commit is contained in:
Pearu Peterson
2025-06-17 20:01:25 +00:00
committed by PyTorch MergeBot
parent 8f02161d10
commit c177abd217
2 changed files with 67 additions and 10 deletions

View File

@ -282,14 +282,17 @@ def _validate_loaded_sparse_tensors():
_sparse_tensors_to_validate.clear()
return
try:
# We disable pinning check (see check_pinning=False below) to
# avoid gh-153143. In fact, pinning check is unnecessary
# anywhy when loading sparse data from external sources.
for t in _sparse_tensors_to_validate:
if True:
# Temporarily disable sparse tensor validation due to
# gh-153143.
pass
elif t.layout is torch.sparse_coo:
if t.layout is torch.sparse_coo:
torch._validate_sparse_coo_tensor_args(
t._indices(), t._values(), t.size(), t.is_coalesced()
t._indices(),
t._values(),
t.size(),
t.is_coalesced(),
check_pinning=False,
)
elif t.layout in {
torch.sparse_csr,
@ -310,7 +313,12 @@ def _validate_loaded_sparse_tensors():
t.row_indices(),
)
torch._validate_sparse_compressed_tensor_args(
compressed_indices, plain_indices, t.values(), t.size(), t.layout
compressed_indices,
plain_indices,
t.values(),
t.size(),
t.layout,
check_pinning=False,
)
else:
raise NotImplementedError(