diff --git a/bitsandbytes/backends/cpu_xpu_common.py b/bitsandbytes/backends/cpu_xpu_common.py index 396234853..c936dce14 100644 --- a/bitsandbytes/backends/cpu_xpu_common.py +++ b/bitsandbytes/backends/cpu_xpu_common.py @@ -1,3 +1,4 @@ +import subprocess from typing import Optional import warnings @@ -19,6 +20,14 @@ ipex_xpu = None +gxx_available = False +try: + subprocess.run(["g++", "--version"]) + gxx_available = True +except BaseException: + warnings.warn("g++ not found, torch.compile disabled for CPU/XPU.") + + Tensor = torch.Tensor @@ -45,8 +54,8 @@ def _ipex_xpu_version_prereq(major, minor): def _maybe_torch_compile(func): - # torch.compile requires pytorch >= 2.0 - if _torch_version_prereq(2, 0): + # torch.compile requires g++ and pytorch >= 2.0 + if gxx_available and _torch_version_prereq(2, 0): options = {} # fx_graph_cache requires pytorch >= 2.2 if _torch_version_prereq(2, 2):