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

Bool tensor does not support the - operator #616

Closed
WilliamCCHuang opened this issue Aug 11, 2019 · 11 comments
Closed

Bool tensor does not support the - operator #616

WilliamCCHuang opened this issue Aug 11, 2019 · 11 comments

Comments

@WilliamCCHuang
Copy link

🐛 Bug

Hi, this tool is very powerful and amazing. Thanks a lot!

However, when I ran gcn.py from example for testing, an error occurred:

Traceback (most recent call last):
File "gcn.py", line 55, in
train()
File "gcn.py", line 39, in train
F.nll_loss(model()[data.train_mask], data.y[data.train_mask]).backward()
File "/Users/william/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in call
result = self.forward(*input, **kwargs)
File "gcn.py", line 25, in forward
x = F.relu(self.conv1(x, edge_index))
File "/Users/william/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 547, in call
result = self.forward(*input, **kwargs)
File "/Users/william/anaconda3/lib/python3.6/site-packages/torch_geometric/nn/conv/gcn_conv.py", line 100, in forward
self.improved, x.dtype)
File "/Users/william/anaconda3/lib/python3.6/site-packages/torch_geometric/nn/conv/gcn_conv.py", line 78, in norm
edge_index, edge_weight, fill_value, num_nodes)
File "/Users/william/anaconda3/lib/python3.6/site-packages/torch_geometric/utils/loop.py", line 107, in add_remaining_self_loops
inv_mask = 1 - mask
File "/Users/william/anaconda3/lib/python3.6/site-packages/torch/tensor.py", line 325, in rsub
return _C._VariableFunctions.rsub(self, other)
RuntimeError: Subtraction, the - operator, with a bool tensor is not supported. If you are trying to invert a mask, use the ~ or bitwise_not() operator instead.

It seems that bool tensor does not support the - operator yet. So I modified the line 107 in loop.py as:

inv_mask = ~mask # inv_mask = 1 - mask

and then re-run gcn.py. The result shows that it works!

...
Epoch: 200, Train: 1.0000, Val: 0.8080, Test: 0.8240

Environment

  • OS: macOS 10.14.6
  • Python version: 3.6
  • PyTorch version: 1.2.0
  • CUDA/cuDNN version: 10.1
  • GCC version: clang
  • Any other relevant information:
@tiancheng-zhi
Copy link

I met the same issue. It might be because of the new pytorch version

@rusty1s
Copy link
Member

rusty1s commented Aug 12, 2019

Thank you. This is already fixed in master, so installing from source should fix it. I will craft a new minor release soon.

@rusty1s rusty1s closed this as completed Aug 12, 2019
@Magnetar99
Copy link

Hey, @rusty1s thanks for this amazing library.

I met the same issue for Knn graph. I even installed the latest commit but the issue still persisted. Also, when I run tests, the issue repeats at multiple times for knn related functions.

Other than the above errors, I also see failures with the error "ValueError: multi_class should be either multinomial or ovr, got auto" in the file logistic.py and there is also assertion error in the file test_signed_gcn.py.

@rusty1s
Copy link
Member

rusty1s commented Aug 12, 2019

Please update torch-cluster to version 1.4.4. The SignedGCN bug should be fixed in PyG master by now.

@neonb88
Copy link

neonb88 commented Aug 20, 2019

Maybe I'm misunderstood, but doing pip install torch-cluster didn't fix the issue for me

@rusty1s
Copy link
Member

rusty1s commented Aug 20, 2019

Are you sure you have the latest version installed? You can check this via

import torch_cluster
print(torch_cluster.__version__)

And update via

pip install --upgrade torch-cluster

@neonb88
Copy link

neonb88 commented Aug 20, 2019

I ended up solving the problem the way the OP solved it. I may take a look at your solution later. Thanks for your contributions to the open source world, rusty1s!

@tjiagoM
Copy link
Contributor

tjiagoM commented Aug 26, 2019

Hello, I'm running the basic example of GCN under "Learning Methods on Graphs" in the introduction section: https://pytorch-geometric.readthedocs.io/en/latest/notes/introduction.html

And I'm having the same issue. Should I downgrade pytorch, as this was working before? I have version 1.4.4 of torch_cluster already. My versions of pytorch are:

>>> import torch ; print(torch.__version__)
1.2.0

>>> import torchvision ; print(torchvision.__version__)
0.4.0a0+6b959ee

>>> import torch_cluster ; print(torch_cluster.__version__)
1.4.4

import torch_geometric ; print(torch_geometric.__version__)
1.3.0

Any suggestions?

@rusty1s
Copy link
Member

rusty1s commented Aug 26, 2019

This is a bug introduced by PyTorch 1.2. You can install PyTorch Geometric from master to fix this (just clone the repository and run python setup.py install). I will craft a new release soon to fix this.

@tjiagoM
Copy link
Contributor

tjiagoM commented Aug 29, 2019

@rusty1s thanks for the update! I just wanted to add that now, when you execute the example I mentioned, we receive a warning:

UserWarning: indexing with dtype torch.uint8 is now deprecated, please use a dtype torch.bool instead.

According to pytorch/pytorch#24918, in the future this will raise an error, so might be worth it to update the example.

Thanks for such awesome tool!

@rusty1s
Copy link
Member

rusty1s commented Aug 29, 2019

Thank you for the reminder, will work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants