    def build_model(cls, cfg: HubertSeq2SeqConfig, task: FairseqTask):
        """Build a new model instance."""

        assert (
            cfg.autoregressive
        ), "Please set task.autoregressive=true for seq2seq asr models"

        src_dict, tgt_dict = task.source_dictionary, task.target_dictionary

        def build_embedding(dictionary, embed_dim):
            num_embeddings = len(dictionary)
            padding_idx = dictionary.pad()
            emb = Embedding(num_embeddings, embed_dim, padding_idx)
            return emb

        decoder_embed_tokens = build_embedding(tgt_dict, cfg.decoder_embed_dim)

        encoder = cls.build_encoder(cfg, task)
        decoder = cls.build_decoder(cfg, tgt_dict, decoder_embed_tokens)

        model = HubertSeq2SeqModel(encoder, decoder)

        if cfg["seq2seq_path"]:
            state = checkpoint_utils.load_checkpoint_to_cpu(cfg.seq2seq_path)
            state = state["model"]
            if cfg["reset_dict"]:
                del state["decoder.embed_out"]
                del state["decoder.embed_tokens.weight"]
            model.load_state_dict(state, strict=False)
        return model
Build a new model instance.
fairseq/models/hubert/hubert_asr.py