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

Gradients do not exist for variables when applying learnable adjacency matrix to the GATConv layer #395

Open
zzzy0828 opened this issue Sep 26, 2022 · 4 comments

Comments

@zzzy0828
Copy link

Hi!
Recently I bulid learnable adjacency matrices for modeling in which case connections between different sites vary at different time steps. (Each time step corresponds to a specific graph structure). I used several fully connected layers (Dense) to make the initial adjacency matrices learnable, where parameters can be updated through model training, namely gradient descent. However, when applying the learnable adjacency matrices to the GATConv layer, Tensorflow Warnings appear as follows:


WARNING:tensorflow:Gradients do not exist for variables ['dense_2/kernel:0', 'dense_4/kernel:0', 'dense_3/kernel:0', 'dense_5/kernel:0'] when minimizing the loss.
WARNING:tensorflow:Gradients do not exist for variables ['dense_2/kernel:0', 'dense_4/kernel:0', 'dense_3/kernel:0', 'dense_5/kernel:0'] when minimizing the loss.
WARNING:tensorflow:Gradients do not exist for variables ['dense_2/kernel:0', 'dense_4/kernel:0', 'dense_3/kernel:0', 'dense_5/kernel:0'] when minimizing the loss.
WARNING:tensorflow:Gradients do not exist for variables ['dense_2/kernel:0', 'dense_4/kernel:0', 'dense_3/kernel:0', 'dense_5/kernel:0'] when minimizing the loss.


If I use the GCNConv layer rather than the GATConv layer, Warnings above disappeared.
I guess that the adjacency matrices didn't truly take part in the process of graph attention. Is that true?
How can I handle this problem (avoid these warnings) when using a GATConv layer?
Expect for your reply, thank you very much!

@danielegrattarola
Copy link
Owner

GAT computes the adjacency matrix as a function of the node features so there might be something unexpected going on there.
The warnings seem to indicate that your learnable weights are not being used to compute the actual adjacency matrix.

Can you post a snippet to reproduce the issue?
Thanks

@zzzy0828
Copy link
Author

Snippet:


x = x_origin # (batch_size, time_step, n_site, features)
a_in = Dense(n_site, activation='relu', use_bias=False)(x) # (batch_size, time_step, n_site, n_site)
x_in_v = Lambda(x_reshape, output_shape=(n_site, features))(x_origin)
a_in_v = Lambda(a_reshape, output_shape=(n_site, n_site))(a_in)
output = GATConv(channels=64, attn_heads=5, add_self_loops=False, activation='relu',
concat_heads=False, return_attn_coef=False)([x_in_v, a_in_v])
...


Epoch 1/80
WARNING:tensorflow:Gradients do not exist for variables ['dense_2/kernel:0'] when minimizing the loss.
WARNING:tensorflow:Gradients do not exist for variables ['dense_2/kernel:0'] when minimizing the loss.
WARNING:tensorflow:Gradients do not exist for variables ['dense_2/kernel:0'] when minimizing the loss.
WARNING:tensorflow:Gradients do not exist for variables ['dense_2/kernel:0'] when minimizing the loss.

Thank you for your reply!
Best wishes.

@danielegrattarola
Copy link
Owner

Yeah unfortunately GAT is not designed to work like that, there is no way to backpropagate the error to the dense layer that's generating the adjacency matrix.
GCNConv is a better choice.

@zzzy0828
Copy link
Author

OK, I got it.
Thank you for your reply.
Thank you very much!
Best wishes.

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

2 participants