Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Incorrect Sparse Operator Construction from COO to CSR #107

Open
alireza78h opened this issue Oct 18, 2024 · 0 comments
Open

[Bug] Incorrect Sparse Operator Construction from COO to CSR #107

alireza78h opened this issue Oct 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@alireza78h
Copy link

alireza78h commented Oct 18, 2024

🐛 Bug

The construction of the sparse operator during the conversion from COO (Coordinate format) to CSR (Compressed Sparse Row format) produces incorrect results.

To reproduce

from cola.ops import Sparse
import torch
row = torch.tensor([1, 3, 2, 2 ])
col = torch.tensor([1, 3, 2, 1 ])
data = torch.tensor([0.2643, 0.3951, 0.8338, 0.2440], dtype=torch.float64)
indices = torch.stack([row, col])
coo_tensor_torch = torch.sparse_coo_tensor(indices, data, size=[4, 4])
coo_op_cola = Sparse(data, row, col, (4,4))
print(torch.isclose(coo_op_cola.to_dense(),coo_tensor_torch.to_dense()).all())
# This outputs False
print(coo_op_cola.to_dense())
'''
tensor([[0.0000, 0.0000, 0.0000, 0.0000],
        [0.0000, 0.2643, 0.0000, 0.0000],
        [0.0000, 0.8338, 0.2440, 0.0000],
        [0.0000, 0.0000, 0.0000, 0.3951]], dtype=torch.float64)
'''
print(coo_tensor_torch.to_dense())
'''
tensor([[0.0000, 0.0000, 0.0000, 0.0000],
        [0.0000, 0.2643, 0.0000, 0.0000],
        [0.0000, 0.2440, 0.8338, 0.0000],
        [0.0000, 0.0000, 0.0000, 0.3951]], dtype=torch.float64)
'''

Expected Behavior

The two tensors should be equal but they are not.

System information

Please complete the following information:

  • CoLA version 0.0.6
  • PyTorch version 2.4.0
  • macOS 14.1
@alireza78h alireza78h added the bug Something isn't working label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant