From 523dbaf8dcf32ff05155e9af4627789695ee2899 Mon Sep 17 00:00:00 2001 From: Vince Navarro Date: Thu, 1 Jun 2023 16:42:21 -0400 Subject: [PATCH 1/2] Add XPU support for --device-id --- modules/devices.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/devices.py b/modules/devices.py index b49745bd3..de35d0066 100644 --- a/modules/devices.py +++ b/modules/devices.py @@ -24,6 +24,8 @@ def extract_device_id(args, name): # pylint: disable=redefined-outer-name def get_cuda_device_string(): if shared.cmd_opts.use_ipex: + if shared.cmd_opts.device_id is not None: + return f"xpu:{shared.cmd_opts.device_id}" return "xpu" else: if shared.cmd_opts.device_id is not None: @@ -33,7 +35,7 @@ def get_cuda_device_string(): def get_optimal_device_name(): if shared.cmd_opts.use_ipex: - return "xpu" + return get_cuda_device_string() elif cuda_ok and not shared.cmd_opts.use_directml: return get_cuda_device_string() if has_mps(): @@ -66,7 +68,7 @@ def torch_gc(force=False): collected = gc.collect() if shared.cmd_opts.use_ipex: try: - with torch.xpu.device("xpu"): + with torch.xpu.device(get_cuda_device_string()): torch.xpu.empty_cache() except: pass @@ -143,7 +145,11 @@ def set_cuda_params(): args = cmd_args.parser.parse_args() if args.use_ipex: - cpu = torch.device("xpu") #Use XPU instead of CPU. %20 Perf improvement on weak CPUs. + print(args.device_id) + if args.device_id is not None: + cpu = torch.device(f"xpu:{args.device_id}") #Use XPU instead of CPU. %20 Perf improvement on weak CPUs. + else: + cpu = torch.device("xpu") else: cpu = torch.device("cpu") device = device_interrogate = device_gfpgan = device_esrgan = device_codeformer = None From c30eb90afff5759d25834c1978ea647d1cd6beb1 Mon Sep 17 00:00:00 2001 From: Vince Navarro Date: Thu, 1 Jun 2023 17:28:13 -0400 Subject: [PATCH 2/2] Remove stray print --- modules/devices.py | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/devices.py b/modules/devices.py index de35d0066..f633400a4 100644 --- a/modules/devices.py +++ b/modules/devices.py @@ -145,7 +145,6 @@ def set_cuda_params(): args = cmd_args.parser.parse_args() if args.use_ipex: - print(args.device_id) if args.device_id is not None: cpu = torch.device(f"xpu:{args.device_id}") #Use XPU instead of CPU. %20 Perf improvement on weak CPUs. else: