From 98a1e16f57158c89da5d993bcf6e00fecd678aa2 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Sun, 29 Sep 2024 23:13:44 -0700 Subject: [PATCH] Update loader.py --- unsloth/models/loader.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index 0ac9b02743..2a89c06c21 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -23,6 +23,7 @@ from peft import PeftConfig, PeftModel from .mapper import INT_TO_FLOAT_MAPPER, FLOAT_TO_INT_MAPPER, MAP_TO_UNSLOTH_16bit import os from huggingface_hub.utils._token import get_token +from huggingface_hub import HfFileSystem # https://github.com/huggingface/transformers/pull/26037 allows 4 bit loading! from packaging.version import Version @@ -191,14 +192,28 @@ class FastLanguageModel(FastLlamaModel): is_peft = False pass - # Cannot be both! - if (is_model and is_peft) and not SUPPORTS_LLAMA32: + # Both config.json and adapter_config.json should not exist! + + # Old transformers versions check + both_exist = (is_model and is_peft) and not SUPPORTS_LLAMA32 + + if SUPPORTS_LLAMA32: + # New transformers need to check manually. + files = HfFileSystem(token = token).glob(os.path.join(model_name, "*.json")) + if sum(x.endswith(("adapter_config.json", "config.json")) for x in files) >= 2: + both_exist = True + pass + pass + + # Error out if both LoRA and normal model config exists. + if both_exist: raise RuntimeError( "Unsloth: Your repo has a LoRA adapter and a base model.\n"\ "You have 2 files `config.json` and `adapter_config.json`.\n"\ "We must only allow one config file.\n"\ "Please separate the LoRA and base models to 2 repos." ) + elif not is_model and not is_peft: error = autoconfig_error or peft_error # Old transformers version