oh man, it’s hard to tell what’s different.
I wanted to add some quick comments:
dqn.forward(next_state_input) # wrong
dqn(next_state_input)         # correct

It doesn’t affect things in your particular code sample though.
Also, have a look at our DQN training for any gotchas you might find: http://pytorch.org/tutorials/intermediate/reinforcement_q_learning.html#training-loop 24