You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently using CoLA version 0.0.6 (which seems uses COO format for Sparse operator) and PyTorch version 2.3.1, and I’ve encountered an issue when working with sparse matrices. I’ve noticed that I get inconsistent results when comparing the dense representations of sparse matrices created using torch.sparse_coo_tensor and CoLA's Sparse operator. Here's a simplified version of my code:
from cola.ops import Sparse
import torch
N = 4
nnz = 4
row = torch.tensor([1, 3, 2, 2 ])
col = torch.tensor([1, 3, 2, 1 ])
data = torch.rand(nnz, dtype=torch.float64)
indices = torch.stack([row, col])
coo_tensor_torch = torch.sparse_coo_tensor(indices, data, size=[N, N])
coo_op_cola = Sparse(data, row, col, (N,N))
torch.isclose(coo_op_cola.to_dense(),coo_tensor_torch.to_dense()).all() # This outputs False
The issue arises when I compare the dense matrix representations of the CoLA sparse matrix and the PyTorch sparse matrix. The result of torch.isclose(...).all() is False, suggesting a mismatch between the two.
However, when I sort the row and column indices before creating the sparse matrix, the results match, as shown in this modified version:
from cola.ops import Sparse
import torch
N = 4
nnz = 4
row = torch.sort(torch.tensor([1, 3, 2, 2 ]))[0]
col = torch.sort(torch.tensor([1, 3, 2, 1 ]))[0]
data = torch.rand(nnz, dtype=torch.float64)
indices = torch.stack([row, col])
coo_tensor_torch = torch.sparse_coo_tensor(indices, data, size=[N, N])
coo_op_cola = Sparse(data, row, col, (N,N))
torch.isclose(coo_op_cola.to_dense(),coo_tensor_torch.to_dense()).all()
I'm not sure why this is happening. I'm not sure if this is a bug or something I haven't understoond.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm currently using CoLA version 0.0.6 (which seems uses COO format for Sparse operator) and PyTorch version 2.3.1, and I’ve encountered an issue when working with sparse matrices. I’ve noticed that I get inconsistent results when comparing the dense representations of sparse matrices created using torch.sparse_coo_tensor and CoLA's Sparse operator. Here's a simplified version of my code:
The issue arises when I compare the dense matrix representations of the CoLA sparse matrix and the PyTorch sparse matrix. The result of torch.isclose(...).all() is False, suggesting a mismatch between the two.
However, when I sort the row and column indices before creating the sparse matrix, the results match, as shown in this modified version:
I'm not sure why this is happening. I'm not sure if this is a bug or something I haven't understoond.
Beta Was this translation helpful? Give feedback.
All reactions