Closed migalkin closed 2 years ago
Sorry for the late reply. It looks like this line and this line can not properly handle bool
. Not sure what I can do about this since they are both delegated to PyTorch.
Importantly, I recommend to make use of SparseTensor
for these operations:
from torch_sparse import SparseTensor
adj = SparseTensor.from_edge_index(index, value)
out = adj @ matrix
Sadly, it is not implemented for bool
either
RuntimeError: "_" not implemented for 'Bool'
due to the way how the PyTorch dispatcher works, see here. We would need to add explicit support for this :(
Wow, turns out the source of the problem is deeper than I expected and leads to the core of PyTorch! 👀
Okay, then maybe let's just insert a comment somewhere in the spmm function about expected data types of value
and matrix
? Eg,
value (:class:`Tensor`): The value tensor of sparse matrix. Expected dtypes are float/double/integer. Does not work for bool, half-precision and complex number dtypes
Thank you! I'll close the issue for now, but feel free to bring it up if pytorch internals change
There seems to be something weird happening when executing
spmm
over Boolean tensors on a GPU. We have a use-case when we could save a lot of memory and compute having bothvalues
andmatrix
as a bool tensor, but executing the same operation over those tensors on a CPU and GPU lead to surprisingly different results.I could reproduce it even with the adjacency matrix from the README
spmm
results are obviously different 🤔The only workaround I found so far is to convert
values
andmatrix
to float or int and then convert the resulting tensor to bool through a comparison, but that effectively removes all the benefits of doing spmm over binary tensors 🤔My environment is as following with CUDA 10.2