class_docstr: Emformer layer attention module.
  
  Args:
      input_dim (int): input dimension.
      num_heads (int): number of attention heads in each Emformer layer.
      dropout (float, optional): dropout probability. (Default: 0.0)
      weight_init_gain (float or None, optional): scale factor to apply when initializing
          attention module parameters. (Default: ``None``)
      tanh_on_mem (bool, optional): if ``True``, applies tanh to memory elements. (Default: ``False``)
      negative_inf (float, optional): value to use for negative infinity in attention weights. (Default: -1e8)
class_docstr_tok: ["Emformer","layer","attention","module",".","Args",":","input_dim","(","int",")",":","input","dimension",".","num_heads","(","int",")",":","number","of","attention","heads","in","each","Emformer","layer",".","dropout","(","float",",","optional",")",":","dropout","probability",".","(","Default",":","0.0",")","weight_init_gain","(","float","or","None",",","optional",")",":","scale","factor","to","apply","when","initializing","attention","module","parameters",".","(","Default",":","``","None","``",")","tanh_on_mem","(","bool",",","optional",")",":","if","``","True","``",",","applies","tanh","to","memory","elements",".","(","Default",":","``","False","``",")","negative_inf","(","float",",","optional",")",":","value","to","use","for","negative","infinity","in","attention","weights",".","(","Default",":","-1e8",")"]
docstr: Forward pass for inference.
  
  B: batch size;
  D: feature dimension of each frame;
  T: number of utterance frames;
  R: number of right context frames;
  S: number of summary elements;
  M: number of memory elements.
  
  Args:
      utterance (torch.Tensor): utterance frames, with shape `(T, B, D)`.
      lengths (torch.Tensor): with shape `(B,)` and i-th element representing
          number of valid frames for i-th batch element in ``utterance``.
      right_context (torch.Tensor): right context frames, with shape `(R, B, D)`.
      summary (torch.Tensor): summary elements, with shape `(S, B, D)`.
      mems (torch.Tensor): memory elements, with shape `(M, B, D)`.
      left_context_key (torch.Tensor): left context attention key computed from preceding invocation.
      left_context_val (torch.Tensor): left context attention value computed from preceding invocation.
  
  Returns:
      (Tensor, Tensor, Tensor, and Tensor):
          Tensor
              output frames corresponding to utterance and right_context, with shape `(T + R, B, D)`.
          Tensor
              updated memory elements, with shape `(M, B, D)`.
          Tensor
              attention key computed for left context and utterance.
          Tensor
              attention value computed for left context and utterance.
docstr_tok: ["Forward","pass","for","inference",".","B",":","batch","size",";","D",":","feature","dimension","of","each","frame",";","T",":","number","of","utterance","frames",";","R",":","number","of","right","context","frames",";","S",":","number","of","summary","elements",";","M",":","number","of","memory","elements",".","Args",":","utterance","(","torch.Tensor",")",":","utterance","frames",",","with","shape","`","(","T",",","B",",","D",")","`",".","lengths","(","torch.Tensor",")",":","with","shape","`","(","B",",",")","`","and","i-th","element","representing","number","of","valid","frames","for","i-th","batch","element","in","``","utterance","``",".","right_context","(","torch.Tensor",")",":","right","context","frames",",","with","shape","`","(","R",",","B",",","D",")","`",".","summary","(","torch.Tensor",")",":","summary","elements",",","with","shape","`","(","S",",","B",",","D",")","`",".","mems","(","torch.Tensor",")",":","memory","elements",",","with","shape","`","(","M",",","B",",","D",")","`",".","left_context_key","(","torch.Tensor",")",":","left","context","attention","key","computed","from","preceding","invocation",".","left_context_val","(","torch.Tensor",")",":","left","context","attention","value","computed","from","preceding","invocation",".","Returns",":","(","Tensor",",","Tensor",",","Tensor",",","and","Tensor",")",":","Tensor","output","frames","corresponding","to","utterance","and","right_context",",","with","shape","`","(","T","+","R",",","B",",","D",")","`",".","Tensor","updated","memory","elements",",","with","shape","`","(","M",",","B",",","D",")","`",".","Tensor","attention","key","computed","for","left","context","and","utterance",".","Tensor","attention","value","computed","for","left","context","and","utterance","."]
code: def infer(
      self,
      utterance: torch.Tensor,
      lengths: torch.Tensor,
      right_context: torch.Tensor,
      summary: torch.Tensor,
      mems: torch.Tensor,
      left_context_key: torch.Tensor,
      left_context_val: torch.Tensor,
  ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
      r"""Forward pass for inference.
  
      B: batch size;
      D: feature dimension of each frame;
      T: number of utterance frames;
      R: number of right context frames;
      S: number of summary elements;
      M: number of memory elements.
  
      Args:
          utterance (torch.Tensor): utterance frames, with shape `(T, B, D)`.
          lengths (torch.Tensor): with shape `(B,)` and i-th element representing
              number of valid frames for i-th batch element in ``utterance``.
          right_context (torch.Tensor): right context frames, with shape `(R, B, D)`.
          summary (torch.Tensor): summary elements, with shape `(S, B, D)`.
          mems (torch.Tensor): memory elements, with shape `(M, B, D)`.
          left_context_key (torch.Tensor): left context attention key computed from preceding invocation.
          left_context_val (torch.Tensor): left context attention value computed from preceding invocation.
  
      Returns:
          (Tensor, Tensor, Tensor, and Tensor):
              Tensor
                  output frames corresponding to utterance and right_context, with shape `(T + R, B, D)`.
              Tensor
                  updated memory elements, with shape `(M, B, D)`.
              Tensor
                  attention key computed for left context and utterance.
              Tensor
                  attention value computed for left context and utterance.
      """
      query_dim = (
          right_context.size(0) + utterance.size(0) + summary.size(0)
      )
      key_dim = (
          right_context.size(0)
          + utterance.size(0)
          + mems.size(0)
          + left_context_key.size(0)
      )
      attention_mask = torch.zeros(query_dim, key_dim).to(
          dtype=torch.bool, device=utterance.device
      )
      attention_mask[-1, : mems.size(0)] = True
      output, output_mems, key, value = self._forward_impl(
          utterance,
          lengths,
          right_context,
          summary,
          mems,
          attention_mask,
          left_context_key=left_context_key,
          left_context_val=left_context_val,
      )
      return (
          output,
          output_mems,
          key[mems.size(0) + right_context.size(0) :],
          value[mems.size(0) + right_context.size(0) :],
      )
  
imports: import math
  from typing import List, Optional, Tuple
  import torch
label_desc: Use image node_id 6 for calling the _EmformerAttention obj's underlying member method code with example usage: obj.infer(utterance, lengths, right_context, summary, mems, left_context_key, left_context_val) and returns: output,  output_mems,  key,  value