Update loader.py

This commit is contained in:
Daniel Han 2024-09-29 23:13:44 -07:00
commit 98a1e16f57

View file

@ -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