code: def build_encoder(cls, args):
      _args = copy.deepcopy(args)
      if not args.adaptor_proj and not args.encoder_proj:  # V0 arch
          if args.w2v_path:
              state = checkpoint_utils.load_checkpoint_to_cpu(
                  args.w2v_path
              )
              if state.get("cfg") is not None:
                  encoder_embed_dim = state["cfg"]._content["model"][
                      "encoder_embed_dim"
                  ]
              elif state.get("args") is not None:
                  encoder_embed_dim = state["args"].encoder_embed_dim
              else:
                  raise ValueError(f"Invalid config in {args.w2v_path}")
              _args.decoder_embed_dim = encoder_embed_dim
              del state
          else:
              _args.decoder_embed_dim = args.encoder_embed_dim
  
      encoder = Wav2VecEncoderWithAdaptor(_args)
      encoder = cls.maybe_load_pretrained(
          encoder, getattr(args, "load_pretrained_encoder_from", None)
      )
      if args.remove_weight_norm:
          # remove the wn for EMA usage
          logger.warning("Removing weight norm from wav2vec encoder")
          remove_weight_norm_from_model(encoder)
  
      return encoder
  
imports: import copy
  import logging
  from typing import Dict, List, Optional, Tuple
  import numpy
  import torch
  import torch.nn
  from torch import Tensor
  from fairseq import checkpoint_utils, utils
  from fairseq.data.data_utils import lengths_to_padding_mask
  from fairseq.models import FairseqEncoder, FairseqEncoderDecoderModel, FairseqEncoderModel, FairseqLanguageModel, register_model, register_model_architecture
  from fairseq.models.speech_to_speech.modules.ctc_decoder import CTCDecoder
  from fairseq.models.speech_to_text.hub_interface import S2THubInterface
  from fairseq.models.transformer import Embedding, TransformerDecoder, TransformerModelBase
  from fairseq.models.wav2vec import Wav2VecEncoder
  from fairseq.modules.layer_norm import LayerNorm
label_desc: Use image node_id 6 for calling the XMTransformerModel obj's underlying member method code with example usage: obj.build_encoder(cls, args) and returns: encoder