# Buggy code
def prepare(cls, args, **kargs):
    args.left_pad_source = options.eval_bool(args.left_pad_source)
    args.left_pad_target = options.eval_bool(args.left_pad_target)

    if args.lang_pairs is None:
        raise ValueError(
            "--lang-pairs is required. List all the language pairs in the training objective."
        )
    args.lang_pairs = args.lang_pairs.split(",")
    sorted_langs = sorted(
        list({x for lang_pair in args.lang_pairs for x in lang_pair.split("-")})
    )
    if args.source_lang is not None or args.target_lang is not None:
        training = False
    else:
        training = True

    # load dictionaries
    dicts = OrderedDict()
    for lang in sorted_langs:
        paths = args.data.split(os.pathsep)
        assert len(paths) > 0
        dicts[lang] = Dictionary.load(
            os.path.join(paths[0], "dict.{}.txt".format(lang))
        )
        if len(dicts) > 0:
            assert dicts[lang].pad() == dicts[sorted_langs[0]].pad()
            assert dicts[lang].eos() == dicts[sorted_langs[0]].eos()
            assert dicts[lang].unk() == dicts[sorted_langs[0]].unk()
        if args.encoder_langtok is not None or args.decoder_langtok:
            for lang_to_add in sorted_langs:
                dicts[lang].add_symbol(_lang_token(lang_to_add))
        print("| [{}] dictionary: {} types".format(lang, len(dicts[lang])))
    return dicts, training


# Traceback (TypeError)
/experiments/falva/tools/fairseq/fairseq/models/fairseq_model.py:280: UserWarning: FairseqModel is deprecated, please use FairseqEncoderDecoderModel or BaseFairseqModel instead
for key in self.keys
Traceback (most recent call last):
File "/home/falva/anaconda3/envs/mtl4ts/bin/fairseq-generate", line 11, in <module>
load_entry_point('fairseq', 'console_scripts', 'fairseq-generate')()
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 190, in cli_main
main(args)
File "/experiments/falva/tools/fairseq/fairseq_cli/generate.py", line 47, in main
task=task,
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 167, in load_model_ensemble
ensemble, args, _task = load_model_ensemble_and_task(filenames, arg_overrides, task)
File "/experiments/falva/tools/fairseq/fairseq/checkpoint_utils.py", line 186, in load_model_ensemble_and_task
model.load_state_dict(state['model'], strict=True, args=args)
TypeError: load_state_dict() got an unexpected keyword argument 'args'

# Fixed code
def prepare(cls, args, **kargs):
    args.left_pad_source = options.eval_bool(args.left_pad_source)
    args.left_pad_target = options.eval_bool(args.left_pad_target)

    if args.lang_pairs is None:
        raise ValueError(
            "--lang-pairs is required. List all the language pairs in the training objective."
        )
    if isinstance(args.lang_pairs, str):
        args.lang_pairs = args.lang_pairs.split(",")
    sorted_langs = sorted(
        list({x for lang_pair in args.lang_pairs for x in lang_pair.split("-")})
    )
    if args.source_lang is not None or args.target_lang is not None:
        training = False
    else:
        training = True

    # load dictionaries
    dicts = OrderedDict()
    for lang in sorted_langs:
        paths = args.data.split(os.pathsep)
        assert len(paths) > 0
        dicts[lang] = Dictionary.load(
            os.path.join(paths[0], "dict.{}.txt".format(lang))
        )
        if len(dicts) > 0:
            assert dicts[lang].pad() == dicts[sorted_langs[0]].pad()
            assert dicts[lang].eos() == dicts[sorted_langs[0]].eos()
            assert dicts[lang].unk() == dicts[sorted_langs[0]].unk()
        if args.encoder_langtok is not None or args.decoder_langtok:
            for lang_to_add in sorted_langs:
                dicts[lang].add_symbol(_lang_token(lang_to_add))
        print("| [{}] dictionary: {} types".format(lang, len(dicts[lang])))
    return dicts, training