Input for GCNConv layer (torch.sparse coo vs edge index and edge attr tensors) #8588
Replies: 3 comments 10 replies
-
Note that for non-symmetric sparse tensors, you need to input the transposed adjacency matrix: x_out = conv1(x, ori_edge_index, edge_weight)
tensor_adjacency = to_torch_coo_tensor(data.edge_index, edge_weight)
x_out2 = conv1(x, tensor_adjacency.t())
print(torch.allclose(x_out, x_out2, atol=1e-4)) works for me. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hello @EdisonLeeeee, Could I ask if there are any considerations otherwise? Because when I tried it on my dataset, I still face a problem where they are not similar: Unfortunately, I cannot share the dataset due to data privacy considerations. Perhaps if there's any advice what should we look out for to make sure the the values are similar? Thank you so much! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am slightly confused by the behaviour of GCNConv.
When I used the input as a torch.sparse_coo tensor vs having the edge_index and edge_attr placed as separate inputs, I get a different outcome from the gcnconv operation. Debugging it made me conclude that it was primarily due to the coalesce function, which has been applied to the torch.sparse_coo tensor but not for the scenario where I used edge_index and edge_attr as inputs. In particular, this happened during the add_self_loops_fn for the torch_sparse_coo_tensor, under to_torch_coo_tensor.
I was trying to debug this as I was training a GCN model where the performance decreases when I used inputs as edge_index and edge_attr, instead of using as a sparse tensor.
For a reproducible scenario, please refer to the collab link here (under Differences in output):
https://colab.research.google.com/drive/144kSk-OfSwZHChfnSHbpmB-iV_4ssCZY?usp=sharing
This is based on the example here: https://pytorch-geometric.readthedocs.io/en/latest/get_started/introduction.html
Would really appreciate if someone can enlighten me on the following
Beta Was this translation helpful? Give feedback.
All reactions