Skip to content

Commit 96443a9

Browse files
authored
enhance installation check (#346)
Signed-off-by: yiliu30 <[email protected]>
1 parent 28bbf40 commit 96443a9

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

setup.py

+34-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,39 @@
1616
version = __version__
1717

1818

19-
BUILD_CUDA_EXT = int(os.environ.get('BUILD_CUDA_EXT', '1')) == 1
20-
PYPI_RELEASE = os.environ.get('PYPI_RELEASE', None)
21-
BUILD_HPU_ONLY = os.environ.get('BUILD_HPU_ONLY', '0') == '1'
19+
# All BUILD_* flags are initially set to `False`` and
20+
# will be updated to `True` if the corresponding environment check passes.
21+
BUILD_CUDA_EXT = int(os.environ.get("BUILD_CUDA_EXT", "0")) == 1
22+
PYPI_RELEASE = os.environ.get("PYPI_RELEASE", None)
23+
BUILD_HPU_ONLY = os.environ.get("BUILD_HPU_ONLY", "0") == "1"
24+
25+
26+
def is_cuda_available():
27+
try:
28+
import torch
29+
30+
return torch.cuda.is_available()
31+
except Exception as e:
32+
print(f"Checking CUDA availability failed: {e}")
33+
return False
34+
35+
36+
if is_cuda_available():
37+
# When CUDA is available, we build CUDA extension by default
38+
BUILD_CUDA_EXT = True
39+
40+
41+
@lru_cache(None)
42+
def is_habana_framework_installed():
43+
"""Check if Habana framework is installed.
44+
Only check for the habana_frameworks package without importing it to avoid
45+
initializing lazy-mode-related components.
46+
"""
47+
from importlib.util import find_spec
48+
49+
package_spec = find_spec("habana_frameworks")
50+
return package_spec is not None
51+
2252

2353
@lru_cache(None)
2454
def is_hpu_available():
@@ -28,7 +58,7 @@ def is_hpu_available():
2858
except ImportError:
2959
return False
3060

31-
if is_hpu_available():
61+
if is_hpu_available() or is_habana_framework_installed():
3262
# When HPU is available, we build HPU only by default
3363
BUILD_HPU_ONLY = True
3464

0 commit comments

Comments
 (0)