Attentive-Group-Recommendation icon indicating copy to clipboard operation
Attentive-Group-Recommendation copied to clipboard

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

Open novakchang opened this issue 5 years ago • 6 comments

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.

novakchang avatar Jun 17 '19 08:06 novakchang

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.

LianHaiMiao avatar Jun 17 '19 09:06 LianHaiMiao

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

novakchang avatar Jun 17 '19 09:06 novakchang

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.

LianHaiMiao avatar Jun 17 '19 13:06 LianHaiMiao

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]

novakchang avatar Jun 18 '19 08:06 novakchang

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)

LianHaiMiao avatar Jun 18 '19 09:06 LianHaiMiao

Thanks a lot. It worked!

novakchang avatar Jun 18 '19 09:06 novakchang