Hi DGL team,
I am interested in the new dgl sparse api, and experimenting with the tutorial examples. However, I received the attribute error when I ran the following code:
import torch
import dgl.sparse as dglspi = torch.tensor([[1, 1, 2],
[0, 2, 0]])
A = dglsp.spmatrix(i)
Environment:
-
System: MacOS 13.2
-
Python: 3.9.6
-
PyTorch: 1.13.1
-
DGL: 1.0.0
Could you please take a look? Thanks a lot.
The full error message is
RuntimeError Traceback (most recent call last)
File ~/Library/Python/3.9/lib/python/site-packages/torch/_ops.py:501, in _OpNamespace.getattr(self, op_name)
500 try:
→ 501 op, overload_names = torch._C._jit_get_operation(qualified_op_name)
502 except RuntimeError as e:
503 # Turn this into AttributeError so getattr(obj, key, default)
504 # works (this is called by TorchScript with origin)RuntimeError: No such operator dgl_sparse::from_coo
The above exception was the direct cause of the following exception:
AttributeError Traceback (most recent call last)
Cell In [6], line 1
----> 1 A = dglsp.spmatrix(i)File ~/Library/Python/3.9/lib/python/site-packages/dgl/sparse/sparse_matrix.py:524, in spmatrix(indices, val, shape)
456 def spmatrix(
457 indices: torch.Tensor,
458 val: Optional[torch.Tensor] = None,
459 shape: Optional[Tuple[int, int]] = None,
460 ) → SparseMatrix:
461 r""“Creates a sparse matrix from Coordinate format indices.
462
463 Parameters
(…)
522 shape=(3, 5), nnz=3, val_size=(2,))
523 “””
→ 524 return from_coo(indices[0], indices[1], val, shape)File ~/Library/Python/3.9/lib/python/site-packages/dgl/sparse/sparse_matrix.py:611, in from_coo(row, col, val, shape)
605 val = torch.ones(row.shape[0]).to(row.device)
607 assert (
608 val.dim() <= 2
609 ), “The values of a SparseMatrix can only be scalars or vectors.”
→ 611 return SparseMatrix(torch.ops.dgl_sparse.from_coo(row, col, val, shape))File ~/Library/Python/3.9/lib/python/site-packages/torch/_ops.py:505, in _OpNamespace.getattr(self, op_name)
501 op, overload_names = torch._C._jit_get_operation(qualified_op_name)
502 except RuntimeError as e:
503 # Turn this into AttributeError so getattr(obj, key, default)
504 # works (this is called by TorchScript with origin)
→ 505 raise AttributeError(
506 f"’_OpNamespace’ ‘{self.name}’ object has no attribute ‘{op_name}’"
507 ) from e
509 # let the script frontend know that op is identical to the builtin op
510 # with qualified_op_name
511 torch.jit._builtins._register_builtin(op, qualified_op_name)AttributeError: ‘_OpNamespace’ ‘dgl_sparse’ object has no attribute ‘from_coo’