From 64326dccfba46890edc93b5bf7be6974b71984d5 Mon Sep 17 00:00:00 2001 From: Sang-Kil Park Date: Thu, 10 Jan 2019 21:51:39 +0900 Subject: [PATCH] Fix it to run properly even if without `--do_train` param. It was modified similar to `run_classifier.py`, and Fixed to run properly even if without `--do_train` param. --- examples/run_squad.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/run_squad.py b/examples/run_squad.py index 245aee0ff2..39e9c50199 100644 --- a/examples/run_squad.py +++ b/examples/run_squad.py @@ -782,7 +782,7 @@ def main(): raise ValueError( "If `do_predict` is True, then `predict_file` must be specified.") - if os.path.exists(args.output_dir) and os.listdir(args.output_dir): + if os.path.exists(args.output_dir) and os.listdir(args.output_dir) and args.do_train: raise ValueError("Output directory () already exists and is not empty.") os.makedirs(args.output_dir, exist_ok=True) @@ -916,7 +916,8 @@ def main(): # Save a trained model model_to_save = model.module if hasattr(model, 'module') else model # Only save the model it-self output_model_file = os.path.join(args.output_dir, "pytorch_model.bin") - torch.save(model_to_save.state_dict(), output_model_file) + if args.do_train: + torch.save(model_to_save.state_dict(), output_model_file) # Load a trained model that you have fine-tuned model_state_dict = torch.load(output_model_file)