[Solved] I get this error using PyTorch: RuntimeError: gather_out_cpu(): Expected dtype int64 for index

Iuli Iuli Asks: I get this error using PyTorch: RuntimeError: gather_out_cpu(): Expected dtype int64 for index
I’m trying to make an AI with PyTorch, but I get this error:

Code:
RuntimeError: gather_out_cpu(): Expected dtype int64 for index

And this is my function:

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()

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.