16
16
version = __version__
17
17
18
18
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
+
22
52
23
53
@lru_cache (None )
24
54
def is_hpu_available ():
@@ -28,7 +58,7 @@ def is_hpu_available():
28
58
except ImportError :
29
59
return False
30
60
31
- if is_hpu_available ():
61
+ if is_hpu_available () or is_habana_framework_installed () :
32
62
# When HPU is available, we build HPU only by default
33
63
BUILD_HPU_ONLY = True
34
64
0 commit comments