class_docstr: ## Feedback Transformer Layer
  
  This implements a single transformer layer in the feedback transformer.
class_docstr_tok: ["#","#","Feedback","Transformer","Layer","This","implements","a","single","transformer","layer","in","the","feedback","transformer","."]
code: def forward(
      self,
      *,
      x: torch.Tensor,
      key: Optional[torch.Tensor],
      value: Optional[torch.Tensor],
  ):
      # If there is memory
      if key is not None:
          # Normalize the vectors before doing self attention
          z = self.norm_self_attn(x)
          # Run through self attention, i.e. keys and values are from self
          self_attn = self.attn(query=z, key=key, value=value)
          # Add the self attention results
          x = x + self.dropout(self_attn)
  
      # Normalize for feed-forward
      z = self.norm_ff(x)
      # Pass through the feed-forward network
      ff = self.feed_forward(z)
      # Add the feed-forward results back
      x = x + self.dropout(ff)
  
      #
      return x
  
imports: import math
  from typing import Optional
  import torch
  from torch import nn
  from labml_helpers.module import Module
  from labml_nn.transformers.feed_forward import FeedForward
  from labml_nn.transformers.mha import PrepareForMultiHeadAttention
  from labml_nn.utils import clone_module_list
label_desc: Use image node_id 2 for calling the FeedbackTransformerLayer obj's underlying member method code with example usage: obj.forward() and returns: x