code: def test_shared_gradients_are_equal(self):
      (
          true_encoder,
          sample_inputs,
      ) = get_small_bert_encoder_and_sample_inputs()
      unwrapped_encoder = bert_encoder_utils.get_unwrapped_bert_encoder(
          true_encoder
      )
      # Create a loss multiplier to avoid small gradients.
      dummy_labels = None
      with tf.GradientTape(persistent=True) as tape:
          true_outputs = true_encoder(sample_inputs)
          true_sqr_sum = tf.reduce_sum(
              custom_reduced_loss(dummy_labels, true_outputs)
          )
          computed_outputs = unwrapped_encoder(sample_inputs)
          computed_sqr_sum = tf.reduce_sum(
              custom_reduced_loss(dummy_labels, computed_outputs)
          )
      # The official BERT encoder may initialize trainable variables that are
      # not used in a model forward pass. Hence, they are invisible when we
      # try to unwrapping layers using our utility function.
      true_vars, computed_vars = get_shared_trainable_variables(
          true_encoder, unwrapped_encoder
      )
      true_grads = tape.gradient(true_sqr_sum, true_vars)
      computed_grads = tape.gradient(computed_sqr_sum, computed_vars)
      self.assertEqual(len(true_grads), len(computed_grads))
      for g1, g2 in zip(true_grads, computed_grads):
          self.assertEqual(type(g1), type(g2))
          if isinstance(g1, tf.IndexedSlices):
              self.assertAllClose(g1.values, g2.values)
              self.assertAllEqual(g2.indices, g2.indices)
          else:
              self.assertAllClose(g1, g2)
  
file_path: privacy/tensorflow_privacy/privacy/fast_gradient_clipping/bert_encoder_utils_test.py
imports: from absl.testing import parameterized
  import numpy
  import tensorflow
  import tensorflow_models
  from tensorflow_privacy.privacy.fast_gradient_clipping import bert_encoder_utils
label_desc: Use image node_id 3 for calling the BertEncoderUtilsTest obj's underlying member method code with example usage: obj.test_shared_gradients_are_equal() without return types