def METHOD_NAME(cls, cfg, task):
    """Build a new model instance."""
    # -- TODO T96535332
    # bug caused by interaction between OmegaConf II and argparsing
    cfg.decoder.input_dim = int(cfg.decoder.input_dim)
    cfg.decoder.output_dim = int(cfg.decoder.output_dim)
    # --
    if cfg.encoder.layers_to_keep:
        cfg.encoder.layers = len(cfg.encoder.layers_to_keep.split(","))
    if cfg.decoder.layers_to_keep:
        cfg.decoder.layers = len(cfg.decoder.layers_to_keep.split(","))
    if cfg.max_source_positions is None:
        cfg.max_source_positions = DEFAULT_MAX_SOURCE_POSITIONS
    if cfg.max_target_positions is None:
        cfg.max_target_positions = DEFAULT_MAX_TARGET_POSITIONS
    tgt_dict = task.target_dictionary
    decoder_embed_tokens = cls.build_embedding(
        cfg, tgt_dict, cfg.decoder.input_dim, cfg.decoder.embed_path
    )
    if cfg.offload_activations:
        cfg.checkpoint_activations = True  # offloading implies checkpointing
    out_channels = speech_utils.eval_str_nested_list_or_tuple(
        cfg.encoder.conv_channels, type=int
    )
    kernel_sizes = speech_utils.eval_str_nested_list_or_tuple(
        cfg.encoder.conv_kernel_sizes, type=int
    )
    strides = speech_utils.eval_str_nested_list_or_tuple(
        cfg.encoder.conv_strides, type=int
    )
    logger.info(
        "input feature dimension: {}, channels: {}".format(
            task.feat_dim, task.feat_in_channels
        )
    )
    assert task.feat_dim % task.feat_in_channels == 0
    conv_layers = (
        ConvBNReLU(
            out_channels,
            kernel_sizes,
            strides,
            in_channels=task.feat_in_channels,
        )
        if out_channels is not None
        else None
    )
    transformer_encoder_input_size = task.feat_dim // task.feat_in_channels
    if conv_layers is not None:
        for stride in strides:
            if isinstance(stride, (list, tuple)):
                assert len(stride) > 0
                s = stride[1] if len(stride) > 1 else stride[0]
            else:
                assert isinstance(stride, int)
                s = stride
            transformer_encoder_input_size = (
                transformer_encoder_input_size + s - 1
            ) // s
        transformer_encoder_input_size *= out_channels[-1]
    else:
        transformer_encoder_input_size = task.feat_dim
    scheduled_sampling_rate_scheduler = ScheduledSamplingRateScheduler(
        cfg.scheduled_sampling_probs,
        cfg.start_scheduled_sampling_epoch,
    )
    encoder = cls.build_encoder(
        cfg,
        pre_encoder=conv_layers,
        input_size=transformer_encoder_input_size,
    )
    decoder = cls.build_decoder(
        cfg,
        tgt_dict,
        decoder_embed_tokens,
        scheduled_sampling_rate_scheduler=scheduled_sampling_rate_scheduler,
    )
    return cls(cfg, encoder, decoder)