Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,9 @@ def collate_fn(examples):
if args.push_to_hub:
repo.push_to_hub(commit_message="End of training", auto_lfs_prune=True)

if args.output_dir is not None:
with open(os.path.join(args.output_dir, "all_results.json"), "w") as f:
json.dump({"eval_accuracy": eval_metric["accuracy"]}, f)
all_results = {f"eval_{k}": v for k, v in eval_metric.items()}
with open(os.path.join(args.output_dir, "all_results.json"), "w") as f:
json.dump(all_results, f)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/pytorch/language-modeling/run_clm_no_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,8 @@ def group_texts(examples):
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({"perplexity": perplexity}, f)
with open(os.path.join(args.output_dir, "all_results.json"), "w") as f:
json.dump({"perplexity": perplexity}, f)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/pytorch/language-modeling/run_mlm_no_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,8 @@ def group_texts(examples):
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({"perplexity": perplexity}, f)
with open(os.path.join(args.output_dir, "all_results.json"), "w") as f:
json.dump({"perplexity": perplexity}, f)


if __name__ == "__main__":
Expand Down
10 changes: 6 additions & 4 deletions examples/pytorch/multiple-choice/run_swag_no_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def parse_args():
"--validation_file", type=str, default=None, help="A csv or a json file containing the validation data."
)
parser.add_argument(
"--max_length",
"--max_seq_length",
type=int,
default=128,
help=(
Expand Down Expand Up @@ -424,7 +424,7 @@ def preprocess_function(examples):
tokenized_examples = tokenizer(
first_sentences,
second_sentences,
max_length=args.max_length,
max_length=args.max_seq_length,
padding=padding,
truncation=True,
)
Expand Down Expand Up @@ -654,8 +654,10 @@ def preprocess_function(examples):
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_accuracy": eval_metric["accuracy"]}, f)

all_results = {f"eval_{k}": v for k, v in eval_metric.items()}
with open(os.path.join(args.output_dir, "all_results.json"), "w") as f:
json.dump(all_results, f)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,9 @@ def preprocess_val(example_batch):
if args.push_to_hub:
repo.push_to_hub(commit_message="End of training", auto_lfs_prune=True)

all_results = {f"eval_{k}": v for k, v in eval_metrics.items()}
with open(os.path.join(args.output_dir, "all_results.json"), "w") as f:
json.dump({"eval_overall_accuracy": eval_metrics["overall_accuracy"]}, f)
json.dump(all_results, f)


if __name__ == "__main__":
Expand Down
14 changes: 4 additions & 10 deletions examples/pytorch/summarization/run_summarization_no_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,16 +747,10 @@ def postprocess_text(preds, labels):
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,
)

all_results = {f"eval_{k}": v for k, v in result.items()}
with open(os.path.join(args.output_dir, "all_results.json"), "w") as f:
json.dump(all_results, f)


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion examples/pytorch/text-classification/run_glue_no_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,9 @@ def preprocess_function(examples):
logger.info(f"mnli-mm: {eval_metric}")

if args.output_dir is not None:
all_results = {f"eval_{k}": v for k, v in eval_metric.items()}
with open(os.path.join(args.output_dir, "all_results.json"), "w") as f:
json.dump({"eval_accuracy": eval_metric["accuracy"]}, f)
json.dump(all_results, f)


if __name__ == "__main__":
Expand Down
9 changes: 5 additions & 4 deletions examples/pytorch/token-classification/run_ner_no_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,11 @@ def compute_metrics():
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_accuracy": eval_metric["accuracy"], "train_loss": total_loss.item() / len(train_dataloader)}, f
)
all_results = {f"eval_{k}": v for k, v in eval_metric.items()}
if args.with_tracking:
all_results.update({"train_loss": total_loss.item() / len(train_dataloader)})
with open(os.path.join(args.output_dir, "all_results.json"), "w") as f:
json.dump(all_results, f)


if __name__ == "__main__":
Expand Down