RexYing / gnn-model-explainer

gnn explainer
Apache License 2.0
880 stars 175 forks source link

RuntimeError: Expected object of device type cuda but got device type cpu for argument #2 'mat2' in call to _th_mm #4

Open debinz opened 4 years ago

debinz commented 4 years ago

Hi

I am using your great code! I have slightly modified your models.py to fit my regression task, but when I run the train.py, error occurred:

Traceback (most recent call last): File "train.py", line 1273, in main() File "train.py", line 1250, in main benchmark_task(prog_args, writer=writer) File "train.py", line 1024, in benchmark_task writer=writer, File "train.py", line 190, in train ypred, att_adj = model(h0, adj, batch_num_nodes, assign_x=assign_input) #use the 'forward' that is in model class File "/home/omnisky/venv/lib/python3.7/site-packages/torch/nn/modules/module.py", line 541, in call result = self.forward(*input, *kwargs) File "/home/omnisky/Documents/individual_variance/gnn-model-explainer/models.py", line 570, in forward self.assign_pred_modulesi File "/home/omnisky/venv/lib/python3.7/site-packages/torch/nn/modules/module.py", line 541, in call result = self.forward(input, **kwargs) File "/home/omnisky/venv/lib/python3.7/site-packages/torch/nn/modules/linear.py", line 87, in forward return F.linear(input, self.weight, self.bias) File "/home/omnisky/venv/lib/python3.7/site-packages/torch/nn/functional.py", line 1372, in linear output = input.matmul(weight.t()) RuntimeError: Expected object of device type cuda but got device type cpu for argument #2 'mat2' in call to _th_mm

Can you give some advice about that? Thank you for your kind assistance!

Zeng

iamzhangyunlu commented 4 years ago

Hi, have you already solved the problem?

RexYing commented 4 years ago

Thanks for pointing out. Since the line number doesn't correspond, wonder if you the argument method is set to "base"? The default should be base.

I'll refactor out some unused code so that it doesn't accidentally call an unused model.

jiank2 commented 4 years ago

I have the same problem. Probably, the reason is that prog_args.gpu is set to False, not sure why it is False since const is True and action is 'store_const' (at least this is what happened on my PC). My solution is kind of like brute force by comment out all if-condition that involves prog_args.gpu/self.gpu, which enforces the program to send all data into GPU.

I wonder if the authors could provide some hint on how to fix the weird prog_args.gpu value assignment.