Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can I use 'edge_weight' in GAT? #810

Closed
xxp17457741 opened this issue Nov 20, 2019 · 11 comments
Closed

how can I use 'edge_weight' in GAT? #810

xxp17457741 opened this issue Nov 20, 2019 · 11 comments

Comments

@xxp17457741
Copy link

❓ Questions & Help

I have a graph that contains edge_weight, so I want to use it in GATConv. But I fail to do it because in gat_conv.py there is no edge_weight parameters. So how can I do what I want to do?

@rusty1s
Copy link
Member

rusty1s commented Nov 20, 2019

It might be best to implement your own GATConv where attention is not only computed based on node features, but also based on edge weights.

@xxp17457741
Copy link
Author

Ok, I will try!

@heartcored98
Copy link

@xxp17457741 Hi, we are facing same situation like you as we also need to consider egde weight within the GATConv layer. Have you ever implemented your own GATConv module and could share it? If so, I would very much appreciate!

@bluelancer
Copy link

+1 for this!

@dongkwan-kim
Copy link
Contributor

I recently wrote GATEdgeConv that uses edge_attr in computing attention coefficients for my own good. It generates attention weights from the concatenation of x_i, x_j, and edge_attr in a similar manner with the original GATConv. This layer can take edge_weight as an input by setting edge_dim to one.

https://github.com/dongkwan-kim/GATEdgeConv

@rusty1s
Copy link
Member

rusty1s commented Sep 3, 2021

Since this is a popular request, do you want to contribute your solution directly to PyG @dongkwan-kim?

@dongkwan-kim
Copy link
Contributor

@rusty1s I have not sent PR since I have not found the right reference for this layer. But if you think it is worth including this layer in PyG, I would happy to work on it.

One quick question. My current version inherits the GATConv, but I do not think this is the best choice for this layer. I am considering three options. What do you think?

  • GATEdgeConv(GATConv)
  • GATEdgeConv(MessagePassing)
  • Add edge_attr-related options to the current GATConv

@rusty1s
Copy link
Member

rusty1s commented Sep 3, 2021

I think adding an edge_attr argument to GATConv is the way to go.

@HelloWorldLTY
Copy link

Hi, I tried to include the edge_attr into the GATConv part, but I will receive this error:
image
Why do we need this lin_edge to help us achieve this target?Are there any tutorials to help us understand GAT with edge attributes? Thanks a lot.

@rusty1s
Copy link
Member

rusty1s commented Sep 13, 2022

The linear layer will project the edge features to the correct shape. If this error occurs for you, it likely means you forgot to set the edge_dim property in the GATConv constructor. We can make this more explicit in the code.

@FrancisOWO
Copy link

The linear layer will project the edge features to the correct shape. If this error occurs for you, it likely means you forgot to set the edge_dim property in the GATConv constructor. We can make this more explicit in the code.

Hi, I noticed that in the latest version (2.7.0) of the code, this assert statement has been removed from GATConv, but it remains in GATv2Conv, as shown in the figure below.

62352385dca7b7eda00cd2df569658d

However, removing the assert statement leads to an issue: if a user passes edge_attr without setting edge_dim, the current GATConv will ignore edge_attr without informing the user, leading them to mistakenly believe that edge_attr has been used in the convolution.

I was not aware of this issue while using GATConv either, until I encountered an AssertionError when using GATv2Conv. Therefore, I think it would be better to retain the assert statement, or alternatively, to raise an error with some explanatory message, such as: require edge_dim to be set in the constructor when edge_attr is used.

I checked the commit history and found that this issue was caused by Commit 025b1cb (GATConv: require edge_dim to be set).

Do you think it would be better to retain the assert statement or raise an error?
At the very least, GATConv and GATv2Conv should be consistent in this part of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants