class_docstr: MEGA module.
  
  Args:
      size: Input/Output size.
      num_heads: Number of EMA heads.
      qk_size: Shared query and key size for attention module.
      v_size: Value size for attention module.
      qk_v_size: (QK, V) sizes for attention module.
      activation: Activation function type.
      normalization: Normalization module.
      rel_pos_bias_type: Type of relative position bias in attention module.
      max_positions: Maximum number of position for RelativePositionBias.
      truncation_length: Maximum length for truncation in EMA module.
      chunk_size: Chunk size for attention computation (-1 = full context).
      dropout_rate: Dropout rate for inner modules.
      att_dropout_rate: Dropout rate for the attention module.
      ema_dropout_rate: Dropout rate for the EMA module.
docstr: Construct a MEGA object.
docstr_tok: ["Construct","a","MEGA","object","."]
code: def __init__(
      self,
      size: int = 512,
      num_heads: int = 4,
      qk_size: int = 128,
      v_size: int = 1024,
      activation: torch.nn.Module = torch.nn.ReLU(),
      normalization: torch.nn.Module = torch.nn.LayerNorm,
      rel_pos_bias_type: str = "simple",
      max_positions: int = 2048,
      truncation_length: Optional[int] = None,
      chunk_size: int = -1,
      dropout_rate: float = 0.0,
      att_dropout_rate: float = 0.0,
      ema_dropout_rate: float = 0.0,
  ) -> None:
      """Construct a MEGA object."""
      super().__init__()
  
      self.multihead_damped_ema = MultiHeadDampedEMA(
          size,
          num_heads=num_heads,
          activation=activation,
          truncation_length=truncation_length,
      )
  
      if chunk_size > 0:
          max_positions = chunk_size
  
      if rel_pos_bias_type == "rotary":
          self.rel_pos_bias = RotaryRelativePositionBias(
              qk_size, max_positions
          )
      elif rel_pos_bias_type == "simple":
          self.rel_pos_bias = RelativePositionBias(max_positions)
      else:
          raise ValueError(
              "Only 'rotary' and 'simple' are valid values for rel_pos_bias_type"
          )
  
      self.proj_v = torch.nn.Linear(size, v_size)
      self.proj_mx = torch.nn.Linear(size, qk_size + v_size + 2 * size)
      self.proj_h = torch.nn.Linear(v_size, size)
  
      self.qk_weight = torch.nn.Parameter(torch.Tensor(2, qk_size))
      self.qk_bias = torch.nn.Parameter(torch.Tensor(2, qk_size))
  
      self.scaling = qk_size**-0.5
  
      self.activation = activation
      self.normalization = normalization
  
      self.dropout = torch.nn.Dropout(p=dropout_rate)
      self.dropout_attn = torch.nn.Dropout(p=att_dropout_rate)
      self.dropout_ema = torch.nn.Dropout(p=ema_dropout_rate)
  
      self.qk_size = qk_size
      self.v_size = v_size
  
      self.size = size
      self.chunk_size = chunk_size
  
      self.reset_parameters()
  
file_path: espnet/espnet2/asr_transducer/decoder/blocks/mega.py
imports: from typing import Dict, Optional, Tuple
  import torch
  from espnet2.asr_transducer.decoder.modules.mega.multi_head_damped_ema import MultiHeadDampedEMA
  from espnet2.asr_transducer.decoder.modules.mega.positional_bias import RelativePositionBias, RotaryRelativePositionBias
label_desc: Use image node_id 1 to create a new MEGA object from inherited base classes: torch.nn with example: obj = MEGA(size, num_heads, qk_size, v_size, activation, normalization, rel_pos_bias_type, max_positions, truncation_length, chunk_size, dropout_rate, att_dropout_rate, ema_dropout_rate)