forked from bitsandbytes-foundation/bitsandbytes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
executable file
·93 lines (81 loc) · 2.03 KB
/
utils.py
File metadata and controls
executable file
·93 lines (81 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import subprocess
from packaging import version
import torch
try:
# to support Intel CPU/XPU (IPEX) backend
import intel_extension_for_pytorch as ipex
ipex_cpu = ipex if ipex._C._has_cpu() else None
ipex_xpu = ipex if ipex._C._has_xpu() else None
except BaseException:
ipex_cpu = None
ipex_xpu = None
try:
import triton # noqa: F401
import triton.language as tl # noqa: F401
triton_available = True
except ImportError:
triton_available = False
_NF4_QUANT_TABLE = torch.tensor(
[
-1.0,
-0.6961928009986877,
-0.5250730514526367,
-0.39491748809814453,
-0.28444138169288635,
-0.18477343022823334,
-0.09105003625154495,
0.0,
0.07958029955625534,
0.16093020141124725,
0.24611230194568634,
0.33791524171829224,
0.44070982933044434,
0.5626170039176941,
0.7229568362236023,
1.0,
],
dtype=torch.float32,
device="xpu"
if hasattr(torch, "xpu") and torch.xpu.is_available()
else "cpu", # Only cpu/xpu use this table for now.
)
_FP4_QUANT_TABLE = torch.tensor(
[
0.0000,
0.0052,
0.6667,
1.0000,
0.3333,
0.5000,
0.1667,
0.2500,
0.0000,
-0.0052,
-0.6667,
-1.0000,
-0.3333,
-0.5000,
-0.1667,
-0.2500,
],
dtype=torch.float32,
device="xpu"
if hasattr(torch, "xpu") and torch.xpu.is_available()
else "cpu", # Only cpu/xpu use this table for now.
)
CODE = {"nf4": _NF4_QUANT_TABLE, "fp4": _FP4_QUANT_TABLE}
def get_gaudi_sw_version():
"""
Returns the installed version of Gaudi SW.
"""
output = subprocess.run(
"pip list | grep habana-torch-plugin",
shell=True,
text=True,
capture_output=True,
)
# If grep return nothing
if not output.stdout.strip():
return None
return version.parse(output.stdout.split("\n")[0].split()[-1])
GAUDI_SW_VER = get_gaudi_sw_version()