code: def dedup_bert_encoder(
      input_bert_encoder: tfm.nlp.networks.BertEncoder,
  ):
      """Deduplicates the layer names in a BERT encoder."""
  
      def _dedup(layer, attr_name, new_name):
          sublayer = getattr(layer, attr_name)
          if sublayer is None:
              return
          else:
              sublayer_config = sublayer.get_config()
              sublayer_config["name"] = new_name
              setattr(
                  layer,
                  attr_name,
                  sublayer.from_config(sublayer_config),
              )
  
      for layer in input_bert_encoder.layers:
          # NOTE: the ordering of the renames is important for the ordering of the
          # variables in the computed gradients. This is why we use three `for-loop`
          # instead of one.
          if isinstance(layer, tfm.nlp.layers.TransformerEncoderBlock):
              # pylint: disable=protected-access
              for attr_name in [
                  "inner_dropout_layer",
                  "attention_dropout",
              ]:
                  _dedup(
                      layer,
                      "_" + attr_name,
                      layer.name + "/" + attr_name,
                  )
              # Some layers are nested within the main attention layer (if it exists).
              if layer._attention_layer is not None:
                  prefix = (
                      layer.name + "/" + layer._attention_layer.name
                  )
                  _dedup(
                      layer,
                      "_attention_layer",
                      prefix + "/attention_layer",
                  )
                  _dedup(
                      layer._attention_layer,
                      "_dropout_layer",
                      prefix + "/attention_inner_dropout_layer",
                  )
              for attr_name in [
                  "attention_layer_norm",
                  "intermediate_dense",
              ]:
                  _dedup(
                      layer,
                      "_" + attr_name,
                      layer.name + "/" + attr_name,
                  )
              # This is one of the few times that we cannot build from a config, due
              # to the presence of lambda functions.
              if layer._intermediate_activation_layer is not None:
                  policy = tf.keras.mixed_precision.global_policy()
                  if policy.name == "mixed_bfloat16":
                      policy = tf.float32
                  layer._intermediate_activation_layer = (
                      tf.keras.layers.Activation(
                          layer._inner_activation,
                          dtype=policy,
                          name=layer.name
                          + "/intermediate_activation_layer",
                      )
                  )
              for attr_name in [
                  "output_dense",
                  "output_dropout",
                  "output_layer_norm",
              ]:
                  _dedup(
                      layer,
                      "_" + attr_name,
                      layer.name + "/" + attr_name,
                  )
  
imports: import tensorflow
  import tensorflow_models
  from tensorflow_privacy.privacy.fast_gradient_clipping import gradient_clipping_utils
label_desc: Use image node_id 1 for calling a global function with example usage: dedup_bert_encoder(input_bert_encoder) without return types