class_docstr: Transformer encoder consisting of *cfg.encoder.layers* layers. Each layer
  is a :class:`TransformerEncoderLayer`.
  
  Args:
      args (argparse.Namespace): parsed command-line arguments
      dictionary (~fairseq.data.Dictionary): encoding dictionary
      embed_tokens (torch.nn.Embedding): input embedding
class_docstr_tok: ["Transformer","encoder","consisting","of","*","cfg.encoder.layers","*","layers",".","Each","layer","is","a",":","class",":","`","TransformerEncoderLayer","`",".","Args",":","args","(","argparse.Namespace",")",":","parsed","command-line","arguments","dictionary","(","~fairseq.data.Dictionary",")",":","encoding","dictionary","embed_tokens","(","torch.nn.Embedding",")",":","input","embedding"]
code: def __init__(self, cfg, dictionary, embed_tokens, return_fc=False):
      self.cfg = cfg
      super().__init__(dictionary)
      self.register_buffer("version", torch.Tensor([3]))
  
      self.dropout_module = FairseqDropout(
          cfg.dropout,
          module_name=module_name_fordropout(self.__class__.__name__),
      )
      self.encoder_layerdrop = cfg.encoder.layerdrop
      self.return_fc = return_fc
  
      embed_dim = embed_tokens.embedding_dim
      self.padding_idx = embed_tokens.padding_idx
      self.max_source_positions = cfg.max_source_positions
  
      self.embed_tokens = embed_tokens
  
      self.embed_scale = (
          1.0 if cfg.no_scale_embedding else math.sqrt(embed_dim)
      )
  
      self.embed_positions = (
          PositionalEmbedding(
              cfg.max_source_positions,
              embed_dim,
              self.padding_idx,
              learned=cfg.encoder.learned_pos,
          )
          if not cfg.no_token_positional_embeddings
          else None
      )
      if cfg.layernorm_embedding:
          self.layernorm_embedding = LayerNorm(
              embed_dim, export=cfg.export
          )
      else:
          self.layernorm_embedding = None
  
      if not cfg.adaptive_input and cfg.quant_noise.pq > 0:
          self.quant_noise = apply_quant_noise_(
              nn.Linear(embed_dim, embed_dim, bias=False),
              cfg.quant_noise.pq,
              cfg.quant_noise.pq_block_size,
          )
      else:
          self.quant_noise = None
  
      if self.encoder_layerdrop > 0.0:
          self.layers = LayerDropModuleList(p=self.encoder_layerdrop)
      else:
          self.layers = nn.ModuleList([])
      self.layers.extend(
          [
              self.build_encoder_layer(cfg)
              for i in range(cfg.encoder.layers)
          ]
      )
      self.num_layers = len(self.layers)
  
      if cfg.encoder.normalize_before:
          self.layer_norm = LayerNorm(embed_dim, export=cfg.export)
      else:
          self.layer_norm = None
  
imports: import math
  from typing import Dict, List, Optional
  import torch
  import torch.nn
  from torch import Tensor
  from fairseq import utils
  from fairseq.distributed import fsdp_wrap
  from fairseq.models import FairseqEncoder
  from fairseq.models.transformer import TransformerConfig
  from fairseq.modules import FairseqDropout, LayerDropModuleList, LayerNorm, PositionalEmbedding, SinusoidalPositionalEmbedding, transformer_layer
  from fairseq.modules.checkpoint_activations import checkpoint_wrapper
  from fairseq.modules.quant_noise import quant_noise
label_desc: Use image node_id 1 to create a new TransformerEncoderBase object from inherited base classes: FairseqEncoder with example: obj = TransformerEncoderBase(cfg, dictionary, embed_tokens, return_fc)