code: def decode_transformer(
      encoder_output,
      encoder_decoder_attention_bias,
      targets,
      hparams,
      name,
      task=None,
      causal=True,
  ):
      """Original Transformer decoder."""
      orig_hparams = hparams
      with tf.variable_scope(name):
          if task is None:
              task = hparams.task
          if task == "translate":
              targets = common_layers.flatten4d3d(targets)
  
              (
                  decoder_input,
                  decoder_self_bias,
              ) = transformer.transformer_prepare_decoder(
                  targets, hparams
              )
  
              decoder_input = tf.nn.dropout(
                  decoder_input,
                  1.0 - hparams.layer_prepostprocess_dropout,
              )
  
              if not causal:
                  decoder_self_bias *= 0.0
  
              decoder_output = transformer.transformer_decoder(
                  decoder_input,
                  encoder_output,
                  decoder_self_bias,
                  encoder_decoder_attention_bias,
                  hparams,
              )
              decoder_output = tf.expand_dims(decoder_output, axis=2)
          else:
              assert task == "image"
              inputs = None
              # have to reshape targets as b, 32, 32, 3 * hidden size] beacuse otherwise
              # prepare_image will choke
              targets = tf.reshape(
                  targets,
                  [
                      tf.shape(targets)[0],
                      hparams.img_len,
                      hparams.img_len,
                      hparams.num_channels * hparams.hidden_size,
                  ],
              )
  
              # Prepare decoder inputs and bias.
              # TODO(nikip): Make prepare_decoder return bias
              decoder_input, _, _ = cia.prepare_decoder(
                  targets, hparams
              )
              bias = None
  
              # Add class label to decoder input.
              if not hparams.drop_inputs:
                  decoder_input += tf.reshape(
                      inputs,
                      [
                          common_layers.shape_list(targets)[0],
                          1,
                          1,
                          hparams.hidden_size,
                      ],
                  )
              decoder_output = cia.transformer_decoder_layers(
                  decoder_input,
                  encoder_output=None,
                  num_layers=hparams.num_decoder_layers
                  or hparams.num_hidden_layers,
                  hparams=hparams,
                  self_attention_bias=bias,
                  attention_type=hparams.dec_attention_type,
                  name="decoder",
              )
          decoder_output_shape = common_layers.shape_list(
              decoder_output
          )
          decoder_output = tf.reshape(
              decoder_output,
              [decoder_output_shape[0], -1, 1, hparams.hidden_size],
          )
          # Expand since t2t expects 4d tensors.
          hparams = orig_hparams
          return decoder_output
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import functools
  import math
  import os
  from six.moves import range
  from tensor2tensor.layers import common_attention
  from tensor2tensor.layers import common_image_attention
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import discretization
  from tensor2tensor.layers import latent_layers
  from tensor2tensor.layers import modalities
  from tensor2tensor.models import transformer
  from tensor2tensor.utils import beam_search
  from tensor2tensor.utils import contrib
  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 8 for calling a global function with example usage: decode_transformer(encoder_output, encoder_decoder_attention_bias, targets, hparams, name, task, causal) and returns: decoder_output