I want to use the trainer over 5 folds. I wanted to add EarlyStoppingCallback to the trainer function to make it stop if the training is not improving. I get this error
AssertionError: EarlyStoppingCallback requires load_best_model_at_end = True
The following is the code I used:
training_args = Seq2SeqTrainingArguments(
output_dir="./logs",
evaluation_strategy="epoch",
logging_strategy="epoch",
learning_rate=2e-5,
per_device_train_batch_size=16,
per_device_eval_batch_size=16,
weight_decay=0.01,
num_train_epochs=5,
save_total_limit=2,
save_strategy="epoch",
load_best_model_at_end=True,
predict_with_generate=True,
fp16=False,
push_to_hub=False,
)
for train_dataset, val_dataset in zip(train_ds, val_ds):
trainer = Seq2SeqTrainer(
model=model,
args=training_args,
train_dataset=train_dataset,
eval_dataset=val_dataset,
tokenizer=tokenizer,
data_collator=data_collator,
compute_metrics=compute_metrics,
callbacks=[
CombinedTensorBoardCallback,
EarlyStoppingCallback(early_stopping_patience=3),
],
)
train_result = trainer.train()
why i can’t use EarlyStoppingCallback and load_best_model_at_end=False? I just want to save the best model at the level of each fold.
Another question: is there a way to save the best model among the 5 folds?