Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

run code on PROTEINS dataset error #7

Open
ColdenChan opened this issue Sep 5, 2019 · 4 comments
Open

run code on PROTEINS dataset error #7

ColdenChan opened this issue Sep 5, 2019 · 4 comments

Comments

@ColdenChan
Copy link

ColdenChan commented Sep 5, 2019

Hi, thanks for your code. But when I run python main.py --dataset PROTEINS, there is an error as follows:

Traceback (most recent call last):
  File "main.py", line 99, in <module>
    test_acc,test_loss = test(model,test_loader)
  File "main.py", line 65, in test
    out = model(data)
  File "/home/colden/.conda/envs/tg/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/colden/SAGPool/networks.py", line 45, in forward
    x, edge_index, _, batch, _ = self.pool3(x, edge_index, None, batch)
  File "/home/colden/.conda/envs/tg/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/colden/SAGPool/layers.py", line 20, in forward
    perm = topk(score, self.ratio, batch)
  File "/home/colden/.conda/envs/tg/lib/python3.6/site-packages/torch_geometric/nn/pool/topk_pool.py", line 18, in topk
    num_nodes = scatter_add(batch.new_ones(x.size(0)), batch, dim=0)
IndexError: dimension specified as 0 but tensor has no dimensions```

Can you help me to fix the bug? Thanks very much.
@ColdenChan
Copy link
Author

Hi, thanks for your code. But when I run python main.py --dataset PROTEINS, there is an error as follows:
Validation loss:0.513576095168655 accuracy:0.7567567567567568 Traceback (most recent call last): File "main.py", line 99, in <module> test_acc,test_loss = test(model,test_loader) File "main.py", line 65, in test out = model(data) File "/home/colden/.conda/envs/tg/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in __call__ result = self.forward(*input, **kwargs) File "/home/colden/SAGPool/networks.py", line 45, in forward x, edge_index, _, batch, _ = self.pool3(x, edge_index, None, batch) File "/home/colden/.conda/envs/tg/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in __call__ result = self.forward(*input, **kwargs) File "/home/colden/SAGPool/layers.py", line 20, in forward perm = topk(score, self.ratio, batch) File "/home/colden/.conda/envs/tg/lib/python3.6/site-packages/torch_geometric/nn/pool/topk_pool.py", line 18, in topk num_nodes = scatter_add(batch.new_ones(x.size(0)), batch, dim=0) IndexError: dimension specified as 0 but tensor has no dimensions
Can you help me to fix the bug? Thanks very much.

When I set testdata batchsize=2 (test_loader = DataLoader(test_set,batch_size=2,shuffle=False)), it will be fine. However, when I run then code in dataset ENZYMES, it report the following error:

/opt/conda/conda-bld/pytorch_1565272271120/work/aten/src/ATen/native/cuda/IndexKernel.cu:60: lambda [](int)->auto::operator()(int)->auto: block: [150,0,0], thread: [58,0,0] Assertion `index >= -sizes[i] && index < sizes[i] && "index out of bounds"` failed.
/opt/conda/conda-bld/pytorch_1565272271120/work/aten/src/ATen/native/cuda/IndexKernel.cu:60: lambda [](int)->auto::operator()(int)->auto: block: [150,0,0], thread: [59,0,0] Assertion `index >= -sizes[i] && index < sizes[i] && "index out of bounds"` failed.
/opt/conda/conda-bld/pytorch_1565272271120/work/aten/src/ATen/native/cuda/IndexKernel.cu:60: lambda [](int)->auto::operator()(int)->auto: block: [150,0,0], thread: [60,0,0] Assertion `index >= -sizes[i] && index < sizes[i] && "index out of bounds"` failed.
/opt/conda/conda-bld/pytorch_1565272271120/work/aten/src/ATen/native/cuda/IndexKernel.cu:60: lambda [](int)->auto::operator()(int)->auto: block: [150,0,0], thread: [61,0,0] Assertion `index >= -sizes[i] && index < sizes[i] && "index out of bounds"` failed.
/opt/conda/conda-bld/pytorch_1565272271120/work/aten/src/ATen/native/cuda/IndexKernel.cu:60: lambda [](int)->auto::operator()(int)->auto: block: [150,0,0], thread: [62,0,0] Assertion `index >= -sizes[i] && index < sizes[i] && "index out of bounds"` failed.
/opt/conda/conda-bld/pytorch_1565272271120/work/aten/src/ATen/native/cuda/IndexKernel.cu:60: lambda [](int)->auto::operator()(int)->auto: block: [150,0,0], thread: [63,0,0] Assertion `index >= -sizes[i] && index < sizes[i] && "index out of bounds"` failed.
Traceback (most recent call last):
  File "main.py", line 79, in <module>
    out = model(data)
  File "/usr/local/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/colden/SAGPool/networks.py", line 45, in forward
    x, edge_index, _, batch, _ = self.pool3(x, edge_index, None, batch)
  File "/usr/local/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/colden/SAGPool/layers.py", line 24, in forward
    edge_index, edge_attr, perm, num_nodes=score.size(0))
  File "/usr/local/anaconda3/lib/python3.7/site-packages/torch_geometric/nn/pool/topk_pool.py", line 59, in filter_adj
    row, col = row[mask], col[mask]
RuntimeError: copy_if failed to synchronize: device-side assert triggered

I am not sure how to fix this bug.

@ThyrixYang
Copy link

ThyrixYang commented Oct 31, 2019

I encountered the same error.
It seems an error related to topk in pytorch-geometric.

I opened an issue at pytorch-geometric repo here

pyg-team/pytorch_geometric#775

@rusty1s
Copy link

rusty1s commented Oct 31, 2019

I identified the issue in the SAGPool layers.py code:

score = self.score_layer(x, edge_index).squeeze()

will actually squeeze the tensor to a 0-dimensional tensor if the input has shape [1, 1]. Replacing this line with

score = self.score_layer(x, edge_index).squeeze(-1)

fixes the error.

@ColdenChan
Copy link
Author

I identified the issue in the SAGPool layers.py code:

score = self.score_layer(x, edge_index).squeeze()

will actually squeeze the tensor to a 0-dimensional tensor if the input has shape [1, 1]. Replacing this line with

score = self.score_layer(x, edge_index).squeeze(-1)

fixes the error.

Thank you very much!

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

No branches or pull requests

3 participants