snap-stanford / ogb

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

fix bug in proteins example #263

Closed TaoLbr1993 closed 3 years ago

TaoLbr1993 commented 3 years ago

Hi there, I'm using ogb and just got an error when I run the example GNN code for ogbn-proteins(ogb/examples/nodeproppred/proteins/gnn.py):

File "/Users/qiantao/Mywork/Project/oneID mining/ogb-test/ogb/examples/nodeproppred/proteins/gnn.py", line 74, in train out = model(data.x, data.adj_t)[train_idx] File "/opt/miniconda3/envs/autogl/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl return forward_call(*input, **kwargs) File "/Users/qiantao/Mywork/Project/oneID mining/ogb-test/ogb/examples/nodeproppred/proteins/gnn.py", line 36, in forward x = conv(x, adj_t) ... File "/opt/miniconda3/envs/autogl/lib/python3.9/site-packages/torch/nn/functional.py", line 1847, in linear return torch._C._nn.linear(input, weight, bias) RuntimeError: mat1 and mat2 shapes cannot be multiplied (1x132534 and 1x256)

It seems data.adj_t only contains adjacency information (data.adj_t.to_dense()=[132534, 132534]) and the code fails to aggregate the edge attributes to the nodes. Referring to MLP.py in the same directory, I modify the code to load the dataset without sparse transformer dataset = PygNodePropPredDataset(name='ogbn-proteins') and generate data.x and data.adj_t based on torch_scatter.scatter and torch_sparse.SparseTensor.

Hope this helps!

rusty1s commented 3 years ago

Thanks for spotting. I ended up modifying the ToSparseTensor transform to include the edge_attr argument.

TaoLbr1993 commented 3 years ago

Cool, that seems a more succinct fix.