question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: `GCNConv` in `to_hetero` with single node type

See original GitHub issue

🐛 Describe the bug

I just started using heterogeneous graphs, so far I have roughly 1 year experience with homogeneous graphs using your library. I have a graph with just 1 node type (“gene”) but multiple edge types between the nodes. My HeteroData object prints as follows:

HeteroData(
  gene={
    x=[16433, 93],
    y=[16433],
    train_mask=[16433],
    test_mask=[16433],
    val_mask=False
  },
  (gene, BioPlex30HCT116, gene)={ edge_index=[2, 95370] },
  (gene, BioPlex30293T, gene)={ edge_index=[2, 156370] },
  (gene, HuRI, gene)={ edge_index=[2, 74488] }
)

I convert my GCN-based model (that runs fine with a homogeneous Data object) using the to_hetero() function.

I then pass my data into the model as follows:

out = model(data.x_dict, data.edge_index_dict)

where data is the HeteroData Object described above.

However, I get an error and I think it is because it expects edge_weight somewhere:

Traceback (most recent call last):
    out = model(data.x_dict, data.edge_index_dict)
  File "/home/fratajcz/anaconda3/envs/compat/lib/python3.7/site-packages/torch/fx/graph_module.py", line 308, in wrapped_call
    return cls_call(self, *args, **kwargs)
  File "/home/fratajcz/anaconda3/envs/compat/lib/python3.7/site-packages/torch/fx/graph_module.py", line 308, in wrapped_call
    return cls_call(self, *args, **kwargs)
  File "/home/fratajcz/anaconda3/envs/compat/lib/python3.7/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "<eval_with_key_1>", line 7, in forward
    edge_weight__gene__BioPlex30HCT116__gene = edge_weight.get(('gene', 'BioPlex30HCT116', 'gene'))
AttributeError: 'NoneType' object has no attribute 'get'

Do I have to specify edge weights in heterogeneous graphs? The Documentation doesnt mention it. It is weird that the traceback does mention only torch packages and not torch_geometric.

Cheers and thanks, Florin

Environment

  • PyG version: 2.0.1
  • PyTorch version: 1.8.0
  • OS: CentOS Linux 7
  • Python version: 3.7
  • CUDA/cuDNN version: irrelevant
  • How you installed PyTorch and PyG (conda, pip, source): conda
  • Any other relevant information (e.g., version of torch-scatter): torch_scatter: 2.0.8

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rusty1scommented, Nov 26, 2022

Yes, you can only use GCNConv for passing messages to the same node type, e.g.:

HeteroConv({
    ...
    ('movie', 'is_similar', 'movie'): GCNConv(...),
    ...
})

This is a limitation of GCNConv as it does not support bipartite message passing.

0reactions
aayyad89commented, Nov 28, 2022

Thanks, I did not get that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

torch_geometric.nn.to_hetero_transformer - PyTorch Geometric
Source code for torch_geometric.nn.to_hetero_transformer. import copy import warnings from collections import defaultdict, ...
Read more >
Heterogeneous Graph Learning - PyTorch Geometric
Heterogeneous graphs come with different types of information attached to nodes and edges. Thus, a single node or edge feature tensor cannot hold...
Read more >
torch_geometric.nn.to_hetero_with_bases_transformer
This allows handling of node and edge features with varying feature dimensionality across different types. (default: :obj:`None`) input_map (Dict[str, str], ...
Read more >
torch_geometric.explain — pytorch_geometric documentation
the different type of masks for node and edges (e.g., mask="object" or ... Should be kept to None in case the model only...
Read more >
torch_geometric.nn — pytorch_geometric documentation
GCNConv. The graph convolutional operator from the "Semi-supervised ... Edge type needs to be a one-dimensional torch.long tensor which stores a relation ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found