From c0c7ec3458f95f41c82737b14cd2637c06bca2e3 Mon Sep 17 00:00:00 2001 From: Davide Fiocco Date: Tue, 3 Mar 2020 14:59:47 +0100 Subject: [PATCH] Don't crash if fine-tuned model doesn't end with a number (#3099) That's the same fix applied in https://github.com/huggingface/transformers/issues/2258 , but for the GLUE example --- examples/run_glue.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/run_glue.py b/examples/run_glue.py index f5bbde9031..57d1c56ac1 100644 --- a/examples/run_glue.py +++ b/examples/run_glue.py @@ -183,8 +183,11 @@ def train(args, train_dataset, model, tokenizer): steps_trained_in_current_epoch = 0 # Check if continuing training from a checkpoint if os.path.exists(args.model_name_or_path): - # set global_step to gobal_step of last saved checkpoint from model path - global_step = int(args.model_name_or_path.split("-")[-1].split("/")[0]) + # set global_step to global_step of last saved checkpoint from model path + try: + global_step = int(args.model_name_or_path.split("-")[-1].split("/")[0]) + except ValueError: + global_step = 0 epochs_trained = global_step // (len(train_dataloader) // args.gradient_accumulation_steps) steps_trained_in_current_epoch = global_step % (len(train_dataloader) // args.gradient_accumulation_steps)