Looks like your inplace operation is += here:
self.actor_loss += actor_loss_function(action.prediction_ships, action.tensor_action_ships)

+= is fine when mutated tensor was not captured before, but here I’d guess that custom_loss() captures its output