From ab470444591e425290db72db9ebc3127f5520449 Mon Sep 17 00:00:00 2001 From: deepdiffuser Date: Fri, 10 Mar 2023 04:29:09 -0800 Subject: [PATCH 1/3] add multi-gpu support for 4bit gptq LLaMA --- modules/models.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/models.py b/modules/models.py index 3e6cea18..14443c89 100644 --- a/modules/models.py +++ b/modules/models.py @@ -110,7 +110,18 @@ def load_model(model_name): exit() model = load_quant(path_to_model, Path(f"models/{pt_model}"), 4) - model = model.to(torch.device('cuda:0')) + + if shared.args.gpu_memory: + max_memory = {} + for i in range(len(shared.args.gpu_memory)): + max_memory[i] = f"{shared.args.gpu_memory[i]}GiB" + max_memory['cpu'] = f"{shared.args.cpu_memory or '99'}GiB" + + import accelerate + device_map = accelerate.infer_auto_device_map(model, max_memory=max_memory) + model = accelerate.dispatch_model(model, device_map=device_map) + else: + model = model.to(torch.device('cuda:0')) # Custom else: From 9fbd60bf22c6a2e9cef0cade23a4933547df9114 Mon Sep 17 00:00:00 2001 From: deepdiffuser Date: Fri, 10 Mar 2023 05:30:47 -0800 Subject: [PATCH 2/3] add no_split_module_classes to prevent tensor split error --- modules/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/models.py b/modules/models.py index 14443c89..986cd73a 100644 --- a/modules/models.py +++ b/modules/models.py @@ -118,7 +118,7 @@ def load_model(model_name): max_memory['cpu'] = f"{shared.args.cpu_memory or '99'}GiB" import accelerate - device_map = accelerate.infer_auto_device_map(model, max_memory=max_memory) + device_map = accelerate.infer_auto_device_map(model, max_memory=max_memory, no_split_module_classes=["LLaMADecoderLayer"]) model = accelerate.dispatch_model(model, device_map=device_map) else: model = model.to(torch.device('cuda:0')) From e461c0b7a0769c4df3aa96505803b004a1071c2e Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Fri, 10 Mar 2023 10:51:12 -0300 Subject: [PATCH 3/3] Move the import to the top --- modules/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/models.py b/modules/models.py index 986cd73a..f4c1071d 100644 --- a/modules/models.py +++ b/modules/models.py @@ -112,12 +112,13 @@ def load_model(model_name): model = load_quant(path_to_model, Path(f"models/{pt_model}"), 4) if shared.args.gpu_memory: + import accelerate + max_memory = {} for i in range(len(shared.args.gpu_memory)): max_memory[i] = f"{shared.args.gpu_memory[i]}GiB" max_memory['cpu'] = f"{shared.args.cpu_memory or '99'}GiB" - import accelerate device_map = accelerate.infer_auto_device_map(model, max_memory=max_memory, no_split_module_classes=["LLaMADecoderLayer"]) model = accelerate.dispatch_model(model, device_map=device_map) else: