From fc7c07007fe341bf6d78a9126d0cb5a914ce28fd Mon Sep 17 00:00:00 2001 From: keiwoo Date: Sat, 14 Dec 2024 08:41:43 +0800 Subject: [PATCH] Update real_accelerator.py (#6845) ### Comment out or delete `accelerate_name="cpu"` when `xpu` is not detected. When `xpu `is not detected it just pass at lines from 68 to 74 if `DS_ACCELERATOR` is set. However, `cpu` is assigned to `accelerate_name` if it cannot import `intel_extension_for_pytorch` or find` xpu`, namely, at line from 125 to 133 when`DS_ACCELERATOR` is not set. I found this problem yesterday and spent whole afternoon figuring it out. I got `intel_extension_for_pytorch `installed with other package which I do not use actually and have no idea about this. Then I found that it `cpu` is assigned to accelerate_name directly if it cannot find `xpu` and it affects `cuda` detection. In fact, `cpu` will be assigned finally if `cuda` is even not detected at line from 170 to 177. --------- Co-authored-by: Olatunji Ruwase Co-authored-by: Logan Adams Co-authored-by: Logan Adams <114770087+loadams@users.noreply.github.com> --- accelerator/real_accelerator.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/accelerator/real_accelerator.py b/accelerator/real_accelerator.py index a6173ac70abd..ced9218d7aca 100644 --- a/accelerator/real_accelerator.py +++ b/accelerator/real_accelerator.py @@ -125,10 +125,9 @@ def get_accelerator(): if accelerator_name is None: try: import intel_extension_for_pytorch as ipex + if ipex._C._has_xpu(): accelerator_name = "xpu" - else: - accelerator_name = "cpu" except ImportError as e: pass if accelerator_name is None: @@ -162,7 +161,6 @@ def get_accelerator(): except ImportError as e: pass if accelerator_name is None: - # borrow this log from PR#5084 try: import torch @@ -174,16 +172,16 @@ def get_accelerator(): # For reference: https://github.com/microsoft/DeepSpeed/pull/6810 if torch.cuda.device_count() > 0 and torch.cuda.is_available(): #ignore-cuda accelerator_name = "cuda" - else: - if accel_logger is not None: - accel_logger.warn( - "Setting accelerator to CPU. If you have GPU or other accelerator, we were unable to detect it." - ) - accelerator_name = "cpu" except (RuntimeError, ImportError) as e: # TODO need a more decent way to detect which accelerator to use, consider using nvidia-smi command for detection - accelerator_name = "cuda" pass + if accelerator_name is None: + # borrow this log from PR#5084 + if accel_logger is not None: + accel_logger.warn( + "Setting accelerator to CPU. If you have GPU or other accelerator, we were unable to detect it.") + # cpu added as catch-all when accelerator detection fails + accelerator_name = "cpu" ds_set_method = "auto detect"