class_docstr: MEGA decoder module.
  
  Based on https://arxiv.org/pdf/2209.10655.pdf.
  
  Args:
      vocab_size: Vocabulary size.
      block_size: Input/Output size.
      linear_size: NormalizedPositionwiseFeedForward hidden size.
      qk_size: Shared query and key size for attention module.
      v_size: Value size for attention module.
      num_heads: Number of EMA heads.
      rel_pos_bias: 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.
      normalization_type: Normalization layer type.
      normalization_args: Normalization layer arguments.
      activation_type: Activation function type.
      activation_args: Activation function arguments.
      chunk_size: Chunk size for attention computation (-1 = full context).
      num_blocks: Number of MEGA blocks.
      dropout_rate: Dropout rate for MEGA internal modules.
      embed_dropout_rate: Dropout rate for embedding layer.
      att_dropout_rate: Dropout rate for the attention module.
      ema_dropout_rate: Dropout rate for the EMA module.
      ffn_dropout_rate: Dropout rate for the feed-forward module.
      embed_pad: Embedding padding symbol ID.
docstr: Construct a MEGADecoder object.
docstr_tok: ["Construct","a","MEGADecoder","object","."]
code: def __init__(
      self,
      vocab_size: int,
      block_size: int = 512,
      linear_size: int = 1024,
      qk_size: int = 128,
      v_size: int = 1024,
      num_heads: int = 4,
      rel_pos_bias_type: str = "simple",
      max_positions: int = 2048,
      truncation_length: Optional[int] = None,
      normalization_type: str = "layer_norm",
      normalization_args: Dict = {},
      activation_type: str = "swish",
      activation_args: Dict = {},
      chunk_size: int = -1,
      num_blocks: int = 4,
      dropout_rate: float = 0.0,
      embed_dropout_rate: float = 0.0,
      att_dropout_rate: float = 0.0,
      ema_dropout_rate: float = 0.0,
      ffn_dropout_rate: float = 0.0,
      embed_pad: int = 0,
  ) -> None:
      """Construct a MEGADecoder object."""
      super().__init__()
  
      assert check_argument_types()
  
      self.embed = torch.nn.Embedding(
          vocab_size, block_size, padding_idx=embed_pad
      )
      self.dropout_embed = torch.nn.Dropout(p=embed_dropout_rate)
  
      activation = get_activation(activation_type, **activation_args)
      norm_class, norm_args = get_normalization(
          normalization_type, **normalization_args
      )
  
      self.mega_blocks = torch.nn.ModuleList(
          [
              torch.nn.ModuleList(
                  [
                      MEGA(
                          block_size,
                          num_heads=num_heads,
                          qk_size=qk_size,
                          v_size=v_size,
                          activation=activation,
                          normalization=norm_class(
                              block_size, **norm_args
                          ),
                          rel_pos_bias_type=rel_pos_bias_type,
                          max_positions=max_positions,
                          truncation_length=truncation_length,
                          chunk_size=chunk_size,
                          dropout_rate=dropout_rate,
                          att_dropout_rate=att_dropout_rate,
                          ema_dropout_rate=ema_dropout_rate,
                      ),
                      NormalizedPositionwiseFeedForward(
                          block_size,
                          linear_size,
                          normalization=norm_class(
                              block_size, **norm_args
                          ),
                          activation=activation,
                          dropout_rate=ffn_dropout_rate,
                      ),
                  ]
              )
              for _ in range(num_blocks)
          ]
      )
  
      self.final_norm = norm_class(block_size, **norm_args)
  
      self.vocab_size = vocab_size
      self.output_size = block_size
      self.chunk_size = chunk_size
  
      self.mega_num_heads = num_heads
      self.mega_att_k_size = qk_size
      self.mega_att_v_size = v_size
      self.mega_ema_size = block_size
      self.mega_ema_num_heads = num_heads
  
      self.pad_idx = embed_pad
      self.num_blocks = num_blocks
  
      self.score_cache = {}
  
      self.device = next(self.parameters()).device
  
imports: import math
  from typing import Dict, List, Optional, Tuple
  import torch
  from typeguard import check_argument_types
  from espnet2.asr_transducer.activation import get_activation
  from espnet2.asr_transducer.beam_search_transducer import Hypothesis
  from espnet2.asr_transducer.decoder.abs_decoder import AbsDecoder
  from espnet2.asr_transducer.decoder.blocks.mega import MEGA
  from espnet2.asr_transducer.decoder.modules.mega.feed_forward import NormalizedPositionwiseFeedForward
  from espnet2.asr_transducer.normalization import get_normalization
label_desc: Use image node_id 1 to create a new MEGADecoder object from inherited base classes: AbsDecoder with example: obj = MEGADecoder(vocab_size, block_size, linear_size, qk_size, v_size, num_heads, rel_pos_bias_type, max_positions, truncation_length, normalization_type, normalization_args, activation_type, activation_args, chunk_size, num_blocks, dropout_rate, embed_dropout_rate, att_dropout_rate, ema_dropout_rate, ffn_dropout_rate, embed_pad)