You could remove the inplace operations and replace them with their out of place equivalent, e.g.:
  output1 -= torch.mean(output1, 0)
  output2 -= torch.mean(output2, 0)

and check, if this would solve the issue.