pytorch
9f97b7c4 - Add integer overflow checks for large compressed tensor dimensions and nnz (#102530)

Commit
1 year ago
Add integer overflow checks for large compressed tensor dimensions and nnz (#102530) With the previous PR allowing large compressed tensors (dimensions larger than `2 ** 31 - 1`), sparse compressed tensor invariants checks may give false-positive results: ```python >>> nnz=2**31 >>> torch.sparse.check_sparse_tensor_invariants.enable() >>> torch.sparse_csr_tensor(torch.arange(nnz+1, dtype=torch.int32), torch.zeros(nnz, dtype=torch.int32), torch.ones(nnz), (nnz, 1)) tensor(crow_indices=tensor([ 0, 1, 2, ..., 2147483646, 2147483647, -2147483648]), col_indices=tensor([0, 0, 0, ..., 0, 0, 0]), values=tensor([1., 1., 1., ..., 1., 1., 1.]), size=(2147483648, 1), nnz=2147483648, layout=torch.sparse_csr) ``` (notice that the last entry in `crow_indices` is invalid) or raise a bogus exception as in ```python >>> torch.sparse_csr_tensor(torch.arange(nnz+1, dtype=torch.int32), torch.arange(nnz, dtype=torch.int32), torch.ones(nnz), (nnz, 1)) Traceback (most recent call last): File "<stdin>", line 1, in <module> RuntimeError: `0 <= col_indices < ncols` is not satisfied. ``` (notice that `col_indices` is actually valid). This PR fixes the above-reported bugs by introducing integer overflow checks for sparse compressed tensors dimensions as well as nnz. Pull Request resolved: https://github.com/pytorch/pytorch/pull/102530 Approved by: https://github.com/nikitaved
Author
Committer
Parents
Loading