-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to use cuda data in state (for train network) #1
Comments
Could you check your computer can use cuda? |
Maybe |
Thank you g6ling. I checked torch.cuda.is_available() and I can see cuda using print. |
Did you change these parts? After you changed this codes and code is not working, plz write your error. |
I changed this line (removed .to(device) from original code) I still have this error when I run this line I think that It means that batch.state data is processed on GPU (because you defined state with cuda in the code) but torch.stack is processed on CPU |
https://pytorch.org/docs/stable/torch.html#torch.tensor
Could you plz check your default device type? If default is cpu, you set device to |
Dear g6ling, I already set Cuda and I used another PyTorch code with Cuda. I solved the problem. https://github.com/g6ling/Reinforcement-Learning-Pytorch-Cartpole/blob/master/rainbow/1-dqn/train.py#L69 ( next_state = torch.Tensor(next_state)) Then I have other errors when train_model is processed Because action, reward, masks are running on CPU and it is used to calculate for target, so I added Finally, I changed this line I think that your implementation is good and a lot of help for me, but some people can have a different setup, so it can help someone who wants to use Cuda using PyTorch. Thank you for your support. |
File "/home/jaeseok/Downloads/Reinforcement-Learning-Pytorch-Cartpole-master/rainbow/1-dqn/train.py", line 107, in
main()
File "/home/jaeseok/Downloads/Reinforcement-Learning-Pytorch-Cartpole-master/rainbow/1-dqn/train.py", line 89, in main
loss = QNet.train_model(online_net, target_net, optimizer, batch)
File "/home/jaeseok/Downloads/Reinforcement-Learning-Pytorch-Cartpole-master/rainbow/1-dqn/model.py", line 29, in train_model
states = torch.stack(batch.state)
RuntimeError: Expected object of backend CPU but got backend CUDA for sequence element 4 in sequence argument at position #1 'tensors'
Hello,
I have tested dqn in rainbow folder.
batch.state data is cuda data. I do not know how to change this line
states = torch.stack(batch.state)
I already did like,
states = torch.stack(batch.state).to(device)
states = torch.stack(batch.state).cuda()
It was not working. Do you have any suggestion
The text was updated successfully, but these errors were encountered: