I ran with device=cpu to debug the error, and the error is asserted at line 443:

  
      github.com
  
  
    edowson/alphapilot_openai_ros/blob/master/ardrone_race_track/src/ardrone_v1_ddqn.py#L440-L443

# Compute Q(s_t, a) - the model computes Q(s_t), then we select the
# columns of actions taken. These are the actions which would've been taken
# for each batch state according to policy_net
state_action_values = policy_net(state_batch).gather(1, action_batch)



  
  
    
    
  
  


  File "/project/ros-kinetic-alphapilot/catkin_ws/src/alphapilot_openai_ros/ardrone_race_track/src/ardrone_v1_ddqn.py", line 443, in optimize_model
    state_action_values = policy_net(state_batch).gather(1, action_batch)
RuntimeError: Invalid index in gather at /pytorch/aten/src/TH/generic/THTensorEvenMoreMath.cpp:457

@ptrblck would you happen to know how I can fix this?
The default cartpole example had 2 actions.
    else:
        return torch.tensor([[random.randrange(2)]], device=device, dtype=torch.long)

I noticed that it crashes, when I update it for my task environment, which has 7 actions.

  
      github.com
  
  
    edowson/alphapilot_openai_ros/blob/master/ardrone_race_track/src/ardrone_v1_ddqn.py#L379-L380

else:
    return torch.tensor([[random.randrange(N_ACTIONS)]], device=device, dtype=torch.long)



  
  
    
    
  
  


N_ACTIONS=7, in this case. If i set it to 2, there is no crash.
Why would this be an issue? I can’t seem to locate any other part of the code that hard-codes the total number of actions.