iTranslated by AI
Model Evaluation and Saving Strategies for Transformers Trainer (evaluation_strategy/save_strategy)
Trainer is one of the classes provided by the huggingface/transformers library, which includes an API for compactly describing model training written in PyTorch.
When initializing the Trainer class, fine-grained adjustments to training settings are possible by providing TrainingArguments—a collection of various training configuration values—as an argument.
Among the various code examples provided by Hugging Face, most training code that does not end in no_trainer uses an implementation method where arguments are aggregated into TrainingArguments and passed to the Trainer class.
Among these, I have summarized evaluation_strategy and save_strategy, as they are parameters I personally find important—or rather, ones I find myself looking up and reminding myself of repeatedly.
evaluation_strategy
Specifies the strategy for validation using a validation set.
By default, this is set to "no", meaning it is not performed.
--evaluation_strategy steps
If set to the above, validation is performed every number of steps specified by eval_steps. Since eval_steps defaults to None, you need to specify a value.
--evaluation_strategy epoch
If set to the above, validation is performed at the end of each epoch.
save_strategy
Specifies the strategy for saving the model.
The default is "steps". This means the model is saved every number of steps specified by save_steps. save_steps defaults to 500.
--save_strategy epoch
If set to the above, the model is saved at the end of each epoch.
--save_strategy no
If set to the above, the model will not be saved.
Additionally, using the --load_best_model_at_end option is convenient, as it saves the model that achieved the best evaluation score as the final version at the end.
Discussion