class_docstr: Encoder layer block.
  
  In the original paper each operation (multi-head attention or FFN) is
  postprocessed with: `dropout -> add residual -> layernorm`. In the
  tensor2tensor code they suggest that learning is more robust when
  preprocessing each layer with layernorm and postprocessing with:
  `dropout -> add residual`. We default to the approach in the paper, but the
  tensor2tensor approach can be enabled by setting
  *cfg.encoder.normalize_before* to ``True``.
  
  Args:
      args (argparse.Namespace): parsed command-line arguments
class_docstr_tok: ["Encoder","layer","block",".","In","the","original","paper","each","operation","(","multi-head","attention","or","FFN",")","is","postprocessed","with",":","`","dropout","-",">","add","residual","-",">","layernorm","`",".","In","the","tensor2tensor","code","they","suggest","that","learning","is","more","robust","when","preprocessing","each","layer","with","layernorm","and","postprocessing","with",":","`","dropout","-",">","add","residual","`",".","We","default","to","the","approach","in","the","paper",",","but","the","tensor2tensor","approach","can","be","enabled","by","setting","*","cfg.encoder.normalize_before","*","to","``","True","``",".","Args",":","args","(","argparse.Namespace",")",":","parsed","command-line","arguments"]
code: def lang_adapter(self, lang_id, x):
      # If language adapters exist pass throught them
      if (
          hasattr(self.cfg, "adapter_modules")
          and self.cfg.adapter_modules
      ):
          if lang_id is None:
              lang_id = ["en_XX"] * x.shape[1]
          d_langs = [lang_id[0]]
          lang_lengths = [1]
          for lang in lang_id[1:]:
              if lang == d_langs[-1]:
                  lang_lengths[-1] += 1
              else:
                  d_langs.append(lang)
                  lang_lengths.append(1)
  
          if (
              not hasattr(self.cfg, "ln_before_adapter")
              or not self.cfg.ln_before_adapter
          ):
              residual = x
          if self.cfg.adapter_layer_norm:
              x = self.adapter_layer_norm(x)
          elif self.cfg.adapter_reuse_layer_norm:
              x = self.final_layer_norm(x)
          if (
              hasattr(self.cfg, "ln_before_adapter")
              and self.cfg.ln_before_adapter
          ):
              residual = x
  
          split_x = torch.split(x, lang_lengths, 1)
          x_ = []
          for i, (lang, s_x) in enumerate(zip(d_langs, split_x)):
              lang = lang.replace("_rom", "").replace("_zaw", "")
              x_.append(self.adapter_modules[str(lang)](s_x))
          x = torch.cat(x_, 1)
  
          x = self.dropout_module(x)
          x = self.residual_connection(x, residual)
  
      return x
  
file_path: fairseq/fairseq/models/xmod/transformer_layer_xmod.py
imports: from fairseq.modules.transformer_layer import TransformerEncoderLayer
  from typing import Optional
  import torch
  import torch.nn
  from fairseq import utils
  from fairseq.modules import LayerNorm
  from fairseq.modules.fairseq_dropout import FairseqDropout
  from fairseq.modules.quant_noise import quant_noise
  from torch import Tensor
label_desc: Use image node_id 2 for calling the XMODTransformerEncoderLayerBase obj's underlying member method code with example usage: obj.lang_adapter(lang_id, x) and returns: x