From a54b2ca1850d96e7c1a01201a130a36788ad0a49 Mon Sep 17 00:00:00 2001 From: younesbelkada Date: Tue, 30 Jan 2024 09:24:17 +0000 Subject: [PATCH 1/3] fix --- src/peft/utils/save_and_load.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/peft/utils/save_and_load.py b/src/peft/utils/save_and_load.py index 2c91c03fe3..d0c901028d 100644 --- a/src/peft/utils/save_and_load.py +++ b/src/peft/utils/save_and_load.py @@ -18,7 +18,7 @@ import torch from huggingface_hub import file_exists, hf_hub_download -from huggingface_hub.utils import EntryNotFoundError +from huggingface_hub.utils import EntryNotFoundError, HFValidationError from safetensors.torch import load_file as safe_load_file from .other import EMBEDDING_LAYER_NAMES, SAFETENSORS_WEIGHTS_NAME, WEIGHTS_NAME, infer_device @@ -136,8 +136,27 @@ def get_peft_model_state_dict( elif save_embedding_layers == "auto": vocab_size = getattr(getattr(model, "config", None), "vocab_size", None) model_id = getattr(config, "base_model_name_or_path", None) + + # For some models e.g. diffusers the text config file is stored in a subfolder + # we need to make sure we can donwload that config. + has_remote_config = False + + if model_id is not None: + try: + has_remote_config = file_exists(model_id, "config.jon") + except (HFValidationError, EntryNotFoundError): + warnings.warn( + f"Could not find a config file in {model_id} - will assume that the vocabulary was not modified." + ) + has_remote_config = False + # check if the vocab size of the base model is different from the vocab size of the finetuned model - if vocab_size and model_id and (vocab_size != model.config.__class__.from_pretrained(model_id).vocab_size): + if ( + vocab_size + and model_id + and has_remote_config + and (vocab_size != model.config.__class__.from_pretrained(model_id).vocab_size) + ): warnings.warn( "Setting `save_embedding_layers` to `True` as the embedding layer has been resized during finetuning." ) From f9bb7d3acaf71ea5f1a0dfdaa139df8b0708d4ec Mon Sep 17 00:00:00 2001 From: Younes Belkada <49240599+younesbelkada@users.noreply.github.com> Date: Tue, 30 Jan 2024 10:29:35 +0100 Subject: [PATCH 2/3] Update src/peft/utils/save_and_load.py --- src/peft/utils/save_and_load.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/peft/utils/save_and_load.py b/src/peft/utils/save_and_load.py index d0c901028d..f35000df35 100644 --- a/src/peft/utils/save_and_load.py +++ b/src/peft/utils/save_and_load.py @@ -143,7 +143,7 @@ def get_peft_model_state_dict( if model_id is not None: try: - has_remote_config = file_exists(model_id, "config.jon") + has_remote_config = file_exists(model_id, "config.json") except (HFValidationError, EntryNotFoundError): warnings.warn( f"Could not find a config file in {model_id} - will assume that the vocabulary was not modified." From 06a55dc444a97667e358464524096e6e5d69f7c9 Mon Sep 17 00:00:00 2001 From: Younes Belkada <49240599+younesbelkada@users.noreply.github.com> Date: Tue, 30 Jan 2024 10:29:39 +0100 Subject: [PATCH 3/3] Update src/peft/utils/save_and_load.py --- src/peft/utils/save_and_load.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/peft/utils/save_and_load.py b/src/peft/utils/save_and_load.py index f35000df35..445bcf8c25 100644 --- a/src/peft/utils/save_and_load.py +++ b/src/peft/utils/save_and_load.py @@ -138,7 +138,7 @@ def get_peft_model_state_dict( model_id = getattr(config, "base_model_name_or_path", None) # For some models e.g. diffusers the text config file is stored in a subfolder - # we need to make sure we can donwload that config. + # we need to make sure we can download that config. has_remote_config = False if model_id is not None: