def load_config(args=None, config_file=None, overwrite_fairseq=False):
    """TODO (huxu): move fairseq overwrite to another function."""
    if args is not None:
        config_file = args.taskconfig
    config = recursive_config(config_file)

    if config.dataset.subsampling is not None:
        batch_size = config.fairseq.dataset.batch_size // config.dataset.subsampling
        print(
            "adjusting batch_size to {} due to subsampling {}.".format(
                batch_size, config.dataset.subsampling
            )
        )
        config.fairseq.dataset.batch_size = batch_size

    is_test = config.dataset.split is not None and config.dataset.split == "test"
    if not is_test:
        if (
            config.fairseq.checkpoint is None
            or config.fairseq.checkpoint.save_dir is None
        ):
            raise ValueError("fairseq save_dir or save_path must be specified.")

        save_dir = config.fairseq.checkpoint.save_dir
        os.makedirs(save_dir, exist_ok=True)
        if config.fairseq.common.tensorboard_logdir is not None:
            tb_run_dir = suffix_rundir(
                save_dir, config.fairseq.common.tensorboard_logdir
            )
            config.fairseq.common.tensorboard_logdir = tb_run_dir
            print(
                "update tensorboard_logdir as", config.fairseq.common.tensorboard_logdir
            )
        os.makedirs(save_dir, exist_ok=True)
        OmegaConf.save(config=config, f=os.path.join(save_dir, "config.yaml"))

    if overwrite_fairseq and config.fairseq is not None and args is not None:
        # flatten fields.
        for group in config.fairseq:
            for field in config.fairseq[group]:
                print("overwrite args." + field, "as", config.fairseq[group][field])
                setattr(args, field, config.fairseq[group][field])
    return config
TODO (huxu): move fairseq overwrite to another function.
examples/MMPT/mmpt/utils/load_config.py