From 902dd0ab472a4c1e22b82827a48ebc4029a139d8 Mon Sep 17 00:00:00 2001 From: Wing Lian Date: Fri, 14 Apr 2023 23:57:55 -0400 Subject: [PATCH] fix issue with completed model being empty see https://github.com/huggingface/peft/issues/286#issuecomment-1501617281 --- scripts/finetune.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/scripts/finetune.py b/scripts/finetune.py index 33d3f1a51..090f8099e 100644 --- a/scripts/finetune.py +++ b/scripts/finetune.py @@ -369,22 +369,18 @@ def train( ) model.config.use_cache = False - old_state_dict = model.state_dict - model.state_dict = ( - lambda self, *_, **__: get_peft_model_state_dict(self, old_state_dict()) - ).__get__(model, type(model)) - if torch.__version__ >= "2" and sys.platform != "win32": model = torch.compile(model) + # go ahead and presave, so we have the adapter config available to inspect + lora_config.save_pretrained(cfg.output_dir) + # In case we want to stop early with ctrl+c, this is a nice to have to save the pretrained model signal.signal( signal.SIGINT, lambda signal, frame: (model.save_pretrained(cfg.output_dir), exit(0)), ) - # go ahead and presave the adapter config - lora_config.save_pretrained(cfg.output_dir) trainer.train(resume_from_checkpoint=cfg.resume_from_checkpoint) model.save_pretrained(cfg.output_dir)