dxyang / DQN_pytorch

Vanilla DQN, Double DQN, and Dueling DQN implemented in PyTorch
426 stars 93 forks source link

Runtime Error : Index tensor must have same dimensions as input tensor #2

Open Ashutosh-Adhikari opened 6 years ago

Ashutosh-Adhikari commented 6 years ago

Hi If i run the code for breakout, i am getting the following error.

Traceback (most recent call last): File "main.py", line 120, in main() File "main.py", line 117, in main atari_learn(env, task.env_id, num_timesteps=task.max_timesteps, double_dqn=double_dqn, dueling_dqn=dueling_dqn) File "main.py", line 72, in atari_learn dueling_dqn=dueling_dqn File "/home/ashutosh/repos/DQN_pytorch/learn.py", line 229, in dqn_learning q_s_a.backward(clipped_error.data.unsqueeze(1)) File "/usr/local/lib/python2.7/dist-packages/torch/autograd/variable.py", line 167, in backward torch.autograd.backward(self, gradient, retain_graph, create_graph, retain_variables) File "/usr/local/lib/python2.7/dist-packages/torch/autograd/init.py", line 99, in backward variables, grad_variables, retain_graph) RuntimeError: invalid argument 3: Index tensor must have same dimensions as input tensor at /pytorch/torch/lib/THC/generic/THCTensorScatterGather.cu:199

bgreenawald commented 6 years ago

I had the same problem and found out it was because I was using a newer version of Pytorch. Assuming you're having the same issue, you can either revert to Pytorch version 0.2.0, or you can change line 229 in "learn.py" from q_s_a.backward(clipped_error.data.unsqueeze(1)) to q_s_a.backward(clipped_error.data)