pyg-team / pytorch_geometric

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

Bipartite check for adding self loops #6987

Open davidnarganes opened 1 year ago

davidnarganes commented 1 year ago

📚 Describe the documentation issue

Hi,

This line: https://github.com/pyg-team/pytorch_geometric/blob/master/torch_geometric/nn/conv/gatv2_conv.py#L230

Is there any way to add self-loops only when the graph has a unique entity type? I do not want to add self-loops when the graph is bipartite. Something like:

        # Remove and add self-loops
        # The original code did not check if the graph is bipartite
        if type(x) == tuple:
            pass
        else:
            # print('self loops')
            edge_index, _ = remove_self_loops(edge_index)
            edge_index, _ = add_self_loops(edge_index, num_nodes=x.size(0))

Thanks.

Suggest a potential alternative/fix

No response

rusty1s commented 1 year ago

I think in this case you should just set add_self_loops to False. Even if the graph is bipartite, there exists scenarios were we still want to add self-loops (e.g., in a hierarchical neighbor sampling scenario). I prefer to keep this explicit.