From 01f668d4bd0d0a8127b6c19ebb1bde8790f13ad2 Mon Sep 17 00:00:00 2001 From: Sylvain Gugger Date: Thu, 4 Mar 2021 09:46:37 -0500 Subject: [PATCH] Not always consider a local model a checkpoint in run_glue --- examples/text-classification/run_glue.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/text-classification/run_glue.py b/examples/text-classification/run_glue.py index cc8ea89f052..28a33091f74 100755 --- a/examples/text-classification/run_glue.py +++ b/examples/text-classification/run_glue.py @@ -406,12 +406,15 @@ def compute_metrics(p: EvalPrediction): # Training if training_args.do_train: + checkpoint = None if last_checkpoint is not None: checkpoint = last_checkpoint elif os.path.isdir(model_args.model_name_or_path): - checkpoint = model_args.model_name_or_path - else: - checkpoint = None + # Check the config from that potential checkpoint has the right number of labels before using it as a + # checkpoint. + if AutoConfig.from_pretrained(model_args.model_name_or_path).num_labels == num_labels: + checkpoint = model_args.model_name_or_path + train_result = trainer.train(resume_from_checkpoint=checkpoint) metrics = train_result.metrics