def _compute_gradients(self, loss, var_list, grad_loss=None, tape=None):
    'DP version of superclass method.'
    self._was_dp_gradients_called = True
    if ((not callable(loss)) and (tape is None)):
        raise ValueError('`tape` is required when a `Tensor` loss is passed.')
    tape = (tape if (tape is not None) else tf.GradientTape())
    if callable(loss):
        with tape:
            if (not callable(var_list)):
                tape.watch(var_list)
            if callable(loss):
                loss = loss()
                microbatch_losses = tf.reduce_mean(tf.reshape(loss, [self._num_microbatches, (- 1)]), axis=1)
            if callable(var_list):
                var_list = var_list()
    else:
        with tape:
            microbatch_losses = tf.reduce_mean(tf.reshape(loss, [self._num_microbatches, (- 1)]), axis=1)
    var_list = tf.nest.flatten(var_list)
    with tf.keras.backend.name_scope((self._name + '/gradients')):
        jacobian = tape.jacobian(microbatch_losses, var_list)
        if self._changing_clipping:
            if False:
                self._norm_clip.assign_add(0.002)
                tf.print('cur C:', self._norm_clip.value(), output_stream=sys.stdout)
            else:
                gr_norm = jacobian.copy()
                for i in range(len(gr_norm)):
                    gr_norm[i] = tf.norm(gr_norm[i])
                gr_mean = tf.math.reduce_mean(gr_norm)
                self._norm_clip.assign(gr_mean)
                C = self._norm_clip.value()
                tf.print('cur C:', C, output_stream=sys.stdout)

        def clip_gradients(g):
            return tf.clip_by_global_norm(g, self._norm_clip.value())[0]
        clipped_gradients = tf.map_fn(clip_gradients, jacobian)

        def reduce_noise_normalize_batch(g):
            summed_gradient = tf.reduce_sum(g, axis=0)
            noise_stddev = (self._l2_norm_clip * self._noise_multiplier)
            noise = tf.random.normal(tf.shape(input=summed_gradient), stddev=noise_stddev)
            noised_gradient = tf.add(summed_gradient, noise)
            return tf.truediv(noised_gradient, self._num_microbatches)
        final_gradients = tf.nest.map_structure(reduce_noise_normalize_batch, clipped_gradients)
    return list(zip(final_gradients, var_list))
DP version of superclass method.
def _compute_gradients(self, loss, var_list, grad_loss=None, tape=None):
    
    self._was_dp_gradients_called = True
    if ((not callable(loss)) and (tape is None)):
        raise ValueError('`tape` is required when a `Tensor` loss is passed.')
    tape = (tape if (tape is not None) else tf.GradientTape())
    if callable(loss):
        with tape:
            if (not callable(var_list)):
                tape.watch(var_list)
            if callable(loss):
                loss = loss()
                microbatch_losses = tf.reduce_mean(tf.reshape(loss, [self._num_microbatches, (- 1)]), axis=1)
            if callable(var_list):
                var_list = var_list()
    else:
        with tape:
            microbatch_losses = tf.reduce_mean(tf.reshape(loss, [self._num_microbatches, (- 1)]), axis=1)
    var_list = tf.nest.flatten(var_list)
    with tf.keras.backend.name_scope((self._name + '/gradients')):
        jacobian = tape.jacobian(microbatch_losses, var_list)
        if self._changing_clipping:
            if False:
                self._norm_clip.assign_add(0.002)
                tf.print('cur C:', self._norm_clip.value(), output_stream=sys.stdout)
            else:
                gr_norm = jacobian.copy()
                for i in range(len(gr_norm)):
                    gr_norm[i] = tf.norm(gr_norm[i])
                gr_mean = tf.math.reduce_mean(gr_norm)
                self._norm_clip.assign(gr_mean)
                C = self._norm_clip.value()
                tf.print('cur C:', C, output_stream=sys.stdout)

        def clip_gradients(g):
            return tf.clip_by_global_norm(g, self._norm_clip.value())[0]
        clipped_gradients = tf.map_fn(clip_gradients, jacobian)

        def reduce_noise_normalize_batch(g):
            summed_gradient = tf.reduce_sum(g, axis=0)
            noise_stddev = (self._l2_norm_clip * self._noise_multiplier)
            noise = tf.random.normal(tf.shape(input=summed_gradient), stddev=noise_stddev)
            noised_gradient = tf.add(summed_gradient, noise)
            return tf.truediv(noised_gradient, self._num_microbatches)
        final_gradients = tf.nest.map_structure(reduce_noise_normalize_batch, clipped_gradients)
    return list(zip(final_gradients, var_list))