docstr: Parameters
  ----------
  data
      - layout = 'NT'
          Shape (batch_size, seq_length, C_in)
      - layout = 'TN'
          Shape (seq_length, batch_size, C_in)
  
  mem
      - layout = 'NT'
          Shape (batch_size, mem_length, C_mem)
      - layout = 'TN'
          Shape (mem_length, batch_size, C_mem)
  
  self_causal_mask
      Shape (batch_size, seq_length, seq_length)
      Mask for the causal self-attention.
      self_causal_mask[i, j, :] masks the elements that token `j` attends to.
      To understand the self-causal attention mask, we can look at the following example:
  
      .. code-block:: none
  
                     ['I', 'can', 'now', 'use', 'numpy', 'in', 'Gluon@@', 'NLP']
          'I':         1,    0,     0,     0,      0,     0,      0,      0
          'can':       1,    1,     0,     0,      0,     0,      0,      0
          'now':       1,    1,     1,     0,      0,     0,      0,      0
          'use':       1,    1,     1,     1,      0,     0,      0,      0
          'numpy':     1,    1,     1,     1,      1,     0,      0,      0
          'in':        1,    1,     1,     1,      1,     1,      0,      0
          'Gluon@@':   1,    1,     1,     1,      1,     1,      1,      0
          'NLP':       1,    1,     1,     1,      1,     1,      1,      1
  
  mem_attn_mask :
      Shape (batch_size, seq_length, mem_length)
      Mask between the decoding input and the memory.
  
      .. code-block:: none
  
                     ['numpy', 'in', 'Gluon@@', 'NLP']
          'I':         1,     1,      1,      1
          'can':       1,     1,      1,      1
          'now':       1,     1,      1,      1
          'use':       1,     1,      1,      1
  
  Returns
  -------
  out
      - layout = 'NT'
          Shape (batch_size, seq_length, C_out)
      - layout = 'TN'
          Shape (seq_length, batch_size, C_out)
docstr_tok: ["Parameters","--","--","--","--","--","data","-","layout","=","'NT'","Shape","(","batch_size",",","seq_length",",","C_in",")","-","layout","=","'TN'","Shape","(","seq_length",",","batch_size",",","C_in",")","mem","-","layout","=","'NT'","Shape","(","batch_size",",","mem_length",",","C_mem",")","-","layout","=","'TN'","Shape","(","mem_length",",","batch_size",",","C_mem",")","self_causal_mask","Shape","(","batch_size",",","seq_length",",","seq_length",")","Mask","for","the","causal","self-attention",".","self_causal_mask","[","i",",","j",",",":","]","masks","the","elements","that","token","`","j","`","attends","to",".","To","understand","the","self-causal","attention","mask",",","we","can","look","at","the","following","example",":","..","code-block",":",":","none","[","'","I","'",",","'can","'",",","'now","'",",","'use","'",",","'numpy","'",",","'in","'",",","'Gluon","@","@","'",",","'NLP","'","]","'","I","'",":","1",",","0",",","0",",","0",",","0",",","0",",","0",",","0","'can","'",":","1",",","1",",","0",",","0",",","0",",","0",",","0",",","0","'now","'",":","1",",","1",",","1",",","0",",","0",",","0",",","0",",","0","'use","'",":","1",",","1",",","1",",","1",",","0",",","0",",","0",",","0","'numpy","'",":","1",",","1",",","1",",","1",",","1",",","0",",","0",",","0","'in","'",":","1",",","1",",","1",",","1",",","1",",","1",",","0",",","0","'Gluon","@","@","'",":","1",",","1",",","1",",","1",",","1",",","1",",","1",",","0","'NLP","'",":","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1","mem_attn_mask",":","Shape","(","batch_size",",","seq_length",",","mem_length",")","Mask","between","the","decoding","input","and","the","memory",".","..","code-block",":",":","none","[","'numpy","'",",","'in","'",",","'Gluon","@","@","'",",","'NLP","'","]","'","I","'",":","1",",","1",",","1",",","1","'can","'",":","1",",","1",",","1",",","1","'now","'",":","1",",","1",",","1",",","1","'use","'",":","1",",","1",",","1",",","1","Returns","--","--","--","-","out","-","layout","=","'NT'","Shape","(","batch_size",",","seq_length",",","C_out",")","-","layout","=","'TN'","Shape","(","seq_length",",","batch_size",",","C_out",")"]
code: def forward(self, data, mem, self_causal_mask, mem_attn_mask):
      """
  
      Parameters
      ----------
      data
          - layout = 'NT'
              Shape (batch_size, seq_length, C_in)
          - layout = 'TN'
              Shape (seq_length, batch_size, C_in)
  
      mem
          - layout = 'NT'
              Shape (batch_size, mem_length, C_mem)
          - layout = 'TN'
              Shape (mem_length, batch_size, C_mem)
  
      self_causal_mask
          Shape (batch_size, seq_length, seq_length)
          Mask for the causal self-attention.
          self_causal_mask[i, j, :] masks the elements that token `j` attends to.
          To understand the self-causal attention mask, we can look at the following example:
  
          .. code-block:: none
  
                         ['I', 'can', 'now', 'use', 'numpy', 'in', 'Gluon@@', 'NLP']
              'I':         1,    0,     0,     0,      0,     0,      0,      0
              'can':       1,    1,     0,     0,      0,     0,      0,      0
              'now':       1,    1,     1,     0,      0,     0,      0,      0
              'use':       1,    1,     1,     1,      0,     0,      0,      0
              'numpy':     1,    1,     1,     1,      1,     0,      0,      0
              'in':        1,    1,     1,     1,      1,     1,      0,      0
              'Gluon@@':   1,    1,     1,     1,      1,     1,      1,      0
              'NLP':       1,    1,     1,     1,      1,     1,      1,      1
  
      mem_attn_mask :
          Shape (batch_size, seq_length, mem_length)
          Mask between the decoding input and the memory.
  
          .. code-block:: none
  
                         ['numpy', 'in', 'Gluon@@', 'NLP']
              'I':         1,     1,      1,      1
              'can':       1,     1,      1,      1
              'now':       1,     1,      1,      1
              'use':       1,     1,      1,      1
  
      Returns
      -------
      out
          - layout = 'NT'
              Shape (batch_size, seq_length, C_out)
          - layout = 'TN'
              Shape (seq_length, batch_size, C_out)
      """
      # 1. Get the causal self-attention value
      if self._pre_norm:
          data = self.ln_in(data)
      self_query, self_key, self_value = np.split(
          self.attn_in_qkv(data), 3, axis=-1
      )
      out, [_, self_attn_weight] = self.self_attention(
          npx.reshape(self_query, (-2, -2, self._num_heads, -1)),
          npx.reshape(self_key, (-2, -2, self._num_heads, -1)),
          npx.reshape(self_value, (-2, -2, self._num_heads, -1)),
          self_causal_mask,
      )
      out = self.proj_in(out)
      out = self.dropout_layer(out)
      out = out + data
      if not self._pre_norm:
          out = self.ln_in(out)
      # 2. Attend to the contextual memory
      data = out
      if self._pre_norm:
          data = self.ln_inter(data)
      out, [_, context_attn_weight] = self.inter_attention(
          npx.reshape(
              self.attn_inter_q(data), (-2, -2, self._num_heads, -1)
          ),
          npx.reshape(
              self.attn_inter_k(mem), (-2, -2, self._num_heads, -1)
          ),
          npx.reshape(
              self.attn_inter_v(mem), (-2, -2, self._num_heads, -1)
          ),
          mem_attn_mask,
      )
      out = self.proj_inter(out)
      out = self.dropout_layer(out)
      out = out + data
      if not self._pre_norm:
          out = self.ln_inter(out)
      # 3. Encode the output via an FFN layer
      out = self.ffn(out)
      return out
  
imports: import numpy
  import mxnet
  from mxnet import np, npx
  from mxnet import use_np
  from mxnet.gluon import nn, HybridBlock
  from typing import Optional, Tuple, List
  from ..utils.registry import Registry
  from ..attention_cell import MultiHeadAttentionCell, gen_self_attn_mask, gen_mem_attn_mask
  from ..layers import PositionalEmbedding, PositionwiseFFN, InitializerType
  from ..utils.config import CfgNode
  from ..sequence_sampler import BaseStepDecoder
label_desc: Use image node_id 3 for calling the TransformerDecoderLayer obj's underlying member method code with example usage: obj.forward(data, mem, _causal_mask, mem_attn_mask) and returns: out