Add tests for no_trainer and fix existing examples (#16656)
* Fixed some bugs involving saving during epochs * Added tests mimicking the existing examples tests * Added in json exporting to all `no_trainer` examples for consistency
This commit is contained in:
@@ -19,6 +19,7 @@ Fine-tuning a 🤗 Transformers model on summarization.
|
||||
# You can also adapt this script on your own summarization task. Pointers for this are left as comments.
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import logging
|
||||
import math
|
||||
import os
|
||||
@@ -602,7 +603,10 @@ def main():
|
||||
|
||||
if isinstance(checkpointing_steps, int):
|
||||
if completed_steps % checkpointing_steps == 0:
|
||||
accelerator.save_state(f"step_{completed_steps}")
|
||||
output_dir = f"step_{completed_steps}"
|
||||
if args.output_dir is not None:
|
||||
output_dir = os.path.join(args.output_dir, output_dir)
|
||||
accelerator.save_state(output_dir)
|
||||
|
||||
if completed_steps >= args.max_train_steps:
|
||||
break
|
||||
@@ -669,7 +673,10 @@ def main():
|
||||
)
|
||||
|
||||
if args.checkpointing_steps == "epoch":
|
||||
accelerator.save_state(f"epoch_{epoch}")
|
||||
output_dir = f"epoch_{epoch}"
|
||||
if args.output_dir is not None:
|
||||
output_dir = os.path.join(args.output_dir, output_dir)
|
||||
accelerator.save_state(output_dir)
|
||||
|
||||
if args.output_dir is not None:
|
||||
accelerator.wait_for_everyone()
|
||||
@@ -679,6 +686,16 @@ def main():
|
||||
tokenizer.save_pretrained(args.output_dir)
|
||||
if args.push_to_hub:
|
||||
repo.push_to_hub(commit_message="End of training", auto_lfs_prune=True)
|
||||
with open(os.path.join(args.output_dir, "all_results.json"), "w") as f:
|
||||
json.dump(
|
||||
{
|
||||
"eval_rouge1": result["rouge1"],
|
||||
"eval_rouge2": result["rouge2"],
|
||||
"eval_rougeL": result["rougeL"],
|
||||
"eval_rougeLsum": result["rougeLsum"],
|
||||
},
|
||||
f,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user