class_docstr: Attention net.  See file docstring.
code: def body_sharded(self, sharded_features):
      # ========= Prepare the input and target =========
  
      hparams = self._hparams
      dp = self._data_parallelism
  
      # Process input
      inputs = sharded_features["inputs"]
      target_space = sharded_features["target_space_id"]
      (
          encoder_input,
          encoder_self_attention_bias,
          encoder_decoder_attention_bias,
      ) = dp(self._prepare_encoder, inputs, target_space)
  
      # Process output
      targets = sharded_features["targets"]
      decoder_input, decoder_self_attention_bias = dp(
          self._prepare_decoder, targets
      )
  
      def dp_preprocess(x):
          return dp(common_layers.layer_preprocess, x, hparams)
  
      def dp_postprocess(x, y):
          return dp(common_layers.layer_postprocess, x, y, hparams)
  
      cache = dict(extra_loss=0.0)
  
      def prepostprocess(fct):
          """Apply processing and capture the extra loss."""
  
          @expert_utils.add_var_scope()
          def decorated(x, *args, **kwargs):
              x_preprocessed = dp_preprocess(x)
              y, loss = fct(x_preprocessed, *args, **kwargs)
              cache["extra_loss"] += loss
              return dp_postprocess(x, y)
  
          return decorated
  
      # ========= Compute the transformer architecture =========
  
      encoder_layers, decoder_layers = self._extract_layer_types()
  
      layers = common_attention.get_standardized_layers(
          hparams=hparams,
          dp=dp,
      )
  
      if hparams.mode == tf_estimator.ModeKeys.TRAIN:
          # Display the encoder-decoder architecture
          def print_layer(name, layers):
              tf.logging.info("{} architecture:".format(name))
              for i, l in enumerate(layers):
                  tf.logging.info(
                      " * Layer {}: {}".format(i, " - ".join(l))
                  )
  
          print_layer("Encoder", encoder_layers)
          print_layer("Decoder", decoder_layers)
  
      # ========= Construct the transformer encoder and decoder =========
  
      encoder_outputs = []
  
      x = encoder_input
      with tf.variable_scope("encoder"):
          for layer_num, block_types in enumerate(encoder_layers):
              # Each encoder layers is composed of two blocks:
              # * self-attention block
              # * feed-forward block
              att_type, ff_type = block_types
              with tf.variable_scope("layer_{}".format(layer_num)):
                  x = prepostprocess(layers[att_type])(
                      x,
                      bias=encoder_self_attention_bias,
                      name="att_{}".format(att_type),
                  )
                  x = prepostprocess(layers[ff_type])(
                      x, name="ff_{}".format(ff_type)
                  )
              encoder_outputs.append(x)
          if encoder_outputs:
              encoder_outputs[-1] = dp_preprocess(x)
  
      x = decoder_input
      with tf.variable_scope("decoder"):
          for layer_num, block_types in enumerate(decoder_layers):
              # Each decoder layers is composed of three blocks:
              # * self-attention block
              # * enco-deco attention block (optional)
              # * feed-forward block
              self_att_type, att_ende_type, ff_type = block_types
              with tf.variable_scope("layer_{}".format(layer_num)):
                  x = prepostprocess(layers[self_att_type])(
                      x,
                      bias=decoder_self_attention_bias,
                      name="self_att_{}".format(self_att_type),
                  )
                  # Only add the enco-deco attention layer if there is an encoder
                  if encoder_outputs:
                      x = prepostprocess(layers[att_ende_type])(
                          x,
                          memory_antecedent=encoder_outputs[-1],
                          bias=encoder_decoder_attention_bias,
                          name="att_ende_{}".format(att_ende_type),
                      )
                  x = prepostprocess(layers[ff_type])(
                      x, name="ff_{}".format(ff_type)
                  )
          # If normalization is done in layer_preprocess, then it should also be
          # done on the output, since the output can grow very large, being the sum
          # of a whole stack of unnormalized layer outputs.
          x = dp_preprocess(x)
  
      decoder_output = dp(tf.expand_dims, x, 2)
      return decoder_output, cache["extra_loss"]
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from tensor2tensor.layers import common_attention
  from tensor2tensor.layers import common_hparams
  from tensor2tensor.layers import common_layers
  from tensor2tensor.models import transformer
  from tensor2tensor.utils import expert_utils
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 2 for calling the TransformerMoe obj's underlying member method code with example usage: obj.body_sharded(sharded_features) and returns: decoder_output,  cache, dp, dp, decorated, dp_postprocess