    def build_model(cls, args, task):
        """Build a new model instance."""

        # make sure all arguments are present in older models
        base_architecture(args)
        if getattr(args, "load_pretrained_decoder_from", None) is not None:
            ckpt = torch.load(getattr(args, "load_pretrained_decoder_from", None))
            decoder_args_dict = cls.get_decoder_args_from_checkpoint(ckpt["cfg"])
            args = cls.override_decoder_args(args, decoder_args_dict)

        decoder_embed_tokens = build_embedding(
            task.target_dictionary, args.decoder_embed_dim
        )

        encoder = cls.build_encoder(args)
        decoder = cls.build_decoder(args, task, decoder_embed_tokens)
        base_model = cls(encoder, decoder)

        # set up multitask decoders
        base_model.multitask_decoders = {}
        for i, (task_name, task_obj) in enumerate(task.multitask_tasks.items()):
            # dummy auxiliary decoder
            if task_obj.args.get_loss_weight(0) == 0:
                continue

            task_decoder = cls.build_multitask_decoder(
                args, task_obj.args, task_obj.target_dictionary, args.decoder_embed_dim
            )

            setattr(base_model, f"{task_name}_decoder", task_decoder)
            decoder_model_cls = (
                FairseqEncoderModel
                if task_obj.args.decoder_type == "ctc"
                else FairseqLanguageModel
            )
            base_model.multitask_decoders[task_name] = decoder_model_cls(
                getattr(base_model, f"{task_name}_decoder")
            )
        return base_model
Build a new model instance.
fairseq/models/speech_to_text/xm_transformer.py