Skip to content

uncoalesced add(dense, sparse) missing sparse values for torch.int16 on cuda #29153

@nairbv

Description

@nairbv

🐛 Bug

When adding (or calling to_dense()) on uncoalesced sparse tensors of dtype int16, values seem to be lost.

To Reproduce

In [23]: sparse=torch.sparse_coo_tensor(indices=torch.tensor([[0,0],[1,1]]), values=torch.tensor([5, 6], dtype=torch.int16), size=(2,2), device='cuda', dtype=torch.int16 )

In [24]: sparse
Out[24]:
tensor(indices=tensor([[0, 0],
                       [1, 1]]),
       values=tensor([5, 6]),
       device='cuda:0', size=(2, 2), nnz=2, dtype=torch.int16,
       layout=torch.sparse_coo)

In [25]: sparse.coalesce()
Out[25]:
tensor(indices=tensor([[0],
                       [1]]),
       values=tensor([11]),
       device='cuda:0', size=(2, 2), nnz=1, dtype=torch.int16,
       layout=torch.sparse_coo)

In [26]: sparse.to_dense()
Out[26]:
tensor([[0, 0],
        [0, 0]], device='cuda:0', dtype=torch.int16)

In [27]: sparse.coalesce().to_dense()
Out[27]:
tensor([[ 0, 11],
        [ 0,  0]], device='cuda:0', dtype=torch.int16)

In [30]: torch.add(torch.zeros([2,2],dtype=torch.int16, device='cuda'), sparse)
Out[30]:
tensor([[0, 0],
        [0, 0]], device='cuda:0', dtype=torch.int16)

Wasn't able to repro on CPU or with any other dtype.

Expected behavior

in above code, expecting tensor([[ 0, 11], [ 0, 0]], device='cuda:0', dtype=torch.int16).
sparse.coalesce().to_dense() should equal sparse.to_dense() or raise an error. I believe to_dense is impacted because it's calling add.

Environment

from master on devgpu

cc @ezyang @gchanan @zou3519 @jerryzh168 @ngimel @vincentqb

Metadata

Metadata

Assignees

Labels

high prioritymodule: cudaRelated to torch.cuda, and CUDA support in generalmodule: sparseRelated to torch.sparsetriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions