LianHaiMiao / Attentive-Group-Recommendation

Attentive Group Recommendation
131 stars 50 forks source link

should I use pytorch 0.3.0 in GPU or CPU version? Or pytorch 1.0.1 can work out? #2

Open novakchang opened 5 years ago

novakchang commented 5 years ago

I seem to have a problem with the code. The error is "TypeError: torch.index_select received an invalid combination of arguments - got (torch.FloatTensor, int, !torch.IntTensor!), but expected (torch.FloatTensor source, int dim, torch.LongTensor index)". I wonder if I get the pytorch version wrong. Now I'm using the pytorch 0.3.0 and python 3.5.4.

LianHaiMiao commented 5 years ago

I am sorry. It seems that you should use Pytorch 0.3.0 as framework. And the error you mentioned is that the pytorch version error, for some APIs, the input of version 1.0.1 is different from version 0.3.0.

novakchang commented 5 years ago

And now I use the Pytorch 0.3.0, but still I have this error when I run the main.py. image

LianHaiMiao commented 5 years ago

Please add this line in main.py to check what's your runing enviroment version of pytorch.

print(torch.__version__)

If you comfire your pytorch version is 0.3.0, you can post your error log in this issue, and I am glad to help you solve your problem.

novakchang commented 5 years ago

C:\Users\Khali\Anaconda2\envs\py3\envs\python35\python3_5.exe "D:/Python workspace/Attentive-Group-Recommendation-master/main.py" torch_version: 0.3.0b0+591e73e AGREE at embedding size 32, run Iteration:30, NDCG and HR at 5 Iteration 0, loss is [0.9978 ] Iteration 0, loss is [0.9808 ] Traceback (most recent call last): File "D:/Python workspace/Attentive-Group-Recommendation-master/main.py", line 112, in u_hr, u_ndcg = evaluation(agree, helper, dataset.user_testRatings, dataset.user_testNegatives, config.topK, 'user') File "D:/Python workspace/Attentive-Group-Recommendation-master/main.py", line 70, in evaluation (hits, ndcgs) = helper.evaluate_model(model, testRatings, testNegatives, K, type_m) File "D:\Python workspace\Attentive-Group-Recommendation-master\utils\util.py", line 41, in evaluate_model (hr,ndcg) = self.eval_one_rating(model, testRatings, testNegatives, K, type_m, idx) File "D:\Python workspace\Attentive-Group-Recommendation-master\utils\util.py", line 62, in eval_one_rating predictions = model(None, users_var, items_var) File "C:\Users\Khali\Anaconda2\envs\py3\envs\python35\lib\site-packages\torch\nn\modules\module.py", line 325, in call result = self.forward(*input, kwargs) File "D:\Python workspace\Attentive-Group-Recommendation-master\model\agree.py", line 37, in forward out = self.usr_forward(user_inputs, item_inputs) File "D:\Python workspace\Attentive-Group-Recommendation-master\model\agree.py", line 69, in usr_forward user_embeds = self.userembeds(user_inputs_var) File "C:\Users\Khali\Anaconda2\envs\py3\envs\python35\lib\site-packages\torch\nn\modules\module.py", line 325, in call result = self.forward(*input, *kwargs) File "D:\Python workspace\Attentive-Group-Recommendation-master\model\agree.py", line 82, in forward user_embeds = self.userEmbedding(user_inputs) File "C:\Users\Khali\Anaconda2\envs\py3\envs\python35\lib\site-packages\torch\nn\modules\module.py", line 325, in call result = self.forward(input, kwargs) File "C:\Users\Khali\Anaconda2\envs\py3\envs\python35\lib\site-packages\torch\nn\modules\sparse.py", line 103, in forward self.scale_grad_by_freq, self.sparse File "C:\Users\Khali\Anaconda2\envs\py3\envs\python35\lib\site-packages\torch\nn_functions\thnn\sparse.py", line 57, in forward output = torch.index_select(weight, 0, indices) TypeError: torch.index_select received an invalid combination of arguments - got (torch.FloatTensor, int, !torch.IntTensor!), but expected (torch.FloatTensor source, int dim, torch.LongTensor index) user and group training time is: [4967.9 s]

LianHaiMiao commented 5 years ago

I am sorry, the error happened when the numpy data transfer to tensor data. It is because our the type of tensor is IntTensor type, however, the model need LongTensor type.

you can try the code below.

# util.py       line 57
users_var = torch.from_numpy(users).type(torch.LongTensor)
novakchang commented 5 years ago

Thanks a lot. It worked!