|
@@ -9,6 +9,7 @@ import modules.shared as shared
|
|
|
|
|
|
|
|
sys.path.insert(0, str(Path("repositories/GPTQ-for-LLaMa")))
|
|
sys.path.insert(0, str(Path("repositories/GPTQ-for-LLaMa")))
|
|
|
import llama
|
|
import llama
|
|
|
|
|
+import llama_inference_offload
|
|
|
import opt
|
|
import opt
|
|
|
|
|
|
|
|
|
|
|
|
@@ -24,7 +25,10 @@ def load_quantized(model_name):
|
|
|
model_type = shared.args.gptq_model_type.lower()
|
|
model_type = shared.args.gptq_model_type.lower()
|
|
|
|
|
|
|
|
if model_type == 'llama':
|
|
if model_type == 'llama':
|
|
|
- load_quant = llama.load_quant
|
|
|
|
|
|
|
+ if not shared.args.gptq_pre_layer:
|
|
|
|
|
+ load_quant = llama.load_quant
|
|
|
|
|
+ else:
|
|
|
|
|
+ load_quant = llama_inference_offload.load_quant
|
|
|
elif model_type == 'opt':
|
|
elif model_type == 'opt':
|
|
|
load_quant = opt.load_quant
|
|
load_quant = opt.load_quant
|
|
|
else:
|
|
else:
|
|
@@ -53,24 +57,26 @@ def load_quantized(model_name):
|
|
|
print(f"Could not find {pt_model}, exiting...")
|
|
print(f"Could not find {pt_model}, exiting...")
|
|
|
exit()
|
|
exit()
|
|
|
|
|
|
|
|
- model = load_quant(str(path_to_model), str(pt_path), shared.args.gptq_bits)
|
|
|
|
|
-
|
|
|
|
|
- # Multiple GPUs or GPU+CPU
|
|
|
|
|
- if shared.args.gpu_memory:
|
|
|
|
|
- memory_map = list(map(lambda x : x.strip(), shared.args.gpu_memory))
|
|
|
|
|
- max_cpu_memory = shared.args.cpu_memory.strip() if shared.args.cpu_memory is not None else '99GiB'
|
|
|
|
|
- max_memory = {}
|
|
|
|
|
- for i in range(len(memory_map)):
|
|
|
|
|
- max_memory[i] = f'{memory_map[i]}GiB' if not re.match('.*ib$', memory_map[i].lower()) else memory_map[i]
|
|
|
|
|
- max_memory['cpu'] = max_cpu_memory
|
|
|
|
|
|
|
+ # Using qwopqwop200's offload
|
|
|
|
|
+ if shared.args.gptq_pre_layer:
|
|
|
|
|
+ model = load_quant(str(path_to_model), str(pt_path), shared.args.gptq_bits, shared.args.gptq_pre_layer)
|
|
|
|
|
+ else:
|
|
|
|
|
+ model = load_quant(str(path_to_model), str(pt_path), shared.args.gptq_bits)
|
|
|
|
|
|
|
|
- device_map = accelerate.infer_auto_device_map(model, max_memory=max_memory, no_split_module_classes=["LlamaDecoderLayer"])
|
|
|
|
|
- print("Using the following device map for the 4-bit model:", device_map)
|
|
|
|
|
- # https://huggingface.co/docs/accelerate/package_reference/big_modeling#accelerate.dispatch_model
|
|
|
|
|
- model = accelerate.dispatch_model(model, device_map=device_map, offload_buffers=True)
|
|
|
|
|
|
|
+ # Using accelerate offload (doesn't work properly)
|
|
|
|
|
+ if shared.args.gpu_memory:
|
|
|
|
|
+ memory_map = list(map(lambda x : x.strip(), shared.args.gpu_memory))
|
|
|
|
|
+ max_cpu_memory = shared.args.cpu_memory.strip() if shared.args.cpu_memory is not None else '99GiB'
|
|
|
|
|
+ max_memory = {}
|
|
|
|
|
+ for i in range(len(memory_map)):
|
|
|
|
|
+ max_memory[i] = f'{memory_map[i]}GiB' if not re.match('.*ib$', memory_map[i].lower()) else memory_map[i]
|
|
|
|
|
+ max_memory['cpu'] = max_cpu_memory
|
|
|
|
|
|
|
|
- # Single GPU
|
|
|
|
|
- elif not shared.args.cpu:
|
|
|
|
|
- model = model.to(torch.device('cuda:0'))
|
|
|
|
|
|
|
+ device_map = accelerate.infer_auto_device_map(model, max_memory=max_memory, no_split_module_classes=["LlamaDecoderLayer"])
|
|
|
|
|
+ print("Using the following device map for the 4-bit model:", device_map)
|
|
|
|
|
+ # https://huggingface.co/docs/accelerate/package_reference/big_modeling#accelerate.dispatch_model
|
|
|
|
|
+ model = accelerate.dispatch_model(model, device_map=device_map, offload_buffers=True)
|
|
|
|
|
+ elif not shared.args.cpu:
|
|
|
|
|
+ model = model.to(torch.device('cuda:0'))
|
|
|
|
|
|
|
|
return model
|
|
return model
|