class_docstr: The encoder for ASR model of Conformer.
  Based on this paper:
  'Conformer: Convolution-augmented Transformer for Speech Recognition' by Anmol Gulati et al.
  https://arxiv.org/abs/2005.08100
  
  Args:
      feat_in (int): the size of feature channels
      n_layers (int): number of layers of ConformerBlock
      d_model (int): the hidden size of the model
      feat_out (int): the size of the output features
          Defaults to -1 (means feat_out is d_model)
      subsampling (str): the method of subsampling, choices=['vggnet', 'striding', 'dw-striding', 'stacking', 'stacking_norm']
          Defaults to striding.
      subsampling_factor (int): the subsampling factor which should be power of 2
          Defaults to 4.
      subsampling_conv_chunking_factor(int): optionally, force chunk inputs (helpful for large inputs)
          Should be power of 2, 1 (auto-chunking, default), or -1 (no chunking)
      subsampling_conv_channels (int): the size of the convolutions in the subsampling module
          Defaults to -1 which would set it to d_model.
      reduction (str, Optional): the method of reduction, choices=['pooling', 'striding']. If no value
          is passed, then no reduction is performed and the models runs with the original 4x subsampling.
      reduction_position (int, Optional): the index of the layer to apply reduction. If -1, apply reduction
          at the end.
      reduction_factor (int): the reduction factor which should be either 1 or a power of 2
          Defaults to 1.
      ff_expansion_factor (int): the expansion factor in feed forward layers
          Defaults to 4.
      self_attention_model (str): type of the attention layer and positional encoding
          'rel_pos': relative positional embedding and Transformer-XL
          'rel_pos_local_attn': relative positional embedding and Transformer-XL with local attention using
              overlapping chunks. Attention context is determined by att_context_size parameter.
          'abs_pos': absolute positional embedding and Transformer
          Default is rel_pos.
      pos_emb_max_len (int): the maximum length of positional embeddings
          Defaults to 5000
      n_heads (int): number of heads in multi-headed attention layers
          Defaults to 4.
      att_context_size (List[Union[List[int],int]]): specifies the context sizes on each side. Each context size should be a list of two integers like [100,100].
          A list of context sizes like [[100,100],[100,50]] can also be passed. -1 means unlimited context.
          Defaults to [-1,-1]
      att_context_probs (List[float]): a list of probabilities of each one of the att_context_size when a list of them is passed. If not specified, uniform distribution is being used.
          Defaults to None
      att_context_style (str): 'regular' or 'chunked_limited'.
          Defaults to 'regular'
      xscaling (bool): enables scaling the inputs to the multi-headed attention layers by sqrt(d_model)
          Defaults to True.
      untie_biases (bool): whether to not share (untie) the bias weights between layers of Transformer-XL
          Defaults to True.
      conv_kernel_size (int): the size of the convolutions in the convolutional modules
          Defaults to 31.
      conv_norm_type (str): the type of the normalization in the convolutional modules
          Defaults to 'batch_norm'.
      conv_context_size (list): it can be"causal" or a list of two integers while conv_context_size[0]+conv_context_size[1]+1==conv_kernel_size.
          None means [(conv_kernel_size-1)//2, (conv_kernel_size-1)//2], and 'causal' means [(conv_kernel_size-1), 0].
          Defaults to None.
      conv_dual_mode (bool): specifies if convolution should be dual mode when dual_offline mode is being used. When enables, the left half of the convolution kernel would get masked in streaming cases.
          Defaults to False
      dropout (float): the dropout rate used in all layers except the attention layers
          Defaults to 0.1.
      dropout_pre_encoder (float): the dropout rate used before the encoder
          Defaults to 0.1.
      dropout_emb (float): the dropout rate used for the positional embeddings
          Defaults to 0.1.
      dropout_att (float): the dropout rate used for the attention layer
          Defaults to 0.0.
      stochastic_depth_drop_prob (float): if non-zero, will randomly drop
          layers during training. The higher this value, the more often layers
          are dropped. Defaults to 0.0.
      stochastic_depth_mode (str): can be either "linear" or "uniform". If
          set to "uniform", all layers have the same probability of drop. If
          set to "linear", the drop probability grows linearly from 0 for the
          first layer to the desired value for the final layer. Defaults to
          "linear".
      stochastic_depth_start_layer (int): starting layer for stochastic depth.
          All layers before this will never be dropped. Note that drop
          probability will be adjusted accordingly if mode is "linear" when
          start layer is > 1. Defaults to 1.
      global_tokens (int): number of tokens to be used for global attention.
          Only relevant if self_attention_model is 'rel_pos_local_attn'.
          Defaults to 0.
      global_tokens_spacing (int): how far apart the global tokens are
          Defaults to 1.
      global_attn_separate (bool): whether the q, k, v layers used for global tokens should be separate.
          Defaults to False.
docstr: This function sets the needed values and parameters to perform streaming. The configuration would be stored in self.streaming_cfg.
  The streaming configuration is needed to simulate streaming inference.
  Args:
      chunk_size (int): overrides the chunk size
      shift_size (int): overrides the shift size for chunks
      left_chunks (int): overrides the number of left chunks visible to each chunk
      max_context (int): the value used for the cache size of last_channel layers if left context is set to infinity (-1)
          Defaults to -1 (means feat_out is d_model)
docstr_tok: ["This","function","sets","the","needed","values","and","parameters","to","perform","streaming",".","The","configuration","would","be","stored","in","self.streaming_cfg",".","The","streaming","configuration","is","needed","to","simulate","streaming","inference",".","Args",":","chunk_size","(","int",")",":","overrides","the","chunk","size","shift_size","(","int",")",":","overrides","the","shift","size","for","chunks","left_chunks","(","int",")",":","overrides","the","number","of","left","chunks","visible","to","each","chunk","max_context","(","int",")",":","the","value","used","for","the","cache","size","of","last_channel","layers","if","left","context","is","set","to","infinity","(","-1",")","Defaults","to","-1","(","means","feat_out","is","d_model",")"]
code: def setup_streaming_params(
      self,
      chunk_size: int = None,
      shift_size: int = None,
      left_chunks: int = None,
      att_context_size: list = None,
      max_context: int = 10000,
  ):
      """
      This function sets the needed values and parameters to perform streaming. The configuration would be stored in self.streaming_cfg.
      The streaming configuration is needed to simulate streaming inference.
      Args:
          chunk_size (int): overrides the chunk size
          shift_size (int): overrides the shift size for chunks
          left_chunks (int): overrides the number of left chunks visible to each chunk
          max_context (int): the value used for the cache size of last_channel layers if left context is set to infinity (-1)
              Defaults to -1 (means feat_out is d_model)
      """
      streaming_cfg = CacheAwareStreamingConfig()
  
      # When att_context_size is not specified, it uses the default_att_context_size
      if att_context_size is None:
          att_context_size = self.att_context_size
  
      if chunk_size is not None:
          if chunk_size < 1:
              raise ValueError(
                  "chunk_size needs to be a number larger or equal to one."
              )
          lookahead_steps = chunk_size - 1
          streaming_cfg.cache_drop_size = chunk_size - shift_size
      elif self.att_context_style == "chunked_limited":
          lookahead_steps = att_context_size[1]
          streaming_cfg.cache_drop_size = 0
      elif self.att_context_style == "regular":
          lookahead_steps = (
              att_context_size[1] * self.n_layers
              + self.conv_context_size[1] * self.n_layers
          )
          streaming_cfg.cache_drop_size = lookahead_steps
      else:
          streaming_cfg.cache_drop_size = 0
          lookahead_steps = None
  
      if chunk_size is None:
          streaming_cfg.last_channel_cache_size = (
              att_context_size[0]
              if att_context_size[0] >= 0
              else max_context
          )
      else:
          if left_chunks is None:
              raise ValueError(
                  "left_chunks can not be None when chunk_size is set."
              )
          streaming_cfg.last_channel_cache_size = (
              left_chunks * chunk_size
          )
  
      if hasattr(self.pre_encode, "get_sampling_frames"):
          sampling_frames = self.pre_encode.get_sampling_frames()
      else:
          sampling_frames = 0
  
      if isinstance(sampling_frames, list):
          streaming_cfg.chunk_size = [
              sampling_frames[0]
              + self.subsampling_factor * lookahead_steps,
              sampling_frames[1]
              + self.subsampling_factor * lookahead_steps,
          ]
      else:
          streaming_cfg.chunk_size = sampling_frames * (
              1 + lookahead_steps
          )
  
      if isinstance(sampling_frames, list):
          streaming_cfg.shift_size = [
              sampling_frames[0]
              + sampling_frames[1]
              * (lookahead_steps - streaming_cfg.cache_drop_size),
              sampling_frames[1]
              + sampling_frames[1]
              * (lookahead_steps - streaming_cfg.cache_drop_size),
          ]
      else:
          streaming_cfg.shift_size = sampling_frames * (
              1 + lookahead_steps - streaming_cfg.cache_drop_size
          )
  
      if isinstance(streaming_cfg.shift_size, list):
          streaming_cfg.valid_out_len = (
              streaming_cfg.shift_size[1] - sampling_frames[1]
          ) // self.subsampling_factor + 1
      else:
          streaming_cfg.valid_out_len = (
              streaming_cfg.shift_size // self.subsampling_factor
          )
  
      if hasattr(self.pre_encode, "get_streaming_cache_size"):
          streaming_cfg.pre_encode_cache_size = (
              self.pre_encode.get_streaming_cache_size()
          )
      else:
          streaming_cfg.pre_encode_cache_size = 0
  
      if isinstance(streaming_cfg.pre_encode_cache_size, list):
          if streaming_cfg.pre_encode_cache_size[1] >= 1:
              streaming_cfg.drop_extra_pre_encoded = (
                  1
                  + (streaming_cfg.pre_encode_cache_size[1] - 1)
                  // self.subsampling_factor
              )
          else:
              streaming_cfg.drop_extra_pre_encoded = 0
      else:
          streaming_cfg.drop_extra_pre_encoded = (
              streaming_cfg.pre_encode_cache_size
              // self.subsampling_factor
          )
  
      for m in self.layers.modules():
          if hasattr(m, "_max_cache_len"):
              if isinstance(m, MultiHeadAttention):
                  m.cache_drop_size = streaming_cfg.cache_drop_size
              if isinstance(m, CausalConv1D):
                  m.cache_drop_size = streaming_cfg.cache_drop_size
  
      self.streaming_cfg = streaming_cfg
  
imports: import math
  import random
  from collections import OrderedDict
  from dataclasses import dataclass
  from typing import List, Optional, Set
  import torch
  import torch.distributed
  import torch.nn
  from omegaconf import DictConfig, ListConfig, open_dict
  from nemo.collections.asr.models.configs import CacheAwareStreamingConfig
  from nemo.collections.asr.parts.mixins.streaming import StreamingEncoder
  from nemo.collections.asr.parts.submodules.causal_convs import CausalConv1D
  from nemo.collections.asr.parts.submodules.conformer_modules import ConformerLayer
  from nemo.collections.asr.parts.submodules.multi_head_attention import LocalAttRelPositionalEncoding, MultiHeadAttention, PositionalEncoding, RelPositionalEncoding, RelPositionMultiHeadAttention, RelPositionMultiHeadAttentionLongformer
  from nemo.collections.asr.parts.submodules.subsampling import ConvSubsampling, StackingSubsampling, SubsamplingReductionModule
  from nemo.collections.asr.parts.utils import adapter_utils
  from nemo.collections.asr.parts.utils.regularization_utils import compute_stochastic_depth_drop_probs
  from nemo.core.classes.common import typecheck
  from nemo.core.classes.exportable import Exportable
  from nemo.core.classes.mixins import AccessMixin, adapter_mixins
  from nemo.core.classes.module import NeuralModule
  from nemo.core.neural_types import AcousticEncodedRepresentation, ChannelType, LengthsType, NeuralType, SpectrogramType
  from nemo.utils import logging
label_desc: Use image node_id 19 for calling the ConformerEncoder obj's underlying member method code with example usage: obj.setup_streaming_params(chunk_size, shift_size, left_chunks, att_context_size, max_context) without return types