code: def universal_transformer_encoder(
      encoder_input,
      encoder_self_attention_bias,
      hparams,
      name="encoder",
      nonpadding=None,
      save_weights_to=None,
      make_image_summary=True,
  ):
      """Universal Transformer encoder function.
  
      Prepares all the arguments and the inputs and passes it to a
      universal_transformer_layer to encode the encoder_input.
  
      Args:
        encoder_input: a Tensor
        encoder_self_attention_bias: bias Tensor for self-attention
           (see common_attention.attention_bias())
        hparams: hyperparameters for model
        name: a string
        nonpadding: optional Tensor with shape [batch_size, encoder_length]
          indicating what positions are not padding.  This must either be
          passed in, which we do for "packed" datasets, or inferred from
          encoder_self_attention_bias.  The knowledge about padding is used
          for pad_remover(efficiency) and to mask out padding in convoltutional
          layers.
        save_weights_to: an optional dictionary to capture attention weights
          for vizualization; the weights tensor will be appended there under
          a string key created from the variable scope (including name).
        make_image_summary: Whether to make an attention image summary.
  
      Returns:
        y: a Tensors as the output of the encoder
        extra_output: which can be used to pass extra information to the body
      """
  
      x = encoder_input
      attention_dropout_broadcast_dims = (
          common_layers.comma_separated_string_to_integer_list(
              getattr(hparams, "attention_dropout_broadcast_dims", "")
          )
      )
      with tf.variable_scope(name):
          if nonpadding is not None:
              padding = 1.0 - nonpadding
          else:
              padding = common_attention.attention_bias_to_padding(
                  encoder_self_attention_bias
              )
              nonpadding = 1.0 - padding
          pad_remover = None
          if (
              hparams.use_pad_remover
              and not common_layers.is_xla_compiled()
          ):
              pad_remover = expert_utils.PadRemover(padding)
  
          ffn_unit = functools.partial(
              transformer_encoder_ffn_unit,
              hparams=hparams,
              nonpadding_mask=nonpadding,
              pad_remover=pad_remover,
          )
  
          attention_unit = functools.partial(
              transformer_encoder_attention_unit,
              hparams=hparams,
              encoder_self_attention_bias=encoder_self_attention_bias,
              attention_dropout_broadcast_dims=attention_dropout_broadcast_dims,
              save_weights_to=save_weights_to,
              make_image_summary=make_image_summary,
          )
  
          x, extra_output = universal_transformer_layer(
              x,
              hparams,
              ffn_unit,
              attention_unit,
              pad_remover=pad_remover,
          )
  
          return (
              common_layers.layer_preprocess(x, hparams),
              extra_output,
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import copy
  import functools
  from six.moves import range
  from tensor2tensor.layers import common_attention
  from tensor2tensor.layers import common_layers
  from tensor2tensor.models import transformer
  from tensor2tensor.utils import contrib
  from tensor2tensor.utils import expert_utils
  import tensorflow.compat.v1
label_desc: Use image node_id 1 for calling a global function with example usage: universal_transformer_encoder(encoder_input, encoder__attention_bias, hparams, name, nonpadding, save_weights_to, make_image_summary) and returns: common_layers,  extra_output