pyg-team / pytorch_geometric

Graph Neural Network Library for PyTorch
https://pyg.org
MIT License
21.28k stars 3.65k forks source link

Bug: tuple indices must be integers or slices, not tuple #3306

Open 24kobebryant opened 3 years ago

24kobebryant commented 3 years ago

Hi, I'm going to test the official node2vec example but I got an error as follows:

Traceback (most recent call last):
  File "test.py", line 51, in <module>
    main()
  File "test.py", line 44, in main
    loss = train()
  File "test.py", line 26, in train
    for pos_rw, neg_rw in loader:
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 435, in __next__
    data = self._next_data()
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1085, in _next_data
    return self._process_data(data)
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1111, in _process_data
    data.reraise()
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/_utils.py", line 428, in reraise
    raise self.exc_type(msg)
TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loop
    data = fetcher.fetch(index)
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 47, in fetch
    return self.collate_fn(data)
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch_geometric/nn/models/node2vec.py", line 116, in sample
    return self.pos_sample(batch), self.neg_sample(batch)
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch_geometric/nn/models/node2vec.py", line 97, in pos_sample
    walks.append(rw[:, j:j + self.context_size])
TypeError: tuple indices must be integers or slices, not tuple

The example runs smoothly on pytorch 1.6, but the error above occurs on pytorch 1.7, so I assume this is a pytorch issue? Here are the version of the librarys:

torch                 1.7.0
torch-cluster         1.5.9
torch-geometric       1.6.1
torch-scatter         2.0.7
torch-sparse          0.6.9
torch-spline-conv     1.2.1

Looking forward to your reply!

rusty1s commented 3 years ago

Can you test the node2vec.py example that is provided with PyG 1.6.1, see here?

24kobebryant commented 3 years ago

Can you test the node2vec.py example that is provided with PyG 1.6.1, see here?

Okay, I'll try it tonight.

24kobebryant commented 3 years ago

Can you test the node2vec.py example that is provided with PyG 1.6.1, see here?

I have tried this link. Then also occurs this problem:

Traceback (most recent call last):
  File "test2.py", line 42, in <module>
    loss = train()
  File "test2.py", line 23, in train
    for pos_rw, neg_rw in loader:
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 435, in __next__
    data = self._next_data()
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1085, in _next_data
    return self._process_data(data)
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1111, in _process_data
    data.reraise()
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/_utils.py", line 428, in reraise
    raise self.exc_type(msg)
TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loop
    data = fetcher.fetch(index)
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 47, in fetch
    return self.collate_fn(data)
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch_geometric/nn/models/node2vec.py", line 116, in sample
    return self.pos_sample(batch), self.neg_sample(batch)
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch_geometric/nn/models/node2vec.py", line 97, in pos_sample
    walks.append(rw[:, j:j + self.context_size])
TypeError: tuple indices must be integers or slices, not tuple
24kobebryant commented 3 years ago

Can you test the node2vec.py example that is provided with PyG 1.6.1, see here?

I have tried this link. Then also occurs this problem:

Traceback (most recent call last):
  File "test2.py", line 42, in <module>
    loss = train()
  File "test2.py", line 23, in train
    for pos_rw, neg_rw in loader:
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 435, in __next__
    data = self._next_data()
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1085, in _next_data
    return self._process_data(data)
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 1111, in _process_data
    data.reraise()
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/_utils.py", line 428, in reraise
    raise self.exc_type(msg)
TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loop
    data = fetcher.fetch(index)
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 47, in fetch
    return self.collate_fn(data)
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch_geometric/nn/models/node2vec.py", line 116, in sample
    return self.pos_sample(batch), self.neg_sample(batch)
  File "/home/mengxinkai-20/anaconda3/envs/autogrl/lib/python3.7/site-packages/torch_geometric/nn/models/node2vec.py", line 97, in pos_sample
    walks.append(rw[:, j:j + self.context_size])
TypeError: tuple indices must be integers or slices, not tuple

Does the pytorch version have to be 1.6 ?

rusty1s commented 3 years ago

PyG 1.6.1 was indeed released for PyTorch 1.6, and only later versions might be able to support PyTorch 1.7.0. If there is any possibility, you can either try to upgrade PyG to a later release, or downgrade PyTorch to 1.6.

24kobebryant commented 3 years ago

PyG 1.6.1 was indeed released for PyTorch 1.6, and only later versions might be able to support PyTorch 1.7.0. If there is any possibility, you can either try to upgrade PyG to a later release, or downgrade PyTorch to 1.6.

Thank u, I'll try to upgrade PyG to a later release and then run this code again. As for downgrading PyTorch version, 3090 don't support Pytorch 1.6.