class_docstr: Sequential self-attention layer.
  Each token will attend to its previous fixed number of steps.
  Note that attention doesn't include the current step itself.
class_docstr_tok: ["Sequential","self-attention","layer",".","Each","token","will","attend","to","its","previous","fixed","number","of","steps",".","Note","that","attention","does","n't","include","the","current","step","itself","."]
code: def forward(self, query, key, value, key_pe):
      # query size = B x M x H
      # key, value sizes = B x (M+L) x H
  
      key, value, key_pe = self.adaptive_span.trim_memory(
          query, key, value, key_pe
      )
  
      # compute attention from context
      # B x M (dest) x (M+L) (src)
      attn_cont = torch.matmul(query, key.transpose(-1, -2))
      attn_cont = _unskew(attn_cont)  # B x M x L
  
      # compute the effect of position embedding
      attn_pos = torch.matmul(query, key_pe)  # B x M x L_pos
      attn = attn_cont + attn_pos
  
      attn = attn / math.sqrt(self.d_model)  # B x M X L_pos
  
      attn = F.softmax(attn.float(), dim=-1).type_as(attn)
  
      # trim attention lengths according to the learned span
      attn = self.adaptive_span(attn)
  
      attn = self.dropout(attn)  # B x M X L_pos
  
      attn_cont = _skew(attn, 0)  # B x M X (L+M)
      out = torch.matmul(attn_cont, value)  # B x M x H
      return out
  
imports: import math
  import torch
  import torch.nn
  import torch.nn.functional
  from fairseq.modules.layer_norm import LayerNorm
  from .adaptive_span_attention import AdaptiveSpan
label_desc: Use image node_id 2 for calling the SeqAttention obj's underlying member method code with example usage: obj.forward(query, key, value, key_pe) and returns: out