docstr: Forward pass for streaming inference.
  
  B: batch size;
  D: feature dimension of each frame.
  
  Args:
      input (torch.Tensor): utterance frames right-padded with right context frames, with
          shape `(B, segment_length + right_context_length, D)`.
      lengths (torch.Tensor): with shape `(B,)` and i-th element representing
          number of valid frames for i-th batch element in ``input``.
      states (List[List[torch.Tensor]] or None, optional): list of lists of tensors
          representing internal state generated in preceding invocation of ``infer``. (Default: ``None``)
  
  Returns:
      (Tensor, Tensor, List[List[Tensor]]):
          Tensor
              output frames, with shape `(B, segment_length, D)`.
          Tensor
              output lengths, with shape `(B,)` and i-th element representing
              number of valid frames for i-th batch element in output frames.
          List[List[Tensor]]
              output states; list of lists of tensors representing internal state
              generated in current invocation of ``infer``.
docstr_tok: ["Forward","pass","for","streaming","inference",".","B",":","batch","size",";","D",":","feature","dimension","of","each","frame",".","Args",":","input","(","torch.Tensor",")",":","utterance","frames","right-padded","with","right","context","frames",",","with","shape","`","(","B",",","segment_length","+","right_context_length",",","D",")","`",".","lengths","(","torch.Tensor",")",":","with","shape","`","(","B",",",")","`","and","i-th","element","representing","number","of","valid","frames","for","i-th","batch","element","in","``","input","``",".","states","(","List","[","List","[","torch.Tensor","]","]","or","None",",","optional",")",":","list","of","lists","of","tensors","representing","internal","state","generated","in","preceding","invocation","of","``","infer","``",".","(","Default",":","``","None","``",")","Returns",":","(","Tensor",",","Tensor",",","List","[","List","[","Tensor","]","]",")",":","Tensor","output","frames",",","with","shape","`","(","B",",","segment_length",",","D",")","`",".","Tensor","output","lengths",",","with","shape","`","(","B",",",")","`","and","i-th","element","representing","number","of","valid","frames","for","i-th","batch","element","in","output","frames",".","List","[","List","[","Tensor","]","]","output","states",";","list","of","lists","of","tensors","representing","internal","state","generated","in","current","invocation","of","``","infer","``","."]
code: def infer(
      self,
      input: torch.Tensor,
      lengths: torch.Tensor,
      states: Optional[List[List[torch.Tensor]]] = None,
  ) -> Tuple[torch.Tensor, torch.Tensor, List[List[torch.Tensor]]]:
      r"""Forward pass for streaming inference.
  
      B: batch size;
      D: feature dimension of each frame.
  
      Args:
          input (torch.Tensor): utterance frames right-padded with right context frames, with
              shape `(B, segment_length + right_context_length, D)`.
          lengths (torch.Tensor): with shape `(B,)` and i-th element representing
              number of valid frames for i-th batch element in ``input``.
          states (List[List[torch.Tensor]] or None, optional): list of lists of tensors
              representing internal state generated in preceding invocation of ``infer``. (Default: ``None``)
  
      Returns:
          (Tensor, Tensor, List[List[Tensor]]):
              Tensor
                  output frames, with shape `(B, segment_length, D)`.
              Tensor
                  output lengths, with shape `(B,)` and i-th element representing
                  number of valid frames for i-th batch element in output frames.
              List[List[Tensor]]
                  output states; list of lists of tensors representing internal state
                  generated in current invocation of ``infer``.
      """
      if (
          input.size(1)
          != self.segment_length + self.right_context_length
      ):
          raise ValueError(
              "Per configured segment_length and right_context_length"
              f", expected size of {self.segment_length + self.right_context_length} for dimension 1 of input"
              f", but got {input.size(1)}."
          )
      input = input.permute(1, 0, 2)
      right_context_start_idx = (
          input.size(0) - self.right_context_length
      )
      right_context = input[right_context_start_idx:]
      utterance = input[:right_context_start_idx]
      output_lengths = torch.clamp(
          lengths - self.right_context_length, min=0
      )
      mems = (
          self.memory_op(utterance.permute(1, 2, 0)).permute(2, 0, 1)
          if self.use_mem
          else torch.empty(0).to(dtype=input.dtype, device=input.device)
      )
      output = utterance
      output_states: List[List[torch.Tensor]] = []
      for layer_idx, layer in enumerate(self.emformer_layers):
          output, right_context, output_state, mems = layer.infer(
              output,
              output_lengths,
              right_context,
              None if states is None else states[layer_idx],
              mems,
          )
          output_states.append(output_state)
  
      return output.permute(1, 0, 2), output_lengths, output_states
  
imports: import math
  from typing import List, Optional, Tuple
  import torch
label_desc: Use image node_id 6 for calling the _EmformerImpl obj's underlying member method code with example usage: obj.infer(input, lengths, states) and returns: output,  output_lengths,  output_states