    def clip_gradient(self):
        """
        Performs gradient clipping.
        If the model is in mixed precision training, we would first unscale the gradient.
        """
        if self._grad_clipping is not None:
            # 1. We have to unscale the gradient before clipping
            if self._scaler is not None:
                optimizer_state = self._scaler._per_optimizer_states[id(self.optimizer)]
                # 2. The `unscale_` shouldn't be performed more than once per optimizer per step call,
                # so we only perform `unscale_` if it has not already been called.
                if optimizer_state["stage"] is not OptState.UNSCALED:
                    self._scaler.unscale_(self.optimizer)
            torch.nn.utils.clip_grad_value_(
                [p for p in self.model.parameters() if p.grad is not None], self._grad_clipping
            )
Performs gradient clipping.
If the model is in mixed precision training, we would first unscale the gradient.
allennlp/training/gradient_descent_trainer.py