d-ailin/GDN

bug

Closed this issue · 8 comments

i tried to run the code for a long time, but the code always throw the bug ,can u tell me how to fix it?

alpha = softmax(alpha, edge_index_i,size_i)
RuntimeError: softmax() Expected a value of type 'Optional[Tensor]' for argument 'ptr' but instead found type 'int'.
Position: 2
Value: 864
Declaration: softmax(Tensor src, Tensor? index=None, Tensor? ptr=None, int? num_nodes=None, int dim=0) -> (Tensor)
Cast error details: Unable to cast Python instance to C++ type (compile in debug mode for details)

Hi, would you mind sharing a more detailed(or complete) traceback log? Thanks.

Thank you for your open code. I have the same problem with m3ditatioin.

Traceback (most recent call last):
File "D:/迅雷下载/GDN/GDN/main.py", line 259, in
main.run()
File "D:/迅雷下载/GDN/GDN/main.py", line 109, in run
self.train_log = train(self.model, model_save_path,
File "D:\迅雷下载\GDN\GDN\train.py", line 69, in train
out = model(x, edge_index).float().to(device)
File "C:\Users\Administrator.conda\envs\torch-geo\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl
result = self.forward(input, **kwargs)
File "D:\迅雷下载\GDN\GDN\models\GDN.py", line 163, in forward
gcn_out = self.gnn_layers[i](x, batch_gated_edge_index, node_num=node_numbatch_num, embedding=all_embeddings)
File "C:\Users\Administrator.conda\envs\torch-geo\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "D:\迅雷下载\GDN\GDN\models\GDN.py", line 73, in forward
out, (new_edge_index, att_weight) = self.gnn(x, edge_index, embedding, return_attention_weights=True)
File "C:\Users\Administrator.conda\envs\torch-geo\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "D:\迅雷下载\GDN\GDN\models\graph_layer.py", line 66, in forward
out = self.propagate(edge_index, x=x, embedding=embedding, edges=edge_index,
File "C:\Users\Administrator.conda\envs\torch-geo\lib\site-packages\torch_geometric\nn\conv\message_passing.py", line 237, in propagate
out = self.message(**msg_kwargs)
File "D:\迅雷下载\GDN\GDN\models\graph_layer.py", line 112, in message
alpha = softmax(alpha, edge_index_i, size_i)
RuntimeError: softmax() Expected a value of type 'Optional[Tensor]' for argument 'ptr' but instead found type 'int'.
Position: 2
Value: 3456
Declaration: softmax(Tensor src, Tensor? index, Tensor? ptr=None, int? num_nodes=None) -> (Tensor)
Cast error details: Unable to cast Python instance to C++ type (compile in debug mode for details)

Process finished with exit code 1

Hi, thanks for providing the log.

I think this issue is caused by the mismatched pytorch-geometric version. Our code is using version 1.5.0. Pytorch-geometric has changed the softmax function since 1.6.0.

Please try to reinstall the pytorch-geometric with 1.5.0 and rerun it. Thanks!

Can you update the code to adapt with new latest version of geometric?

@d-ailin @wjj5881005 modified

in graph_layer.py

self.node_dim=0
alpha = softmax(alpha, edge_index_i, num_nodes=size_i)

@iDestro Hello! Do you have solved this problem?

@d-ailin @wjj5881005 modified

in graph_layer.py

self.node_dim=0
alpha = softmax(alpha, edge_index_i, num_nodes=size_i)

Thanks for your help.
But I encounter a strange problem: If I omit the code self.node_dim=0, it will report a wrong issue on return x_j * alpha.view(-1, self.heads, 1); If I add this code, it works. Why is this line of code so important?

very good!