From cc56718a7e191d5acc6d3a7109ae0c169f46d044 Mon Sep 17 00:00:00 2001 From: Gnome Ann <> Date: Sun, 19 Jun 2022 00:29:35 -0400 Subject: [PATCH] Fix lazy loader putting too many layers on CPU --- aiserver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiserver.py b/aiserver.py index 36924482..868a5755 100644 --- a/aiserver.py +++ b/aiserver.py @@ -1686,7 +1686,7 @@ def load_model(use_gpu=True, gpu_layers=None, initial_load=False, online_model=" if isinstance(value, torch_lazy_loader.LazyTensor) and not any(key.startswith(n) or key.startswith(n.split(".", 1)[1]) for n in vars.layers_module_names): device_map[key] = vars.gpu_device if vars.hascuda and vars.usegpu else "cpu" else: - layer = int(next(n for n in vars.layers_module_names if key.startswith(n) or key.startswith(n.split(".", 1)[1])).rsplit(".", 1)[1]) + layer = int(max((n for n in vars.layers_module_names if key.startswith(n) or key.startswith(n.split(".", 1)[1])), key=len).rsplit(".", 1)[1]) device = vars.gpu_device if vars.hascuda and vars.usegpu else "cpu" if not vars.hascuda or not vars.breakmodel or layer < ram_blocks else bisect.bisect_right(cumulative_gpu_blocks, layer - ram_blocks) device_map[key] = device