bitsandbytes-cpu-fork 0.50.2.dev3__py3-none-win_amd64.whl → 0.50.2.dev4__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bitsandbytes/__init__.py +1 -1
- bitsandbytes/__main__.py +4 -4
- bitsandbytes/_cpu_caps.py +110 -0
- bitsandbytes/_ops.py +526 -526
- bitsandbytes/autograd/_functions.py +491 -491
- bitsandbytes/backends/cpu/ops.py +805 -805
- bitsandbytes/backends/cuda/ops.py +1212 -1212
- bitsandbytes/backends/default/ops.py +632 -632
- bitsandbytes/backends/hpu/ops.py +53 -53
- bitsandbytes/backends/mps/ops.py +277 -277
- bitsandbytes/backends/triton/kernels_4bit.py +583 -577
- bitsandbytes/backends/triton/kernels_8bit_quant.py +195 -195
- bitsandbytes/backends/triton/kernels_optim.py +1177 -1177
- bitsandbytes/backends/triton/ops.py +304 -304
- bitsandbytes/backends/utils.py +94 -94
- bitsandbytes/backends/xpu/ops.py +305 -305
- bitsandbytes/cextension.py +447 -405
- bitsandbytes/cli.py +50 -50
- bitsandbytes/consts.py +12 -12
- bitsandbytes/cuda_specs.py +111 -111
- bitsandbytes/detect_cpu.py +189 -189
- bitsandbytes/diagnostics/cuda.py +193 -193
- bitsandbytes/diagnostics/main.py +134 -134
- bitsandbytes/diagnostics/utils.py +12 -12
- bitsandbytes/disk_balancer.py +1276 -1224
- bitsandbytes/efst.py +777 -0
- bitsandbytes/functional.py +1836 -1836
- bitsandbytes/gdn_cpu.py +616 -602
- bitsandbytes/libbitsandbytes_cpu.dll +0 -0
- bitsandbytes/nn/__init__.py +19 -19
- bitsandbytes/nn/modules.py +1220 -1220
- bitsandbytes/nn/parametrize.py +206 -206
- bitsandbytes/optim/__init__.py +0 -4
- bitsandbytes/optim/adagrad.py +187 -187
- bitsandbytes/optim/adam.py +346 -346
- bitsandbytes/optim/adamw.py +337 -337
- bitsandbytes/optim/ademamix.py +410 -410
- bitsandbytes/optim/lamb.py +190 -190
- bitsandbytes/optim/lars.py +259 -259
- bitsandbytes/optim/lion.py +266 -266
- bitsandbytes/optim/optimizer.py +756 -756
- bitsandbytes/optim/rmsprop.py +170 -170
- bitsandbytes/optim/sgd.py +152 -152
- bitsandbytes/torch_cpu_kit.py +468 -468
- bitsandbytes/utils.py +208 -208
- {bitsandbytes_cpu_fork-0.50.2.dev3.dist-info → bitsandbytes_cpu_fork-0.50.2.dev4.dist-info}/METADATA +14 -7
- bitsandbytes_cpu_fork-0.50.2.dev4.dist-info/RECORD +64 -0
- {bitsandbytes_cpu_fork-0.50.2.dev3.dist-info → bitsandbytes_cpu_fork-0.50.2.dev4.dist-info}/licenses/LICENSE +21 -21
- bitsandbytes/optim/adamw4bit.py +0 -183
- bitsandbytes_cpu_fork-0.50.2.dev3.dist-info/RECORD +0 -63
- {bitsandbytes_cpu_fork-0.50.2.dev3.dist-info → bitsandbytes_cpu_fork-0.50.2.dev4.dist-info}/WHEEL +0 -0
- {bitsandbytes_cpu_fork-0.50.2.dev3.dist-info → bitsandbytes_cpu_fork-0.50.2.dev4.dist-info}/entry_points.txt +0 -0
- {bitsandbytes_cpu_fork-0.50.2.dev3.dist-info → bitsandbytes_cpu_fork-0.50.2.dev4.dist-info}/top_level.txt +0 -0
bitsandbytes/__init__.py
CHANGED
bitsandbytes/__main__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
if __name__ == "__main__":
|
|
2
|
-
from bitsandbytes.diagnostics.main import main
|
|
3
|
-
|
|
4
|
-
main()
|
|
1
|
+
if __name__ == "__main__":
|
|
2
|
+
from bitsandbytes.diagnostics.main import main
|
|
3
|
+
|
|
4
|
+
main()
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""CPU feature queries used to choose between the AVX2 and AVX-512 CPU libraries.
|
|
2
|
+
|
|
3
|
+
Why a separate module: two places need the same answer -- `cextension` (the main native
|
|
4
|
+
library loader) and `gdn_cpu` (the fused Gated DeltaNet wrapper). Importing one from the
|
|
5
|
+
other would drag the whole native library in at import time, so the query lives here and
|
|
6
|
+
imports nothing but the standard library; torch is imported lazily, only when it is already
|
|
7
|
+
present in the process.
|
|
8
|
+
|
|
9
|
+
The AVX-512 backend is a separate artifact because it is NOT safe on AVX2-only CPUs
|
|
10
|
+
(and it is compiled with AVX512-BF16, so it is also unsafe on AVX-512 CPUs without BF16):
|
|
11
|
+
building it with `-mavx512f` is a translation-unit-wide switch, and GCC auto-vectorises
|
|
12
|
+
ordinary kernels (dequantise, optimizer, rmsnorm) with zmm instructions. The library must
|
|
13
|
+
therefore only be loaded after the CPU and OS are known to support AVX-512. On Linux the
|
|
14
|
+
`/proc/cpuinfo` flags are authoritative; on Windows the query goes through torch, which
|
|
15
|
+
already performs the full CPUID + XGETBV check (and exists in any process that can use this
|
|
16
|
+
package). If neither source can answer, the answer is "no" -- refusing to load the AVX-512
|
|
17
|
+
library is always safe, guessing is not.
|
|
18
|
+
"""
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import os
|
|
22
|
+
|
|
23
|
+
# avx512_bf16 is required too: the AVX-512 artifact is compiled with
|
|
24
|
+
# -mavx512bf16, so it contains bf16 instructions (auto-vectorised) even outside
|
|
25
|
+
# the explicitly guarded bf16 kernels. CPUs with AVX-512 but no BF16
|
|
26
|
+
# (Skylake-X, Cascade Lake) would SIGILL on them.
|
|
27
|
+
_AVX512_FLAGS = frozenset({"avx512f", "avx512bw", "avx512dq", "avx512vl", "avx512_bf16"})
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _env_flag(name: str) -> bool:
|
|
31
|
+
value = os.environ.get(name)
|
|
32
|
+
if value is None:
|
|
33
|
+
return False
|
|
34
|
+
return value.strip().lower() not in ("", "0", "false", "no", "off")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _torch_capability() -> str | None:
|
|
38
|
+
"""What torch already knows about this CPU ('AVX2', 'AVX512', 'DEFAULT', ...)."""
|
|
39
|
+
try:
|
|
40
|
+
import torch
|
|
41
|
+
except Exception: # pragma: no cover - torch is a hard dependency in practice
|
|
42
|
+
return None
|
|
43
|
+
backend = getattr(torch, "backends", None)
|
|
44
|
+
cpu = getattr(backend, "cpu", None)
|
|
45
|
+
query = getattr(cpu, "get_cpu_capability", None)
|
|
46
|
+
if query is None:
|
|
47
|
+
return None
|
|
48
|
+
try:
|
|
49
|
+
return str(query()).upper()
|
|
50
|
+
except Exception: # pragma: no cover - defensive: a broken torch must not crash import
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _read_cpuinfo_flags(path: str = "/proc/cpuinfo") -> set[str] | None:
|
|
55
|
+
"""First ``flags`` line of /proc-style cpuinfo, or None when unreadable (non-Linux)."""
|
|
56
|
+
try:
|
|
57
|
+
with open(path, "r", encoding="utf-8", errors="replace") as handle:
|
|
58
|
+
for line in handle:
|
|
59
|
+
if line.startswith("flags"):
|
|
60
|
+
return set(line.split(":", 1)[1].split())
|
|
61
|
+
except OSError:
|
|
62
|
+
return None
|
|
63
|
+
return None
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _proc_cpuinfo_supports_avx2(path: str = "/proc/cpuinfo") -> bool:
|
|
67
|
+
flags = _read_cpuinfo_flags(path)
|
|
68
|
+
return flags is not None and {"avx2", "fma", "f16c"} <= flags
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _proc_cpuinfo_supports_avx512(path: str = "/proc/cpuinfo") -> bool:
|
|
72
|
+
flags = _read_cpuinfo_flags(path)
|
|
73
|
+
return flags is not None and _AVX512_FLAGS <= flags
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def avx512_supported() -> bool:
|
|
77
|
+
"""True only when the CPU + OS can execute the AVX-512 libraries' instructions.
|
|
78
|
+
|
|
79
|
+
BNB_CPU_DISABLE_AVX512=1 forces the AVX2 library even on capable hardware (useful when
|
|
80
|
+
comparing the two backends); BNB_CPU_FORCE_AVX512=1 forces the AVX-512 path (only safe on
|
|
81
|
+
a machine that really supports it -- it exists so the selection logic can be tested).
|
|
82
|
+
"""
|
|
83
|
+
if _env_flag("BNB_CPU_DISABLE_AVX512"):
|
|
84
|
+
return False
|
|
85
|
+
if _env_flag("BNB_CPU_FORCE_AVX512"):
|
|
86
|
+
return True
|
|
87
|
+
flags = _read_cpuinfo_flags()
|
|
88
|
+
if flags is not None:
|
|
89
|
+
# /proc/cpuinfo knows about BF16, so it is the authoritative answer on Linux.
|
|
90
|
+
return _AVX512_FLAGS <= flags
|
|
91
|
+
# torch reports only the ISA level ("AVX512"), not BF16. Since the shipped AVX-512
|
|
92
|
+
# library contains bf16 instructions, an ISA-level "yes" alone is not safe there.
|
|
93
|
+
capability = _torch_capability()
|
|
94
|
+
if capability is not None:
|
|
95
|
+
return False
|
|
96
|
+
return False
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def avx2_supported() -> bool:
|
|
100
|
+
"""True when the CPU can execute the regular (AVX2+FMA) artifact.
|
|
101
|
+
|
|
102
|
+
BNB_CPU_FORCE_GENERIC=1 forces the portable artifact (it runs on any x86-64, so this is
|
|
103
|
+
safe and makes the three-way selection testable on an AVX2 machine).
|
|
104
|
+
"""
|
|
105
|
+
if _env_flag("BNB_CPU_FORCE_GENERIC"):
|
|
106
|
+
return False
|
|
107
|
+
capability = _torch_capability()
|
|
108
|
+
if capability is not None:
|
|
109
|
+
return capability in ("AVX2", "AVX512")
|
|
110
|
+
return _proc_cpuinfo_supports_avx2()
|