snap-stanford / ogb

Benchmark datasets, data loaders, and evaluators for graph machine learning
https://ogb.stanford.edu
MIT License
1.89k stars 397 forks source link

AttributeError: 'GlobalStorage' object has no attribute 'num_nodes' #294

Closed XikunHuang closed 2 years ago

XikunHuang commented 2 years ago

Hi! I got an error when run python3 examples/linkproppred/ddi/gnn.py

Environments pytorch: 1.10.0 torch_geometric: 2.0.3

Namespace(device=0, log_steps=1, use_sage=False, num_layers=2, hidden_channels=256, dropout=0.5, batch_size=65536, lr=0.005, epochs=200, eval_steps=5, runs=10) Downloading http://snap.stanford.edu/ogb/data/linkproppred/ddi.zip Downloaded 0.04 GB: 100%|███████████████████████████████████████████████████████████████████████████████████| 46/46 [00:41<00:00, 1.12it/s] Extracting dataset/ddi.zip Processing... Loading necessary files... This might take a while. Processing graphs... 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 48.51it/s] Converting graphs into PyG objects... 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 2250.16it/s] Saving... Done! /data/huangxikun/opt/miniconda3/envs/gnn/lib/python3.9/site-packages/torch_geometric/data/storage.py:259: UserWarning: Unable to accurately infer 'num_nodes' from the attribute set '{'edge_index'}'. Please explicitly set 'num_nodes' as an attribute of 'data' to suppress this warning warnings.warn( Traceback (most recent call last): File "/data/huangxikun/opt/miniconda3/envs/gnn/lib/python3.9/site-packages/torch_geometric/data/storage.py", line 48, in getattr return self[key] File "/data/huangxikun/opt/miniconda3/envs/gnn/lib/python3.9/site-packages/torch_geometric/data/storage.py", line 68, in getitem return self._mapping[key] KeyError: 'num_nodes' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/data/huangxikun/workspace_py/OBG_xk/ogb/examples/linkproppred/ddi/gnn.py", line 296, in main() File "/data/huangxikun/workspace_py/OBG_xk/ogb/examples/linkproppred/ddi/gnn.py", line 245, in main emb = torch.nn.Embedding(data.num_nodes, args.hidden_channels).to(device) File "/data/huangxikun/opt/miniconda3/envs/gnn/lib/python3.9/site-packages/torch_geometric/data/data.py", line 362, in getattr return getattr(self._store, key) File "/data/huangxikun/opt/miniconda3/envs/gnn/lib/python3.9/site-packages/torch_geometric/data/storage.py", line 50, in getattr raise AttributeError( AttributeError: 'GlobalStorage' object has no attribute 'num_nodes'

It seems that pyg dataloader does not set 'num_nodes' as an attribute of 'data'. I notice that there is a file dataset/ogbl_ddi/raw/num-node-list.csv.gz which contains the number of nodes of ddi network. So I think pyg dataloader should set this attibute, right? Thanks!

rusty1s commented 2 years ago

This is a bug in PyG which is now fixed, see https://github.com/pyg-team/pytorch_geometric/commit/af95df956f4473656f94d9ed04be0480534e397c.

Nonetheless, the DDI dataset should set the num_nodes attribute. This is now fixed inside OGB as well, see https://github.com/snap-stanford/ogb/pull/295.