PaccMann / paccmann_rl

Code pipeline for the PaccMann^RL in iScience: https://www.cell.com/iscience/fulltext/S2589-0042(21)00237-6
MIT License
31 stars 9 forks source link

RuntimeError: Expected object of device type cuda but got device type cpu for argument #1 'self' in call to _th_index_select #3

Closed cook-kuk closed 4 years ago

cook-kuk commented 4 years ago

Thanks for fixing the previous issue. I tried again but the error comes back.

All steps were done according to the steps in the tutorial.

I checked that the cuda is well assigned to the model, but I got the following error:

Error message :

Traceback (most recent call last):
  File "C:/Users/seungho.kuk/Desktop/Python_project/paccmann_rl/code/paccmann_generator/examples/train_paccmann_rl.py", line 316, in <module>
    main()
  File "C:/Users/seungho.kuk/Desktop/Python_project/paccmann_rl/code/paccmann_generator/examples/train_paccmann_rl.py", line 222, in main
    cell_line, epoch, params['batch_size']
  File "C:\Users\seungho.kuk\Desktop\Python_project\paccmann_rl\code\paccmann_generator\paccmann_generator\reinforce.py", line 400, in policy_gradient
    latent_z, remove_invalid=True
  File "C:\Users\seungho.kuk\Desktop\Python_project\paccmann_rl\code\paccmann_generator\paccmann_generator\reinforce.py", line 315, in get_smiles_from_latent
    temperature=self.temperature
  File "C:\Users\seungho.kuk\Desktop\Python_project\paccmann_rl\code\paccmann_chemistry\paccmann_chemistry\models.py", line 382, in generate
    temperature=temperature
  File "C:\Users\seungho.kuk\Desktop\Python_project\paccmann_rl\code\paccmann_chemistry\paccmann_chemistry\models.py", line 209, in generate_from_latent
    output, hidden, stack = self(input_token, hidden, stack)
  File "C:\Users\seungho.kuk\anaconda3\envs\paccmann_rl\lib\site-packages\torch\nn\modules\module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "C:\Users\seungho.kuk\Desktop\Python_project\paccmann_rl\code\paccmann_chemistry\paccmann_chemistry\stack_rnn.py", line 106, in forward
    embedded_input = self.encoder(input_token.to(self.device))
  File "C:\Users\seungho.kuk\anaconda3\envs\paccmann_rl\lib\site-packages\torch\nn\modules\module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "C:\Users\seungho.kuk\anaconda3\envs\paccmann_rl\lib\site-packages\torch\nn\modules\sparse.py", line 114, in forward
    self.norm_type, self.scale_grad_by_freq, self.sparse)
  File "C:\Users\seungho.kuk\anaconda3\envs\paccmann_rl\lib\site-packages\torch\nn\functional.py", line 1724, in embedding
    return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
RuntimeError: Expected object of device type cuda but got device type cpu for argument #1 'self' in call to _th_index_select

Process finished with exit code 1
jannisborn commented 4 years ago

This is a GPU related issue. It seems like you're running the code locally but one of the modules in paccmann_chemistry expects a GPU tensor. This is something you have to solve locally on your machine, it's difficult to debug from far away.

cook-kuk commented 4 years ago

I solved this by assigning specific GPUs to the models. (to. ("cuda")-> to ("cuda: 0"))