From 67f495454c23aec6a6e34ee7faa5d1285095c95b Mon Sep 17 00:00:00 2001 From: Disty0 Date: Thu, 6 Mar 2025 22:55:03 +0300 Subject: [PATCH] IPEX fix torch.cuda.device --- modules/intel/ipex/hijacks.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/intel/ipex/hijacks.py b/modules/intel/ipex/hijacks.py index 5191e324a..cdce4d073 100644 --- a/modules/intel/ipex/hijacks.py +++ b/modules/intel/ipex/hijacks.py @@ -343,6 +343,13 @@ def torch_cuda_synchronize(device=None): else: return torch.xpu.synchronize(device) +@wraps(torch.cuda.device) +def torch_cuda_device(device): + if check_cuda(device): + return torch.xpu.device(return_xpu(device)) + else: + return torch.xpu.device(device) + # Hijack Functions: def ipex_hijacks(legacy=True): @@ -367,6 +374,7 @@ def ipex_hijacks(legacy=True): torch.load = torch_load torch.Generator = torch_Generator torch.cuda.synchronize = torch_cuda_synchronize + torch.cuda.device = torch_cuda_device torch.backends.cuda.sdp_kernel = return_null_context torch.nn.DataParallel = DummyDataParallel