code: def decoder_block(
      layer_input,
      encoder_output,
      attention_head_size,
      batch_size,
      seq_length,
      encoder_length,
      cross_attention_mask=None,
      hidden_size=768,
      num_attention_heads=12,
      intermediate_size=3072,
      intermediate_act_fn=gelu,
      hidden_dropout_prob=0.1,
      attention_probs_dropout_prob=0,
      initializer_range=0.02,
      drop_self_attention=False,
  ):
      """
      Taken from base_models.bert.modeling.full_block()
      Applies cross attention in addition to the blocks normal operations
      """
  
      def _attention(from_tensor, to_tensor, mask, from_len, to_len):
          with tf.compat.v1.variable_scope("attention"):
              attention_output = attention_layer(
                  from_tensor=from_tensor,
                  to_tensor=to_tensor,
                  attention_mask=mask,
                  num_attention_heads=num_attention_heads,
                  size_per_head=attention_head_size,
                  attention_probs_dropout_prob=attention_probs_dropout_prob,
                  initializer_range=initializer_range,
                  do_return_2d_tensor=True,
                  batch_size=batch_size,
                  from_seq_length=from_len,
                  to_seq_length=to_len,
              )
          with tf.compat.v1.variable_scope("output"):
              attention_output = tf.compat.v1.layers.dense(
                  attention_output,
                  hidden_size,
                  kernel_initializer=create_initializer(
                      initializer_range
                  ),
              )
              attention_output = dropout(
                  attention_output, hidden_dropout_prob
              )
              attention_output = layer_norm(
                  attention_output + layer_input
              )
          return attention_output
  
      if drop_self_attention:
          attention_output = layer_input
      else:
          with tf.compat.v1.variable_scope("self-attention"):
              attention_output = _attention(
                  layer_input, layer_input, None, seq_length, seq_length
              )
      with tf.compat.v1.variable_scope("cross-attention"):
          attention_output = _attention(
              attention_output,
              encoder_output,
              cross_attention_mask,
              seq_length,
              encoder_length,
          )
  
      # The activation is only applied to the "intermediate" hidden layer.
      with tf.compat.v1.variable_scope("intermediate"):
          intermediate_output = tf.compat.v1.layers.dense(
              attention_output,
              intermediate_size,
              activation=intermediate_act_fn,
              kernel_initializer=create_initializer(initializer_range),
          )
  
      # Down-project back to `hidden_size` then add the residual.
      with tf.compat.v1.variable_scope("output"):
          layer_output = tf.compat.v1.layers.dense(
              intermediate_output,
              hidden_size,
              kernel_initializer=create_initializer(initializer_range),
          )
          layer_output = dropout(layer_output, hidden_dropout_prob)
          layer_output = layer_norm(layer_output + attention_output)
      return layer_output
  
imports: import math
  import functools
  import tensorflow
  from tensorflow_addons.text.crf import crf_log_likelihood
  from scipy.optimize import linear_sum_assignment
  from finetune.base_models.gpt.featurizer import attn, dropout, norm
  from finetune.util.shapes import shape_list, merge_leading_dims
  from finetune.optimizers.recompute_grads import recompute_grad
  from finetune.errors import FinetuneError
  from finetune.nn.activations import act_fns
  from finetune.nn.nn_utils import norm
  from finetune.nn.target_blocks import sequence_labeler
  from tensorflow.python.framework import function
  from finetune.nn.target_blocks import class_reweighted_grad
  from finetune.base_models.bert.modeling import attention_layer, dropout, create_initializer, layer_norm, gelu
label_desc: Use image node_id 6 for calling a global function with example usage: decoder_block(layer_input, encoder_output, attention_head_size, batch_size, seq_length, encoder_length, cross_attention_mask, hidden_size, num_attention_heads, intermediate_size, intermediate_act_fn, hidden_dropout_prob, attention_probs_dropout_prob, initializer_range, drop__attention) and returns: layer_output, attention_output