Gather_out_cpu(): Expected dtype int64 for index

Hii i get this error and i don’ t really know how to solve it:gather_out_cpu(): Expected dtype int64 for index

and this is my code def learn(self, batch_state, batch_next_state, batch_reward, batch_action): outputs = self.model(batch_state).gather(1, batch_action.unsqueeze(1)).squeeze(1) next_outputs = self.model(batch_next_state).detach().max(1)[0] target = self.gamma * next_outputs + batch_reward td_loss = F.smooth_l1_loss(outputs, target) self.optimizer.zero_grad() td_loss.backward(retain_variables = True) self.optimizer.step()

What is the data type of your index tensor here? You might want to call .long() on it to change the datatype before passing it to gather. (e.g., if it is batch_action, you may want to use batch_action.long().

    batch_action = batch_action.type(torch.int64)

i had to add this line to make it work