docstr: Parameters
  ----------
  data
      The input data.
  
      - layout = 'NT'
          Shape (batch_size, query_length, units)
      - layout = 'TN'
          Shape (query_length, batch_size, units)
  
  mem
      The memory.
  
      - layout = 'NT'
          Shape (batch_size, mem_length, units)
      - layout = 'TN'
          Shape (mem_length, batch_size, units)
  
  rel_positions
      The relative positions between data and concat(mem, data).
      Shape is (query_length, mem_length + query_length).
      A positive value means that query is after the memory, i.e.,
      query_location - mem_location.
  mask
      Mask between the query and the memory + query.
      1--> will be used, 0 --> won't be used
      Shape (batch_size, query_length, mem_length + query_length)
  query_r_bias
      The query bias for calculating the relative scores
      Shape (num_heads, query_head_units)
  query_k_bias
      The key bias for calculating the relative scores.
      Shape (num_heads, query_head_units)
  
  Returns
  -------
  out
      - layout = 'NT'
          Shape (batch_size, query_length, units)
      - layout = 'TN'
          Shape (query_length, batch_size, units)
docstr_tok: ["Parameters","--","--","--","--","--","data","The","input","data",".","-","layout","=","'NT'","Shape","(","batch_size",",","query_length",",","units",")","-","layout","=","'TN'","Shape","(","query_length",",","batch_size",",","units",")","mem","The","memory",".","-","layout","=","'NT'","Shape","(","batch_size",",","mem_length",",","units",")","-","layout","=","'TN'","Shape","(","mem_length",",","batch_size",",","units",")","rel_positions","The","relative","positions","between","data","and","concat","(","mem",",","data",")",".","Shape","is","(","query_length",",","mem_length","+","query_length",")",".","A","positive","value","means","that","query","is","after","the","memory",",","i.e.",",","query_location","-","mem_location",".","mask","Mask","between","the","query","and","the","memory","+","query",".","1","--",">","will","be","used",",","0","--",">","wo","n't","be","used","Shape","(","batch_size",",","query_length",",","mem_length","+","query_length",")","query_r_bias","The","query","bias","for","calculating","the","relative","scores","Shape","(","num_heads",",","query_head_units",")","query_k_bias","The","key","bias","for","calculating","the","relative","scores",".","Shape","(","num_heads",",","query_head_units",")","Returns","--","--","--","-","out","-","layout","=","'NT'","Shape","(","batch_size",",","query_length",",","units",")","-","layout","=","'TN'","Shape","(","query_length",",","batch_size",",","units",")"]
code: def forward(
      self, data, mem, rel_positions, mask, query_r_bias, query_k_bias
  ):
      """
  
      Parameters
      ----------
      data
          The input data.
  
          - layout = 'NT'
              Shape (batch_size, query_length, units)
          - layout = 'TN'
              Shape (query_length, batch_size, units)
  
      mem
          The memory.
  
          - layout = 'NT'
              Shape (batch_size, mem_length, units)
          - layout = 'TN'
              Shape (mem_length, batch_size, units)
  
      rel_positions
          The relative positions between data and concat(mem, data).
          Shape is (query_length, mem_length + query_length).
          A positive value means that query is after the memory, i.e.,
          query_location - mem_location.
      mask
          Mask between the query and the memory + query.
          1--> will be used, 0 --> won't be used
          Shape (batch_size, query_length, mem_length + query_length)
      query_r_bias
          The query bias for calculating the relative scores
          Shape (num_heads, query_head_units)
      query_k_bias
          The key bias for calculating the relative scores.
          Shape (num_heads, query_head_units)
  
      Returns
      -------
      out
          - layout = 'NT'
              Shape (batch_size, query_length, units)
          - layout = 'TN'
              Shape (query_length, batch_size, units)
  
      """
      if self._layout == "NT":
          context = np.concatenate([mem, data], axis=1)
      elif self._layout == "TN":
          context = np.concatenate([mem, data], axis=0)
      else:
          raise NotImplementedError
      if self._pre_norm:
          query = self.attn_query(self.layer_norm(data))
          key_value = self.attn_kv(self.layer_norm(context))
          key, value = np.split(key_value, 2, axis=-1)
      else:
          query = self.attn_query(data)
          key_value = self.attn_kv(context)
          key, value = np.split(key_value, 2, axis=-1)
      query = npx.reshape(query, (-2, -2, self._num_heads, -1))
      key = npx.reshape(key, (-2, -2, self._num_heads, -1))
      value = npx.reshape(value, (-2, -2, self._num_heads, -1))
      # Compute attention
      rel_score = self.rel_pos_score_cell(
          rel_positions, query + query_r_bias
      )
      out, _ = self.attn_cell(
          query + query_k_bias, key, value, mask, rel_score
      )
      out = self.dropout_layer(out)
      if self._pre_norm:
          out = data + out
      else:
          out = self.layer_norm(data + out)
      out = self.ffn(out)
      return out
  
imports: import numpy
  import mxnet
  from mxnet import use_np, np, npx
  from mxnet.gluon import nn, Block, HybridBlock, Parameter
  from ..attention_cell import multi_head_dot_attn, gen_self_attn_mask, gen_mem_attn_mask, RelAttentionScoreCell, MultiHeadAttentionCell
  from ..layers import get_activation, PositionalEmbedding, PositionwiseFFN, AdaptiveEmbedding, ProjectedAdaptiveLogSoftmaxWithLoss
  from ..utils.config import CfgNode
  from ..sequence_sampler import BaseStepDecoder
label_desc: Use image node_id 3 for calling the TransformerXLDecoderLayer obj's underlying member method code with example usage: obj.forward(data, mem, rel_positions, mask, query_r_bias, query_k_bias) and returns: out