If you put all of them, it will be long, so put only a part
loss=torch.sum(output.permute(1,2,0),dim=2)-torch.sum(targets.detach().permute(1,2,0),dim=2)
    
optimizer.zero_grad()
loss=loss__(loss)#(loss**2)/2
loss.backward()
torch.nn.utils.clip_grad_norm_(mainQN.parameters(),1,2)
optimizer.step()
scheduler.step()
self.tortal_losses+=loss.clone().detach().to('cpu')