Skip to content

[BUG] Incorrect behavior of sparse matrix-matrix multiplication #6219

@kose-y

Description

@kose-y

This PyTorch bug was introduced by #4707.
Unlike claimed there, indices should not only be unique, but also be sorted in coalesced matrix for correct behavior of matrix multiplication. This raises a major issue when performing matrix multiplication with coalesced then transposed matrix.

The following is tested on 2e156f3, but any version after 5e72d7a will have the same behavior.

import torch
idx = torch.LongTensor([[0,1,2], [2,1,0]])
val = torch.ones(3)
D = torch.sparse.FloatTensor(idx,val,torch.Size([3,3]))
Dc = D.coalesce()
x = torch.ones((3,1))
torch.mm(D.t(), x)
 1
 1
 1
[torch.FloatTensor of size (3,1)]
torch.mm(Dc.t(), x)
 3
 0
 0
[torch.FloatTensor of size (3,1)]

I will create a pull request regarding this and #6171 later today.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions