fix TypeError: TrainingArguments.__init__() got an unexpected keyword argument 'evaluation_strategy'

#539
by jackkuo - opened

Due to the update of transformer, evaluation_strategy is now eval_strategy in the new version. The author ctheodoris has made corresponding modifications to this file [in: https://huggingface.co/ctheodoris/Geneformer/discussions/531#6822ed18c442885b1dcbf70a ], but the modification still has problems. The reasons are as follows: the original def_training_args dictionary is referenced from the classifier_utils.py file, which has already preset evaluation_strategy as the key, so the original modification in classifier.py here is incorrect:

if eval_data is None:
    if transformers_version >= parse("4.46"):
        def_training_args["eval_strategy"] = "no"
    else:
        def_training_args["evaluation_strategy"] = "no"
    def_training_args["load_best_model_at_end"] = False 

will still retain the evaluation_strategy field. The new modification can solve this problem through def_training_args["eval_strategy"] = def_training_args.pop("evaluation_strategy"):

if eval_data is None:
    def_training_args["evaluation_strategy"] = "no"
    def_training_args["load_best_model_at_end"] = False
if transformers_version >= parse("4.46"):
    def_training_args["eval_strategy"] = def_training_args.pop("evaluation_strategy")

Thank you for the fix!

ctheodoris changed pull request status to merged

Sign up or log in to comment