code: def build_encoder(cls, args, task):
      _args = copy.deepcopy(args)
      _args.dropout = args.mbart_dropout
      _args.attention_dropout = args.mbart_attention_dropout
      _args.activation_dropout = args.mbart_activation_dropout
      _args.max_source_positions = 1024
      enc_emb = nn.Embedding(
          len(task.src_dict),
          _args.encoder_embed_dim,
          task.src_dict.pad(),
      )
      text_encoder = TransformerEncoder(_args, task.src_dict, enc_emb)
      spch_encoder = Wav2VecEncoderWithAdaptor(args)
      if getattr(args, "load_pretrained_mbart_from", None):
          text_encoder = (
              checkpoint_utils.load_pretrained_component_from_model(
                  component=text_encoder,
                  checkpoint=args.load_pretrained_mbart_from,
              )
          )
      if getattr(args, "stack_w2v_mbart_encoder", False):
          assert getattr(args, "share_w2v_text_encoder", False) is False
          spch_encoder = StackedWav2VecEncoderWithAdaptor(
              spch_encoder.w2v_encoder,
              text_encoder.layers,
              text_encoder.layer_norm,
              spch_encoder.adaptor,
              args.drop_w2v_layers,
          )
      elif getattr(args, "stack_w2v_mbart_nonorm_encoder", False):
          text_encoder.layer_norm = None
          spch_encoder = StackedWav2VecEncoderWithAdaptor(
              spch_encoder.w2v_encoder,
              text_encoder.layers,
              text_encoder.layer_norm,
              spch_encoder.adaptor,
              args.drop_w2v_layers,
          )
      elif getattr(args, "share_w2v_text_encoder", False):
          spch_encoder = SharedEncoder(
              spch_encoder.w2v_encoder,
              text_encoder,
              spch_encoder.adaptor,
              args.shared_w2v_layers,
          )
  
      for k, p in spch_encoder.named_parameters():
          # Freeze pretrained models by default
          if safe_hasattr(
              args, "finetune_w2v_params"
          ) and need_finetuning(args.finetune_w2v_params, k):
              p.requires_grad = True
          else:
              p.requires_grad = False
      for k, p in text_encoder.named_parameters():
          # Freeze pretrained models by default
          if safe_hasattr(
              args, "finetune_mbart_encoder_params"
          ) and need_finetuning(args.finetune_mbart_encoder_params, k):
              p.requires_grad = True
          else:
              p.requires_grad = False
      cross_attentive_loss_before_last_layer = (
          0
          if getattr(args, "attentive_cost_regularization", 0.0) > 0.0
          else -1
      )
      encoder = DualInputEncoder(
          args,
          spch_encoder,
          text_encoder,
          task.src_dict,
          cross_attentive_loss_before_last_layer,
      )
      return encoder
  
imports: import copy
  import torch.nn
  from fairseq import checkpoint_utils
  from fairseq import utils
  from fairseq.data.data_utils import lengths_to_padding_mask
  from fairseq.models import register_model, register_model_architecture, FairseqEncoder
  from fairseq.models.speech_to_text import Wav2VecEncoderWithAdaptor
  from fairseq.models.speech_to_text.xm_transformer import set_default_adaptor_args, set_default_w2v_encoder_args, need_finetuning
  from fairseq.models.transformer import TransformerEncoder, TransformerDecoder
  from fairseq.models.wav2vec import TransformerSentenceEncoderLayer
  from fairseq.utils import safe_hasattr
  from .s2t_dualinputtransformer import DualInputS2TTransformerModel, TransformerMultiInputDecoder, DualInputEncoder
label_desc: Use image node_id 3 for calling the DualInputXMTransformerModel obj's underlying member method code with example usage: obj.build_encoder(cls, args, task) and returns: encoder