Bitsandbytes: load preconverted 4bit models without additional flags

This commit is contained in:
oobabooga 2024-04-04 18:09:34 -07:00
parent d423021a48
commit 308452b783

View File

@ -145,17 +145,18 @@ def huggingface_loader(model_name):
else: else:
LoaderClass = AutoModelForCausalLM LoaderClass = AutoModelForCausalLM
# Load the model in simple 16-bit mode by default # Load the model without any special settings
if not any([shared.args.cpu, shared.args.load_in_8bit, shared.args.load_in_4bit, shared.args.auto_devices, shared.args.disk, shared.args.deepspeed, shared.args.gpu_memory is not None, shared.args.cpu_memory is not None, shared.args.compress_pos_emb > 1, shared.args.alpha_value > 1, shared.args.disable_exllama, shared.args.disable_exllamav2]): if not any([shared.args.cpu, shared.args.load_in_8bit, shared.args.load_in_4bit, shared.args.auto_devices, shared.args.disk, shared.args.deepspeed, shared.args.gpu_memory is not None, shared.args.cpu_memory is not None, shared.args.compress_pos_emb > 1, shared.args.alpha_value > 1, shared.args.disable_exllama, shared.args.disable_exllamav2]):
model = LoaderClass.from_pretrained(path_to_model, **params) model = LoaderClass.from_pretrained(path_to_model, **params)
if torch.backends.mps.is_available(): if not (hasattr(model, 'is_loaded_in_4bit') and model.is_loaded_in_4bit):
device = torch.device('mps') if torch.backends.mps.is_available():
model = model.to(device) device = torch.device('mps')
elif is_xpu_available(): model = model.to(device)
device = torch.device("xpu") elif is_xpu_available():
model = model.to(device) device = torch.device("xpu")
else: model = model.to(device)
model = model.cuda() else:
model = model.cuda()
# DeepSpeed ZeRO-3 # DeepSpeed ZeRO-3
elif shared.args.deepspeed: elif shared.args.deepspeed: