docstr: Forward pass for training and non-streaming inference.
  
  B: batch size;
  T: max number of input frames in batch;
  D: feature dimension of each frame.
  
  Args:
      input (torch.Tensor): utterance frames right-padded with right context frames, with
          shape `(B, T + right_context_length, D)`.
      lengths (torch.Tensor): with shape `(B,)` and i-th element representing
          number of valid utterance frames for i-th batch element in ``input``.
  
  Returns:
      (Tensor, Tensor):
          Tensor
              output frames, with shape `(B, T, D)`.
          Tensor
              output lengths, with shape `(B,)` and i-th element representing
              number of valid frames for i-th batch element in output frames.
docstr_tok: ["Forward","pass","for","training","and","non-streaming","inference",".","B",":","batch","size",";","T",":","max","number","of","input","frames","in","batch",";","D",":","feature","dimension","of","each","frame",".","Args",":","input","(","torch.Tensor",")",":","utterance","frames","right-padded","with","right","context","frames",",","with","shape","`","(","B",",","T","+","right_context_length",",","D",")","`",".","lengths","(","torch.Tensor",")",":","with","shape","`","(","B",",",")","`","and","i-th","element","representing","number","of","valid","utterance","frames","for","i-th","batch","element","in","``","input","``",".","Returns",":","(","Tensor",",","Tensor",")",":","Tensor","output","frames",",","with","shape","`","(","B",",","T",",","D",")","`",".","Tensor","output","lengths",",","with","shape","`","(","B",",",")","`","and","i-th","element","representing","number","of","valid","frames","for","i-th","batch","element","in","output","frames","."]
code: def forward(
      self, input: torch.Tensor, lengths: torch.Tensor
  ) -> Tuple[torch.Tensor, torch.Tensor]:
      r"""Forward pass for training and non-streaming inference.
  
      B: batch size;
      T: max number of input frames in batch;
      D: feature dimension of each frame.
  
      Args:
          input (torch.Tensor): utterance frames right-padded with right context frames, with
              shape `(B, T + right_context_length, D)`.
          lengths (torch.Tensor): with shape `(B,)` and i-th element representing
              number of valid utterance frames for i-th batch element in ``input``.
  
      Returns:
          (Tensor, Tensor):
              Tensor
                  output frames, with shape `(B, T, D)`.
              Tensor
                  output lengths, with shape `(B,)` and i-th element representing
                  number of valid frames for i-th batch element in output frames.
      """
      input = input.permute(1, 0, 2)
      right_context = self._gen_right_context(input)
      utterance = input[: input.size(0) - self.right_context_length]
      attention_mask = self._gen_attention_mask(utterance)
      mems = (
          self.memory_op(utterance.permute(1, 2, 0)).permute(2, 0, 1)[
              :-1
          ]
          if self.use_mem
          else torch.empty(0).to(dtype=input.dtype, device=input.device)
      )
      output = utterance
      for layer in self.emformer_layers:
          output, right_context, mems = layer(
              output, lengths, right_context, mems, attention_mask
          )
      return output.permute(1, 0, 2), lengths
  
imports: import math
  from typing import List, Optional, Tuple
  import torch
label_desc: Use image node_id 5 for calling the _EmformerImpl obj's underlying member method code with example usage: obj.forward(input, lengths) and returns: output,  lengths