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

Error when running the link prediction experiment #12

Open
raftelo opened this issue Nov 2, 2021 · 9 comments
Open

Error when running the link prediction experiment #12

raftelo opened this issue Nov 2, 2021 · 9 comments

Comments

@raftelo
Copy link

raftelo commented Nov 2, 2021

I was able to run the node classification on all datasets, unfortunately the link prediction experiment always throws an exception, I've tried changing the configurations but no luck, below is the error:

...
WARNING - root - Added new config entry: "training.use_cuda"
WARNING - R-GCN Link Prediction  - No observers have been added to this run
INFO - R-GCN Link Prediction  - Running command 'train'
INFO - R-GCN Link Prediction  - Started
ERROR - R-GCN Link Prediction  - Failed after 0:00:00!
Traceback (most recent calls WITHOUT Sacred internals):
  File "experiments/predict_links.py", line 88, in train
    decoder_config=decoder
  File "/home/raftel/torch-rgcn/torch_rgcn/models.py", line 224, in __init__
    .__init__(nnodes, nrel, nfeat, encoder_config, decoder_config)
  File "/home/raftel/torch-rgcn/torch_rgcn/models.py", line 58, in __init__
    init(self.node_embeddings)
TypeError: schlichtkrull_normal_() missing 1 required positional argument: 'shape'
@huluwaaaa
Copy link

Hello, I also encountered this problem, can I ask if you found a solution?

@JuliaGast
Copy link

Hello,

I also encountered this problem.

It seems like there is a bug with both, schlichtkrull_normal_, and schlichtkrull_uniform_ in utils.misc

def schlichtkrull_normal_(tensor, shape, gain=1.):
    """Fill the input `Tensor` with values according to the Schlichtkrull method, using a normal distribution."""
    std = schlichtkrull_std(shape, gain)
    with torch.no_grad():
        return tensor.normal_(0.0, std)

def schlichtkrull_uniform_(tensor, gain=1.):
    """Fill the input `Tensor` with values according to the Schlichtkrull method, using a uniform distribution."""
    std = schlichtkrull_std(tensor, gain)
    with torch.no_grad():
        return tensor.uniform_(-std, std)

because in torch_rgcn.models. my line 55, 56 you do not pass the 'shape' value

        init = select_w_init(encoder_w_init)
        init(self.node_embeddings) #here, shape is missing

I think, in addition, there is something wrong with schlichtkrull_uniform - this passes the tensor to schlichtkrull_std, which also is wrong in my opinion (should be shape instead, no?)

Workaround:

I am able to get rid of that error when changing, in the respective yaml file, the weight_init for encoder from schlichtkrull-normal to xavier-normal:
(e.g., line 30 in conf.yaml)
weight_init: xavier-normal # schlichtkrull-normal

This means of course that a different function is used for initialising biases, however, it at least gets rid of the error, so maybe this helps you for now @huluwaaaa :)

@thiviyanT
Copy link
Owner

thiviyanT commented Mar 17, 2022

Thanks @JuliaGast for this. I will look into this. It's strange that I didn't encounter the problem. Which version of PyTorch were you using?

@JuliaGast
Copy link

Hi @thiviyanT thanks for your reply and for looking into this!
I'm using pytorch 1.11.0.

I assume it has nothing to do with pytorch though, because I get the error message about the missing argument:

schlichtkrull_normal_() missing 1 required positional argument: 'shape'

which actually makes sense, when looking at the fact that only one argument is given here:
init(self.node_embeddings) #here, shape is missing

:)
Best
Julia

@OIGrass
Copy link

OIGrass commented Mar 21, 2022

I also encounter this problem. The classification part of mine goes well. And I have create the environment the same as the environment.yml except the scared=0.8.2 because of the loss of 0.8.1 in all my channels, but I think it doesn't matter.
In my opinion, I think the shape argument of the initial function is the shape of the tensor which need to be initialized. But either I try my way , or use the method Julia mention, the program still doesn't work.

the error log as follow:

INFO - R-GCN Link Prediction - Running command 'train'
INFO - R-GCN Link Prediction - Started
nodes padded to 280 to make it divisible by 5.0 (added 0 null nodes).
Start training...
min tensor(-5.51041, device='cuda:0', grad_fn=)
max tensor(4.98508, device='cuda:0', grad_fn=)
mean tensor(0.21224, device='cuda:0', grad_fn=)
std tensor(1.49450, device='cuda:0', grad_fn=)
size torch.Size([3300])
ERROR - R-GCN Link Prediction - Failed after 0:00:03!

@OIGrass
Copy link

OIGrass commented Apr 16, 2022

Hello, it's me again. This time ,I solve the error I met. I found that the LinkPredictor.Forward of the file "models.py" has a strange line. line 134 exists a exit(),this make my code didn't work. Why this line exists?

@OIGrass
Copy link

OIGrass commented Apr 16, 2022

@thiviyanT

@JuliaGast
Copy link

Hello @OIGrass
Does link prediction run for you now, even when using the
default weight_init:
weight_init: schlichtkrull-normal

Or did you modify it to something like:

weight_init: xavier-normal

(in conf.yaml)?

@benearnthof
Copy link

Hello @thiviyanT @OIGrass @JuliaGast The link prediction runs after changing the config to use normal initialization like @OIGrass suggested and after removing the exit() statement from line 132 of models.py

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

6 participants