Expected tensor for argument #1 'indices' to have scalar type Long; but got torch.IntTensor instead (while checking arguments for embedding)
Closed this issue · 2 comments
Getting this error while running sample on windows 10, torch 1.7.1
Traceback (most recent call last):
File "main.py", line 116, in
main()
File "main.py", line 74, in main
logging.info('Test Before Training: ' + runner.print_res(model, data_dict['test']))
File "xxx\ReChorus-master\src\helpers\BaseRunner.py", line 221, in print_res
result_dict = self.evaluate(model, data, self.topk, self.metrics)
File "xxx\ReChorus-master\src\helpers\BaseRunner.py", line 197, in evaluate
predictions = self.predict(model, data)
File "xxx\ReChorus-master\src\helpers\BaseRunner.py", line 212, in predict
prediction = model(utils.batch_to_gpu(batch, model.device))['prediction']
File "xxx\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "xxx\ReChorus-master\src\models\general\BPR.py", line 30, in forward
cf_u_vectors = self.u_embeddings(u_ids)
File "xxx\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "xxx\lib\site-packages\torch\nn\modules\sparse.py", line 126, in forward
self.norm_type, self.scale_grad_by_freq, self.sparse)
File "xxx\lib\site-packages\torch\nn\functional.py", line 1852, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got torch.IntTensor instead (while checking arguments for embedding)
Maybe it's the problem caused by PyTorch version (mine is 1.0). The direct solution is converting uid
and iid
to LongTensor in the beginning of the forward function:
u_ids = feed_dict['user_id'].long()
i_ids = feed_dict['item_id'].long()
Thanks a lot for your quick reply! this works