pyg-lib icon indicating copy to clipboard operation
pyg-lib copied to clipboard

Errors when sampling neighbors with disjoint setting

Open joneswong opened this issue 1 year ago • 4 comments

🐛 Describe the bug

from ogb.nodeproppred import PygNodePropPredDataset
from torch_geometric.loader import NeighborLoader



if __name__ == '__main__':
    dataset = PygNodePropPredDataset(name='ogbn-products', root='~/GNSL/on_products/dataset')
    split_idx= dataset.get_idx_split()
    data = dataset[0]
    # transform_sampler_output
    #print(data.x, data.x.shape, data.x.dtype)

    loader = NeighborLoader(data, num_neighbors=[10, 10], batch_size=2, disjoint=1, input_nodes=split_idx['train'])
    for mini_batch in loader:
        print(mini_batch)
        break

When I run python3 data.py, this program encounters exception:

Traceback (most recent call last): File "/root/GG4RL/data.py", line 14, in for mini_batch in loader: File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch_geometric/loader/base.py", line 36, in next return self.transform_fn(next(self.iterator)) File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 633, in next data = self._next_data() File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 677, in _next_data data = self._dataset_fetcher.fetch(index) # may raise StopIteration File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 54, in fetch return self.collate_fn(data) File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch_geometric/loader/node_loader.py", line 117, in collate_fn out = self.node_sampler.sample_from_nodes(input_data) File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch_geometric/sampler/neighbor_sampler.py", line 174, in sample_from_nodes return node_sample(inputs, self._sample) File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch_geometric/sampler/neighbor_sampler.py", line 358, in node_sample out = sample_fn(seed, seed_time) File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch_geometric/sampler/neighbor_sampler.py", line 282, in _sample out = torch.ops.pyg.neighbor_sample( File "/root/miniconda3/envs/digress/lib/python3.10/site-packages/torch/_ops.py", line 502, in call return self._op(*args, **kwargs or {}) RuntimeError: pyg::neighbor_sample() Expected a value of type 'Optional[Tensor]' for argument 'edge_weight' but instead found type 'bool'. Position: 6 Value: True Declaration: pyg::neighbor_sample(Tensor rowptr, Tensor col, Tensor seed, int[] num_neighbors, Tensor? time=None, Tensor? seed_time=None, Tensor? edge_weight=None, bool csc=False, bool replace=False, bool directed=True, bool disjoint=False, str temporal_strategy="uniform", bool return_edge_id=True) -> (Tensor, Tensor, Tensor, Tensor?, int[], int[]) Cast error details: Unable to cast True to Tensor

Environment

  • pyg-lib version: '0.3.1+pt20cu118'
  • PyTorch version: '2.0.1+cu118'
  • OS: Ubuntu 18.04
  • Python version: 3.10
  • CUDA/cuDNN version: 11.8
  • How you installed PyTorch and pyg-lib (conda, pip, source): pip
  • Any other relevant information: installed GLIBC-2.9 and pytorch_geometric: 2.3.1

joneswong avatar Mar 15 '24 05:03 joneswong

I downgrade my pyg_lib from 0.4.0 to 0.3.1 according to another issue when I encountered another similar issue. However, I encounter this one.

If this issue cannot be resolved now, could you kindly tell me how to build a dataloader, where each mini-batch contains batch_size independent ego-graphs of sampled target nodes, i.e., providing a similar result as disjoint=True?

I think one way is to pass in an transform_sampler_output implemented by myself, which would not combine the ego-graphs into one global subgraph. Could you give me an toy example to show how to achieve my purpose? Thanks!

joneswong avatar Mar 15 '24 05:03 joneswong

Even thought I changed disjoint to False, it is still such an error there. It seems that pyg_lib causes the issues. torch_sparse works well for disjoint=false.

joneswong avatar Mar 15 '24 05:03 joneswong

Hi, I'm having the same exact problem and would also appreciate the help! Here are my

torch==2.2.0+cu118
torch_cluster==1.6.3+pt22cu118
torch_geometric==2.4.0
torch_scatter==2.1.2+pt22cu118
torchaudio==2.2.0+cu118
torchmetrics==0.11.4
torchvision==0.17.0+cu118
pyg_lib==0.4.0

pujacomputes avatar Mar 17 '24 16:03 pujacomputes

You either need torch-geometric==2.4.0 and pyg-lib==0.3.0, or torch-geometric==2.5.0 and pyg-lib==0.4.0.

rusty1s avatar Mar 18 '24 14:03 rusty1s