import tensorflow as tf

        self.grads_and_vars = self._optimizer.compute_gradients(total_loss)

        # clip gradients
        clipped_grads_and_vars = self._clip_gradients(self.grads_and_vars, self._grad_clipping_tuple)

        # compute norms in case they need to be logged
        self.gradient_norms = [tf.norm(g) + NUMTOL for (g, v) in clipped_grads_and_vars]
        self.weight_norms = [tf.norm(v) + NUMTOL for (g, v) in clipped_grads_and_vars]
        # check that gradients are finite
        grads = [tf.check_numerics(g, "grads is not finite") for (g, v) in clipped_grads_and_vars]
        variables = [tf.check_numerics(v, "grads is not finite") for (g, v) in clipped_grads_and_vars]
        self.gradient_weight_global_norms = [tf.global_norm(grads), tf.global_norm(variables)]

        # 2nd part of minimize: apply_gradient
        optimizer_step = self._optimizer.apply_gradients(clipped_grads_and_vars, global_step=self.global_step)

        update_ops = tf.group(*self.update_ops)
        self.training_op = tf.group(update_ops, optimizer_step)


    def set_check_ops(self):
        self._check_ops = 1
