question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bool tensor does not support the `-` operator

See original GitHub issue

🐛 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 <module> 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:

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rusty1scommented, 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.

1reaction
rusty1scommented, Aug 12, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

RuntimeError: Subtraction, the `-` operator, with a bool tensor ...
RuntimeError: Subtraction, the `-` operator, with a bool tensor is not supported. If you are trying to invert a mask, use the `~`...
Read more >
Subtraction, the - operator, with a bool tensor is not supported ...
Subtraction, the `-` operator, with a bool tensor is not supported. Issue #73 · nlpyang/BertSum · GitHub.
Read more >
RuntimeError: Subtraction, the `-` operator, with a bool tensor ...
I received the following error while training the model : RuntimeError: Subtraction, the - operator, with a bool tensor is not supported. If...
Read more >
torch.any — PyTorch 1.13 documentation
This function matches the behaviour of NumPy in returning output of dtype bool for all supported dtypes except uint8 . For uint8 the...
Read more >
Subtraction, the `-` operator, with a bool tensor is not ...
operator, with a bool tensor is not supported. If you are trying to invert a mask, use the `~` or `logical_not()` operator instead....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found