class_docstr: FairSeq Hubert pretrain encoder module, only used for pretraining stage
  
  Args:
      input_size: input dim
      output_size: dimension of attention
      linear_units: dimension of feedforward layers
      attention_heads: the number of heads of multi head attention
      num_blocks: the number of encoder blocks
      dropout_rate: dropout rate
      attention_dropout_rate: dropout rate in attention
      hubert_dict: target dictionary for Hubert pretraining
      label_rate: label frame rate. -1 for sequence label
      sample_rate: target sample rate.
      use_amp: whether to use automatic mixed precision
      normalize_before: whether to use layer_norm before the first block
code: def __init__(
      self,
      input_size: int = 1,
      output_size: int = 1024,
      linear_units: int = 1024,
      attention_heads: int = 12,
      num_blocks: int = 12,
      dropout_rate: float = 0.0,
      attention_dropout_rate: float = 0.0,
      activation_dropout_rate: float = 0.0,
      hubert_dict: str = "./dict.txt",
      label_rate: int = 100,
      checkpoint_activations: bool = False,
      sample_rate: int = 16000,
      use_amp: bool = False,
      **kwargs,
  ):
      assert check_argument_types()
      super().__init__()
      self._output_size = output_size
      self.use_amp = use_amp
      try:
          from fairseq.data.dictionary import Dictionary
          from fairseq.models.hubert.hubert import (
              HubertConfig,
          )  # noqa: H301
          from fairseq.models.hubert.hubert import (
              HubertModel,
          )  # noqa: H301
          from fairseq.models.hubert.hubert import (  # noqa: H301
              HubertPretrainingConfig,
          )
      except Exception as e:
          print("Error: FairSeq is not properly installed.")
          print(
              "Please install FairSeq: cd ${MAIN_ROOT}/tools && make fairseq.done"
          )
          raise e
  
      cfg_overides = {
          "encoder_embed_dim": output_size,
          "encoder_ffn_embed_dim": linear_units,
          "encoder_attention_heads": attention_heads,
          "encoder_layers": num_blocks,
          "final_dim": output_size,
          "dropout": dropout_rate,
          "attention_dropout": attention_dropout_rate,
          "label_rate": label_rate,
          "checkpoint_activations": checkpoint_activations,
      }
      cfg_overides = {**cfg_overides, **kwargs}
      self.cfg = HubertConfig()
  
      for key, value in cfg_overides.items():
          if hasattr(self.cfg, key):
              setattr(self.cfg, key, value)
  
      hubert_task_cfg = HubertPretrainingConfig()
      hubert_task_cfg_overides = {
          "label_rate": label_rate,
          "sample_rate": sample_rate,
      }
      for key, value in hubert_task_cfg_overides.items():
          if hasattr(hubert_task_cfg, key):
              setattr(hubert_task_cfg, key, value)
  
      d = Dictionary()
      self._build_dictionary(d, hubert_dict)
      self.encoder = HubertModel(
          self.cfg, hubert_task_cfg, self.dictionaries
      )
  
imports: import contextlib
  import copy
  import logging
  import os
  from pathlib import Path
  from typing import List, Optional, Tuple
  import torch
  import yaml
  from filelock import FileLock
  from typeguard import check_argument_types
  from espnet2.asr.encoder.abs_encoder import AbsEncoder
  from espnet.nets.pytorch_backend.nets_utils import make_pad_mask
  from espnet.nets.pytorch_backend.transformer.layer_norm import LayerNorm
label_desc: Use image node_id 1 to create a new FairseqHubertPretrainEncoder object from inherited base classes: AbsEncoder with example: obj = FairseqHubertPretrainEncoder(input_size, output_size, linear_units, attention_heads, num_blocks, dropout_rate, attention_dropout_rate, activation_dropout_rate, hubert_dict, label_rate, checkpoint_activations, sample_rate, use_amp)