RUCAIBox / RecBole

A unified, comprehensive and efficient recommendation library
https://recbole.io/
MIT License
3.48k stars 615 forks source link

IndexError: tensors used as indices must be long, byte or bool tensors #1283

Closed rezash121 closed 2 years ago

rezash121 commented 2 years ago

Hi, I have this problem. IndexError: tensors used as indices must be long, byte or bool tensors

However, I didn't understand what I should do to fix this problem after reading https://github.com/RUCAIBox/RecBole/issues/1012 and https://github.com/RUCAIBox/RecBole/issues/1041. I would appreciate it if you described how I could fix this problem. Thank you

zgmming commented 2 years ago

I met the same issue, try this: row_idx= row_idx.type(torch.long) col_idx = col_idx.type(torch.long)

hyp1231 commented 2 years ago

Hi, I have this problem. IndexError: tensors used as indices must be long, byte or bool tensors

However, I didn't understand what I should do to fix this problem after reading #1012 and #1041. I would appreciate it if you described how I could fix this problem. Thank you

Hi @rezash121 and @zgmming, thanks for your attention. Could you please post the model, dataset, and the running script when you met this issue? So that we can try to reproduce, thank you!

rezash121 commented 2 years ago

Thank you @zgmming for your help. Do you mean I should change the https://github.com/RUCAIBox/RecBole/blob/b7b29954fbc963a406ddbe2f917b4ba56bd7a22b/tests/data/test_dataloader.py ?

Thank you for help.

rezash121 commented 2 years ago

Hi, I have this problem. IndexError: tensors used as indices must be long, byte or bool tensors However, I didn't understand what I should do to fix this problem after reading #1012 and #1041. I would appreciate it if you described how I could fix this problem. Thank you

Hi @rezash121 and @zgmming, thanks for your attention. Could you please post the model, dataset, and the running script when you met this issue? So that we can try to reproduce, thank you!

Dear @hyp1231,

I use precisely the same code on #1041.

zgmming commented 2 years ago

Hi @hyp1231 , this issue occurs on windows os, it's ok on Linux. Model: bpr Dataset: ml-100k Pytorch: 1.11

Hi @rezash121, I changed trainer.py and collector.py where the Error reports.

hyp1231 commented 2 years ago

Hi @hyp1231 , this issue occurs on windows os, it's ok on Linux. Model: bpr Dataset: ml-100k Pytorch: 1.11

Hi @rezash121, I changed trainer.py and collector.py where the Error reports.

Thanks so much for the feedback! Could you please try @zgmming's solution to see whether it works for you @rezash121?

rezash121 commented 2 years ago

Dear @zgmming and @hyp1231 Thank you for your help. I did this in trainer.py

scores[row_idx.long(), col_idx.long()] = origin_scores

and this one in collector.py

pos_matrix[positive_u.long(), positive_i.long()] = 1

this worked for me.

hyp1231 commented 2 years ago

Glad to see that works for you @rezash121, sincerely thanks @zgmming for the amazing solution!