bitsandbytes-cpu-fork 0.50.2.dev8__py3-none-win_amd64.whl → 0.50.2.dev10__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/fused/__init__.py +21 -0
- bitsandbytes/fused/_native.py +66 -0
- bitsandbytes/fused/_ref.py +62 -0
- bitsandbytes/libbitsandbytes_cpu.dll +0 -0
- bitsandbytes/q3bit.py +9 -3
- bitsandbytes_cpu_cli.py +6 -6
- {bitsandbytes_cpu_fork-0.50.2.dev8.dist-info → bitsandbytes_cpu_fork-0.50.2.dev10.dist-info}/METADATA +71 -8
- {bitsandbytes_cpu_fork-0.50.2.dev8.dist-info → bitsandbytes_cpu_fork-0.50.2.dev10.dist-info}/RECORD +13 -10
- {bitsandbytes_cpu_fork-0.50.2.dev8.dist-info → bitsandbytes_cpu_fork-0.50.2.dev10.dist-info}/WHEEL +0 -0
- {bitsandbytes_cpu_fork-0.50.2.dev8.dist-info → bitsandbytes_cpu_fork-0.50.2.dev10.dist-info}/entry_points.txt +0 -0
- {bitsandbytes_cpu_fork-0.50.2.dev8.dist-info → bitsandbytes_cpu_fork-0.50.2.dev10.dist-info}/licenses/LICENSE +0 -0
- {bitsandbytes_cpu_fork-0.50.2.dev8.dist-info → bitsandbytes_cpu_fork-0.50.2.dev10.dist-info}/top_level.txt +0 -0
bitsandbytes/__init__.py
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""CPU fused operators (Liger-style minimal package).
|
|
2
|
+
|
|
3
|
+
Public API:
|
|
4
|
+
rms_norm(x, weight, eps=1e-6) # torch reference (autograd-friendly)
|
|
5
|
+
silu_mul(gate, up) # torch reference (autograd-friendly)
|
|
6
|
+
rope(x, cos, sin) # torch reference (autograd-friendly)
|
|
7
|
+
fused_ce(logits, labels) # torch reference, mean cross entropy
|
|
8
|
+
native_available() # zig AVX2 kernels loaded?
|
|
9
|
+
rms_norm_native(x, weight, eps) # forward-only AVX2
|
|
10
|
+
silu_mul_native(gate, up) # forward-only AVX2
|
|
11
|
+
|
|
12
|
+
The torch versions are the contract; native versions must match rel<1e-3.
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from ._ref import fused_ce, linear_cross_entropy, rms_norm, rope, silu_mul
|
|
17
|
+
from ._native import native_available, rms_norm_native, silu_mul_native
|
|
18
|
+
|
|
19
|
+
__all__ = ['rms_norm', 'silu_mul', 'rope', 'fused_ce',
|
|
20
|
+
'native_available', 'rms_norm_native', 'silu_mul_native',
|
|
21
|
+
'linear_cross_entropy']
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""ctypes loader for the zig-compiled AVX2 fused kernels."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import ctypes
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
import torch
|
|
8
|
+
|
|
9
|
+
_HERE = os.path.dirname(os.path.abspath(__file__))
|
|
10
|
+
_DLL = os.path.join(_HERE, 'bnb_fused.dll')
|
|
11
|
+
_LIB = None
|
|
12
|
+
_TRIED = False
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _lib():
|
|
16
|
+
global _LIB, _TRIED
|
|
17
|
+
if _TRIED:
|
|
18
|
+
return _LIB
|
|
19
|
+
_TRIED = True
|
|
20
|
+
if not os.path.exists(_DLL):
|
|
21
|
+
return None
|
|
22
|
+
try:
|
|
23
|
+
lib = ctypes.CDLL(_DLL)
|
|
24
|
+
lib.rms_norm_f32.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p,
|
|
25
|
+
ctypes.c_int, ctypes.c_int, ctypes.c_float]
|
|
26
|
+
lib.rms_norm_f32.restype = None
|
|
27
|
+
lib.silu_mul_f32.argtypes = [ctypes.c_void_p, ctypes.c_void_p,
|
|
28
|
+
ctypes.c_void_p, ctypes.c_longlong]
|
|
29
|
+
lib.silu_mul_f32.restype = None
|
|
30
|
+
_LIB = lib
|
|
31
|
+
except Exception: # noqa: BLE001 - missing/incompatible lib means torch fallback
|
|
32
|
+
_LIB = None
|
|
33
|
+
return _LIB
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def native_available() -> bool:
|
|
37
|
+
return _lib() is not None
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _f32(t: torch.Tensor) -> torch.Tensor:
|
|
41
|
+
return t.detach().contiguous().float()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def rms_norm_native(x: torch.Tensor, weight: torch.Tensor, eps: float = 1e-6) -> torch.Tensor:
|
|
45
|
+
lib = _lib()
|
|
46
|
+
if lib is None:
|
|
47
|
+
raise RuntimeError('native fused DLL not available')
|
|
48
|
+
if x.dim() < 2:
|
|
49
|
+
raise ValueError('x must have at least 2 dims')
|
|
50
|
+
D = x.shape[-1]
|
|
51
|
+
x2 = _f32(x).reshape(-1, D)
|
|
52
|
+
w = _f32(weight).reshape(D)
|
|
53
|
+
out = torch.empty_like(x2)
|
|
54
|
+
lib.rms_norm_f32(x2.data_ptr(), w.data_ptr(), out.data_ptr(), x2.shape[0], D, float(eps))
|
|
55
|
+
return out.reshape(x.shape)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def silu_mul_native(gate: torch.Tensor, up: torch.Tensor) -> torch.Tensor:
|
|
59
|
+
lib = _lib()
|
|
60
|
+
if lib is None:
|
|
61
|
+
raise RuntimeError('native fused DLL not available')
|
|
62
|
+
g = _f32(gate).reshape(-1)
|
|
63
|
+
u = _f32(up).reshape(-1)
|
|
64
|
+
out = torch.empty_like(g)
|
|
65
|
+
lib.silu_mul_f32(g.data_ptr(), u.data_ptr(), out.data_ptr(), g.numel())
|
|
66
|
+
return out.reshape(gate.shape)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Torch reference implementation of the fused operators (the contract)."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import torch
|
|
5
|
+
import torch.nn.functional as F
|
|
6
|
+
|
|
7
|
+
__all__ = ['rms_norm', 'silu_mul', 'rope', 'fused_ce']
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def rms_norm(x: torch.Tensor, weight: torch.Tensor, eps: float = 1e-6) -> torch.Tensor:
|
|
11
|
+
"""RMSNorm over the last dim: x * rsqrt(mean(x^2)+eps) * weight."""
|
|
12
|
+
y = x * torch.rsqrt(x.pow(2).mean(dim=-1, keepdim=True) + eps)
|
|
13
|
+
return y * weight
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def silu_mul(gate: torch.Tensor, up: torch.Tensor) -> torch.Tensor:
|
|
17
|
+
"""SwiGLU gate: silu(gate) * up."""
|
|
18
|
+
return F.silu(gate) * up
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def rope(x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor) -> torch.Tensor:
|
|
22
|
+
"""Rotary embedding: x*cos + rotate_half(x)*sin.
|
|
23
|
+
|
|
24
|
+
x: (..., D), D even; cos/sin broadcast to x's shape.
|
|
25
|
+
rotate_half: [x0,x1,...,xd-1] -> [-x_{d/2},...,-x_{d-1}, x0,...,x_{d/2-1}]
|
|
26
|
+
"""
|
|
27
|
+
if x.shape[-1] % 2:
|
|
28
|
+
raise ValueError('rope last dim must be even')
|
|
29
|
+
half = x.shape[-1] // 2
|
|
30
|
+
rot = torch.cat((-x[..., half:], x[..., :half]), dim=-1)
|
|
31
|
+
return x * cos + rot * sin
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def fused_ce(logits: torch.Tensor, labels: torch.Tensor,
|
|
35
|
+
ignore_index: int = -100) -> torch.Tensor:
|
|
36
|
+
"""Mean cross entropy over N rows (logits [N,V], labels [N])."""
|
|
37
|
+
return F.cross_entropy(logits, labels, ignore_index=ignore_index)
|
|
38
|
+
|
|
39
|
+
def linear_cross_entropy(hidden: torch.Tensor, weight: torch.Tensor,
|
|
40
|
+
labels: torch.Tensor, chunk: int = 1024,
|
|
41
|
+
ignore_index: int = -100) -> torch.Tensor:
|
|
42
|
+
"""Cross entropy of hidden @ weight.T without materialising full logits."""
|
|
43
|
+
M, D = hidden.shape
|
|
44
|
+
V = weight.shape[0]
|
|
45
|
+
mask = labels != ignore_index
|
|
46
|
+
tgt = labels.clone()
|
|
47
|
+
tgt[~mask] = 0
|
|
48
|
+
target_logit = (hidden * weight[tgt]).sum(dim=-1)
|
|
49
|
+
maxv = torch.full((M,), -float('inf'), dtype=torch.float64)
|
|
50
|
+
sumexp = torch.zeros(M, dtype=torch.float64)
|
|
51
|
+
target_logit = target_logit.double()
|
|
52
|
+
for s in range(0, V, chunk):
|
|
53
|
+
e = min(V, s + chunk)
|
|
54
|
+
logits = (hidden @ weight[s:e].t()).double()
|
|
55
|
+
cmax = logits.max(dim=-1).values
|
|
56
|
+
newmax = torch.maximum(maxv, cmax)
|
|
57
|
+
sumexp = sumexp * torch.exp(maxv - newmax) + torch.exp(logits - newmax[:, None]).sum(dim=-1)
|
|
58
|
+
maxv = newmax
|
|
59
|
+
loss = torch.log(sumexp) + maxv - target_logit
|
|
60
|
+
if mask.any():
|
|
61
|
+
return loss[mask].mean()
|
|
62
|
+
return loss.mean()
|
|
Binary file
|
bitsandbytes/q3bit.py
CHANGED
|
@@ -182,7 +182,11 @@ def _quantize(w: torch.Tensor, bits: int, block: int) -> Tuple[torch.Tensor, tor
|
|
|
182
182
|
flat = torch.cat([flat, torch.zeros(pad, dtype=flat.dtype)])
|
|
183
183
|
nb = flat.numel() // block
|
|
184
184
|
blk = flat.view(nb, block)
|
|
185
|
-
|
|
185
|
+
_clip = float(os.environ.get('BNB_Q3BIT_CLIP', '1.0') or 1.0)
|
|
186
|
+
if 0.5 < _clip < 1.0:
|
|
187
|
+
absmax = torch.quantile(blk.abs(), _clip, dim=1)
|
|
188
|
+
else:
|
|
189
|
+
absmax = blk.abs().amax(dim=1)
|
|
186
190
|
center = _CENTER[bits]
|
|
187
191
|
scale = (absmax / center).clamp_min(1e-12)
|
|
188
192
|
q = torch.round(blk / scale.unsqueeze(1) + center).clamp(0, _levels(bits) - 1).to(torch.uint8)
|
|
@@ -447,8 +451,10 @@ class QuantLinear3bit(nn.Module):
|
|
|
447
451
|
else:
|
|
448
452
|
w = self.weight().to(x.dtype)
|
|
449
453
|
base = F.linear(x2, w, self.bias)
|
|
450
|
-
|
|
451
|
-
|
|
454
|
+
la = self.lora_A.to(x2.dtype)
|
|
455
|
+
lb = self.lora_B.to(x2.dtype)
|
|
456
|
+
lora = (x2 @ la.t()) @ lb.t() * self.scale
|
|
457
|
+
return (base + lora).to(x.dtype).reshape(*lead, self.out_features)
|
|
452
458
|
|
|
453
459
|
def extra_repr(self) -> str:
|
|
454
460
|
return ("in_features=%d, out_features=%d, bits=3, block=%d, lora_r=%d"
|
bitsandbytes_cpu_cli.py
CHANGED
|
@@ -312,15 +312,15 @@ SECTIONS = [
|
|
|
312
312
|
"# what runs today is the verified scalar path",
|
|
313
313
|
"# the optimizer is a few percent of a real training step at 30M params,",
|
|
314
314
|
"# so the wall-clock cost is small while the state saving is 7.8x",
|
|
315
|
-
"# the pure-torch fallback (
|
|
315
|
+
"# older Windows wheels run the pure-torch fallback (dev9+ is native)",
|
|
316
316
|
], PY),
|
|
317
317
|
("traps",
|
|
318
318
|
"the failure modes seen while building this, each one silent at first", [
|
|
319
319
|
"# 1. torch.optim.AdamW is NOT replaced: this is a separate class, and",
|
|
320
320
|
"# AdamW4bit requires fp32 params (the kernel's dtype 0).",
|
|
321
321
|
"# 2. blocksize is compiled in at 256; passing another value raises.",
|
|
322
|
-
"# 3.
|
|
323
|
-
"# coptimizer_update_4bit_blockwise_cpu (
|
|
322
|
+
"# 3. older Windows wheels (< dev9) do not export",
|
|
323
|
+
"# coptimizer_update_4bit_blockwise_cpu (pre-dev9 Windows wheels),",
|
|
324
324
|
"# this class transparently uses a pure-torch implementation with the",
|
|
325
325
|
"# same numbers and the same 1.031 B/param state, just slower.",
|
|
326
326
|
"# 4. quantised state is not a drop-in for exact reproducibility runs:",
|
|
@@ -549,7 +549,7 @@ SECTIONS = [
|
|
|
549
549
|
"A = torch.randn(4, 128)",
|
|
550
550
|
"out = q3bit.gemm_3bit(A, packed, absmax)",
|
|
551
551
|
"ref = A @ q3bit.dequantize_3bit(packed, absmax, w.shape).t()",
|
|
552
|
-
"assert (out - ref).abs().max().item() < 1e-
|
|
552
|
+
"assert (out - ref).abs().max().item() < 1e-4 # native kernel rounds at the ULP",
|
|
553
553
|
], PY),
|
|
554
554
|
("QuantLinear3bit.from_linear(linear, lora_r=8)",
|
|
555
555
|
"frozen 3-bit base + trainable LoRA; only lora_A/lora_B require grad", [
|
|
@@ -565,8 +565,8 @@ SECTIONS = [
|
|
|
565
565
|
("convert_linears_3bit(model, lora_r=8)",
|
|
566
566
|
"replaces every nn.Linear in place and returns the count; lm_head stays fp32", []),
|
|
567
567
|
("experimental / portability",
|
|
568
|
-
"the Windows wheel
|
|
569
|
-
"fallback
|
|
568
|
+
"since dev9 the Windows wheel ships a CI-built MSVC DLL; older wheels use the pure-torch "
|
|
569
|
+
"fallback, while the dev9 Windows and Linux wheels use the native kernels", []),
|
|
570
570
|
]),
|
|
571
571
|
("layers", "Reference: bitsandbytes.nn", [
|
|
572
572
|
("Linear4bit(input_features, output_features, bias=True, compute_dtype=None,\n"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bitsandbytes-cpu-fork
|
|
3
|
-
Version: 0.50.2.
|
|
3
|
+
Version: 0.50.2.dev10
|
|
4
4
|
Summary: bitsandbytes with a pure-CPU training backend (AVX2 / NEON): 8-bit optimizers, fused GDN, gemm_8bit, disk balancer. No GPU required.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: repository, https://github.com/Ganyvnanoaa09-0906/bitsandbytes-CPU
|
|
@@ -36,7 +36,7 @@ Dynamic: license-file
|
|
|
36
36
|
> toolkit and no driver** — just an AVX2 x86-64 CPU (or ARM64 NEON), the CPU build of PyTorch,
|
|
37
37
|
> and 12–16 GB of RAM.
|
|
38
38
|
|
|
39
|
-
**Version: `0.50.2.
|
|
39
|
+
**Version: `0.50.2.dev9`** · import name is unchanged (`import bitsandbytes as bnb`) · MIT.
|
|
40
40
|
|
|
41
41
|
What the CPU backend provides: 8-bit blockwise optimizers (≈2.3 bytes of state per parameter
|
|
42
42
|
instead of 8; the 4-bit optimizer ≈1.03), 4/8-bit layers that run on CPU tensors, the fused
|
|
@@ -202,7 +202,7 @@ Also: `estimate_training_memory_gb()`, `spawn_training_jobs(cmds, plan)` (logs p
|
|
|
202
202
|
| Area | What it does |
|
|
203
203
|
|---|---|
|
|
204
204
|
| 8-bit optimizers | AdamW/Adam/AdEMAMix/LAMB/LARS/Lion + paged variants, blockwise 8-bit state with single-pass dequant→update→requant kernels (AVX2/NEON) |
|
|
205
|
-
| 4-bit optimizer | `AdamW4bit`: ≈1.03 bytes of state per parameter (
|
|
205
|
+
| 4-bit optimizer | `AdamW4bit`: ≈1.03 bytes of state per parameter (scalar kernel; native on Linux and, since dev9, Windows) |
|
|
206
206
|
| Quantisation | blockwise 8-bit, NF4/FP4 4-bit quantize/dequantize; 4-bit GEMV inference kernel |
|
|
207
207
|
| `gemm_8bit` | `out = A @ dequant8(B)` with weights kept uint8 (¼ DRAM traffic), no fp32 temporary (`bnb.functional.fused_dequant_linear_8bit`) |
|
|
208
208
|
| GDN | fused Gated DeltaNet forward + chunk-checkpointed backward (`gdn_fwd_cpu` / `gdn_bwd_cpu`), plus `patch_transformers()` / `patch_fla()` |
|
|
@@ -215,6 +215,48 @@ The library never loads a CUDA/ROCm/XPU library: `bnb.cuda`/`bnb.optim` CPU path
|
|
|
215
215
|
|
|
216
216
|
---
|
|
217
217
|
|
|
218
|
+
## Full fine-tuning vs LoRA
|
|
219
|
+
|
|
220
|
+
`--mode full` (and `bnb.optim.*` directly) fine-tunes **every parameter**; measured on
|
|
221
|
+
Qwen3.5-0.8B (752 M, 100% trainable, fp32 + AdamW8bit, seq 64, batch 1): **peak RSS
|
|
222
|
+
10.4 GB, 8.8 s/step**, versus LoRA (5.4 M trainable) at **5.9 GB / 2.65 s/step**. On a
|
|
223
|
+
15.4 GB machine ~0.8 B full fine-tuning is comfortable; ~1 B is tight (estimator:
|
|
224
|
+
10.7 GB weights+grads+8-bit state before activations), and above that use LoRA / EFST /
|
|
225
|
+
q3bit, or add activation checkpointing (not yet wired into the generic trainer).
|
|
226
|
+
|
|
227
|
+
## iGPU image inference (experimental)
|
|
228
|
+
|
|
229
|
+
The OpenCL kit is GEMM-oriented (`nn.Linear`/`Conv1D`); diffusion UNets are conv2d-heavy and
|
|
230
|
+
need an im2col+dGEMM conv engine before the OpenCL path can run them. As a proof of concept,
|
|
231
|
+
`gt1030/igpu_image_ort.py` runs an ONNX-exported SD1.5 through ONNX Runtime's
|
|
232
|
+
**DmlExecutionProvider** on the integrated GPU (local `_sd15_combined`, 256x256, DDIM):
|
|
233
|
+
|
|
234
|
+
| path | 8 steps | per step |
|
|
235
|
+
|---|---|---|
|
|
236
|
+
| CPU diffusers (Torch 2.13, 6 threads) | 25.29 s | 3.16 s |
|
|
237
|
+
| **iGPU ONNX Runtime DirectML** | **13.05 s** | **1.63 s** |
|
|
238
|
+
|
|
239
|
+
≈**1.9x** faster at 256x256; 512x512 currently fails inside the UNet on the DML EP (activation
|
|
240
|
+
memory / operator coverage) while the same ONNX runs on `CPUExecutionProvider`. Export once with
|
|
241
|
+
`optimum-cli export onnx --task stable-diffusion --opset 17`. A diffusers + `torch_directml`
|
|
242
|
+
variant (`igpu_image_infer.py`) is kept as a comparison; it needs legacy attention and still hits
|
|
243
|
+
DML `chunk`/reshape issues. Long-term the OpenCL backend gets an **fp16 device-resident conv engine**: measured probes
|
|
244
|
+
show per-op OpenCL conv is 2-3x slower than CPU oneDNN and fp32 resident only reaches parity,
|
|
245
|
+
but fp16 resident im2col+Hgemm is **1.3-2x faster than the CPU conv** at SD1.5 shapes
|
|
246
|
+
(538 vs 342 GFLOPS; 1280-channel 16x16 layer 17.3 vs 34.8 ms). The 256-resolution demo
|
|
247
|
+
therefore uses DirectML, while the OpenCL engine is the planned production backend.
|
|
248
|
+
|
|
249
|
+
The fp16 device-resident building blocks are in `gt1030/opencl_fp16_ops.py` +
|
|
250
|
+
`gt1030/kernels_attention.cl` (im2col + CLBlast Hgemm conv, GroupNorm+SiLU, LayerNorm,
|
|
251
|
+
GEGLU, multi-head attention, nearest-2x upsample, add). Clean measurements on the
|
|
252
|
+
Vega 6 (no CPU contention), parity 0.02-1.1% relL2:
|
|
253
|
+
ResNetBlock2D 0.61-0.77x, VAE up-block 0.40x, FFN 0.16-0.23x, attention 0.42-0.99x,
|
|
254
|
+
full Transformer block 0.51-0.71x of CPU time -- i.e. 1.3-6x faster for most blocks.
|
|
255
|
+
The **VAE decoder is now end-to-end on the iGPU** (`gt1030/opencl_vae.py`): fp16 parity
|
|
256
|
+
2.7-3.7% vs CPU, 1.81 s vs 2.07 s at 256 (0.87x), 7.93 s vs 8.34 s at 512 (0.95x, warm).
|
|
257
|
+
The remaining step is assembling the full 256px UNet graph (fp16 weights ~1.7 GB,
|
|
258
|
+
under the 5,090 MB single-allocation limit; 512px needs activation tiling).
|
|
259
|
+
|
|
218
260
|
## 3-bit frozen base + LoRA (`bitsandbytes.q3bit`, experimental)
|
|
219
261
|
|
|
220
262
|
A frozen weight can be stored as blockwise **3-bit** codes (≈11% of fp32 memory) and
|
|
@@ -256,6 +298,8 @@ R5-4500U (6C/6T, AVX2, 15.4 GB) / i5-10400 (6C/12T, AVX2, 12 GB), no NVIDIA GPU.
|
|
|
256
298
|
| Concurrency packing (synthetic jobs) | 6 jobs × 1 thread **5619 tok/s** vs 1 job × 6 threads **3843 tok/s** (+46%) |
|
|
257
299
|
| Real model (Qwen3.5-0.8B LoRA, seq 64) | 4 threads beat 6 by **7–10%** — measure with `tune_threads()` |
|
|
258
300
|
| Fused lm_head 3-bit GEMM (research) | 14–22% faster than fp32 matmul, 89% less weight memory |
|
|
301
|
+
| 3-bit frozen base + LoRA (Qwen3-1.7B, CPU) | 80 steps: eval loss 4.34 → **4.03**; RSS **2.9 GB vs 8.7 GB** fp32; step 7.7 s vs 5.5 s (native Windows) |
|
|
302
|
+
| Full-parameter fine-tune (Qwen3.5-0.8B, 752 M, fp32 + AdamW8bit, CPU) | **10.4 GB peak RSS**, 8.8 s/step; LoRA on the same model: 5.9 GB, 2.65 s/step |
|
|
259
303
|
| AdamW4bit step (1M params) | 28.6 ms vs 3.3 ms for the AVX2 8-bit kernel; state 1.031 vs 2.062 B/param |
|
|
260
304
|
|
|
261
305
|
Not every workload is faster than fp32: 4-bit/8-bit kernels trade compute for memory traffic,
|
|
@@ -267,14 +311,15 @@ the full trade-off tables, including negative results.
|
|
|
267
311
|
## Platform limitations
|
|
268
312
|
|
|
269
313
|
- **CPU only.** CUDA/ROCm/XPU kernels are not built; a GPU is never required or used.
|
|
270
|
-
- **Windows wheel
|
|
271
|
-
|
|
272
|
-
|
|
314
|
+
- **Windows wheel**: from dev9 on it ships the MSVC DLL built by CI from the current
|
|
315
|
+
`csrc`, which exports the 2/3-bit dequant/GEMM and 4-bit optimizer kernels; they run
|
|
316
|
+
natively on Windows (verified: dequant maxdiff 1.2e-6, 4-bit native vs torch 1.2e-7).
|
|
317
|
+
Wheels older than dev9 fall back to pure torch for those symbols.
|
|
273
318
|
- **manylinux_2_17 wheel**: the AVX-512 library inside it is single-threaded (the parallel
|
|
274
319
|
build is only for the native `manylinux_2_39` wheel). On AVX-512 machines set
|
|
275
320
|
`BNB_CPU_DISABLE_AVX512=1` to run the AVX2 OpenMP path.
|
|
276
|
-
- **aarch64**: there is no PyPI wheel yet; build from the sdist (`build_linux.sh`) or
|
|
277
|
-
Termux
|
|
321
|
+
- **aarch64**: there is no PyPI wheel yet; build from the sdist (`build_linux.sh`) or follow the
|
|
322
|
+
Termux guide [`TERMUX_GUIDE.md`](https://github.com/Ganyvnanoaa09-0906/bitsandbytes-CPU/blob/HEAD/bitsandbytes/TERMUX_GUIDE.md).
|
|
278
323
|
- **macOS**: no wheel is published and the CPU backend is not tested there; the sdist build may
|
|
279
324
|
work with clang + OpenMP, but treat it as unsupported.
|
|
280
325
|
- 3-bit (and 2-bit dequant-only) is **experimental**: the API and kernels are covered
|
|
@@ -293,6 +338,23 @@ bash build_linux.sh --selftest # also build + run the torch-free C se
|
|
|
293
338
|
build_manual\build_manual.bat amd # run inside "x64 Native Tools Command Prompt"
|
|
294
339
|
```
|
|
295
340
|
|
|
341
|
+
### Termux (Android / ARM64)
|
|
342
|
+
|
|
343
|
+
On-device builds work; there is no aarch64 PyPI wheel, so build from the sdist:
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
pkg update && pkg install -y clang libomp make python
|
|
347
|
+
bash build_termux.sh # -> bitsandbytes/libbitsandbytes_cpu.so
|
|
348
|
+
bash build_termux.sh --selftest # also build + run the torch-free C self-test
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
Three Termux-specific traps the script already handles: the compiler is `clang++` (there is no
|
|
352
|
+
`g++`), OpenMP needs `pkg install libomp`, and `-march=native` is unsafe under Android's clang.
|
|
353
|
+
The script is also what the automated flow uses to build on a phone **driven from a PC over ADB**
|
|
354
|
+
— see [`TERMUX_GUIDE.md`](https://github.com/Ganyvnanoaa09-0906/bitsandbytes-CPU/blob/HEAD/bitsandbytes/TERMUX_GUIDE.md)
|
|
355
|
+
for the phone-side preparation, the ADB/wireless-debugging path, the ARM64 kernel notes and the
|
|
356
|
+
verification matrix.
|
|
357
|
+
|
|
296
358
|
Two special wheel builds used by this project are documented in
|
|
297
359
|
[`docs_cpu/WHEEL_PLATFORM_NOTES.md`](https://github.com/Ganyvnanoaa09-0906/bitsandbytes-CPU/blob/HEAD/bitsandbytes/docs_cpu/WHEEL_PLATFORM_NOTES.md):
|
|
298
360
|
the zig manylinux_2_17 portable build and the devtoolset-8 manylinux_2_17 **OpenMP** build
|
|
@@ -334,6 +396,7 @@ The long-form docs live in the repository (`bitsandbytes/docs_cpu/`, Chinese and
|
|
|
334
396
|
| `0.50.2.dev6` | manylinux_2_17 wheel is now **OpenMP** (devtoolset-8, bundled libgomp → 3–4× optimizer-kernel speedup on old glibc); csrc 2/3-bit dequant + fused GEMM kernels with 9-item C self-test; EFST fused tensor-expert routing fix; GCC 8 `<cpuid.h>` portability fix |
|
|
335
397
|
| `0.50.2.dev7` | documentation release: README rewritten for the CPU fork (install/wheels/platform matrix, feature table, measured performance, limitations, tests, full dev1→dev7 changelog, EFST/disk-balancer/toolbox examples) |
|
|
336
398
|
| `0.50.2.dev8` | **restored `AdamW4bit`** (the kernel was dropped when dev4 vendored upstream; now scalar C kernel + torch fallback, 1.031 B/param); **new `bitsandbytes.q3bit` API** — `quantize_3bit`/`dequantize_3bit`/`gemm_3bit`/`gemm_3bit_transposed`, `QuantLinear3bit` (frozen 3-bit base + LoRA), `convert_linears_3bit`, native kernels on Linux with identical pure-torch fallback; CLI reference now includes 4bitopt/q3bit and all 43 examples execute in CI-style verification |
|
|
399
|
+
| `0.50.2.dev9` | **Windows native kernels**: CI now compiles the MSVC DLL from the current csrc and the export list includes the 4-bit optimizer and 2/3-bit symbols (they were silently missing before); **q3bit real-model validation** on Qwen3-1.7B (frozen 3-bit base + LoRA, eval 4.34→4.03 over 80 steps, RSS −67%, native step 7.7 s vs fp32 5.5 s); fixed the causal-LM **double-shift** label bug in the iGPU training kit (Windows package v0.1.2) |
|
|
337
400
|
|
|
338
401
|
## License and attribution
|
|
339
402
|
|
{bitsandbytes_cpu_fork-0.50.2.dev8.dist-info → bitsandbytes_cpu_fork-0.50.2.dev10.dist-info}/RECORD
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
bitsandbytes_cpu_cli.py,sha256=
|
|
2
|
-
bitsandbytes/__init__.py,sha256
|
|
1
|
+
bitsandbytes_cpu_cli.py,sha256=m0hrlRdNnEDhWMLknfUzn1xJ4g4ogjKyLG9XwhPbUeg,53333
|
|
2
|
+
bitsandbytes/__init__.py,sha256=nQqvH6ddoj_9cMfT_lb9GFq8Jbq9SopMuEyusuJRzd0,2515
|
|
3
3
|
bitsandbytes/__main__.py,sha256=A3iA9QH8yfn-60uN6w_7WUiuRIM777rZ_pf_HsZtse4,90
|
|
4
4
|
bitsandbytes/_cpu_caps.py,sha256=LgG3yRHdf0YGxTACxrweqiunghmuJbDAol4s02mwmHA,4691
|
|
5
5
|
bitsandbytes/_ops.py,sha256=VrOBIbain2ftHpBgxUHkf8fRpq1RCnsFi16tS-YGj6E,20640
|
|
@@ -12,9 +12,9 @@ bitsandbytes/disk_balancer.py,sha256=lyNgcqfBSsoflBDMffXKA4oNld4jBTbzugja988IN9w
|
|
|
12
12
|
bitsandbytes/efst.py,sha256=V3MGNwLicha2KmoFYmYM9RiEJCuU5Km8IsXDRWwXxXk,31222
|
|
13
13
|
bitsandbytes/functional.py,sha256=chLY-f592gXbSVOHA78ME3d-6Jq8rU3d2xJwx3GYDII,66814
|
|
14
14
|
bitsandbytes/gdn_cpu.py,sha256=QT5pdWwxPob6SL33wj4kjJLGnIkApivxvXjn7a--8Ys,27412
|
|
15
|
-
bitsandbytes/libbitsandbytes_cpu.dll,sha256=
|
|
15
|
+
bitsandbytes/libbitsandbytes_cpu.dll,sha256=RyZ135UuEnDbHfhMqRopatsAaR4puQGiGlF2fJd8qFU,402944
|
|
16
16
|
bitsandbytes/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
-
bitsandbytes/q3bit.py,sha256=
|
|
17
|
+
bitsandbytes/q3bit.py,sha256=ONdpCvu1EBG4Haq07-LqOBmlDzXHoTM749GYmvXpvcU,21760
|
|
18
18
|
bitsandbytes/torch_cpu_kit.py,sha256=P5Bk5jI86sT3Z2cleWDwv9XV0ydZ2rPflNdxOP2zzPU,32844
|
|
19
19
|
bitsandbytes/utils.py,sha256=G1oZbgIAt07m9-7SpLBRtIjsipI8kCptdfTWKz96g9I,6928
|
|
20
20
|
bitsandbytes/vcomp140.dll,sha256=ldTOSmgC0eGLXg4XIsww6nLKfgM_g4KPBcC3uZP-fL8,212920
|
|
@@ -43,6 +43,9 @@ bitsandbytes/diagnostics/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
|
|
|
43
43
|
bitsandbytes/diagnostics/cuda.py,sha256=O3907PxFrWr5gN34nDHgY7dWCaYcP2P5D35DYIlapGM,7256
|
|
44
44
|
bitsandbytes/diagnostics/main.py,sha256=08pFuKjQrltzVyj7F3ch31SPJcI6PGiSyVQts0GtTJo,4202
|
|
45
45
|
bitsandbytes/diagnostics/utils.py,sha256=ECiI279jh78977RWZFIOkmTJG4g1O_YiQLwP4iSa7Tw,284
|
|
46
|
+
bitsandbytes/fused/__init__.py,sha256=CqSK3nL9P1H50v0LZkZ8iXycsMGjfYU8h82WIdXwfFs,975
|
|
47
|
+
bitsandbytes/fused/_native.py,sha256=oUHOovpoDWUPrZKXne8rf3V9f85azRpMG7akJbxn7UY,2017
|
|
48
|
+
bitsandbytes/fused/_ref.py,sha256=d-Jv7O1EVX9a3Ig94PQwqqE8aGA49vHRkkRi79HA5uU,2404
|
|
46
49
|
bitsandbytes/nn/__init__.py,sha256=aTONEw0rCr5xTt9xw2X-sbpXJxcFg-MXNksFxXtgL_4,432
|
|
47
50
|
bitsandbytes/nn/modules.py,sha256=96shYGgeLwicqugNb9KDrGqbnxuCJp5vOVw7BG-vYG4,44262
|
|
48
51
|
bitsandbytes/nn/parametrize.py,sha256=tSc2Iij4q1J2evGdD7nVF8NY9dVdaR678kKW1Ve7bAM,8365
|
|
@@ -58,9 +61,9 @@ bitsandbytes/optim/lion.py,sha256=OUu1aysIM85NNHNFu-LDTCLI6HoqPNMp-bLVgZAGtHk,83
|
|
|
58
61
|
bitsandbytes/optim/optimizer.py,sha256=LgegbqBzbk5s57uCEgcmSqXC5wRHGMiAIbe646Fd3y4,28127
|
|
59
62
|
bitsandbytes/optim/rmsprop.py,sha256=2sHSY1hfTr83aZvBmIEfzoTiKER8LZc_BDkmyJG3lPs,6134
|
|
60
63
|
bitsandbytes/optim/sgd.py,sha256=gVjbjjYrm197RiOt6vLoXaMxaWVK6De91Ap_KL6WFtg,4916
|
|
61
|
-
bitsandbytes_cpu_fork-0.50.2.
|
|
62
|
-
bitsandbytes_cpu_fork-0.50.2.
|
|
63
|
-
bitsandbytes_cpu_fork-0.50.2.
|
|
64
|
-
bitsandbytes_cpu_fork-0.50.2.
|
|
65
|
-
bitsandbytes_cpu_fork-0.50.2.
|
|
66
|
-
bitsandbytes_cpu_fork-0.50.2.
|
|
64
|
+
bitsandbytes_cpu_fork-0.50.2.dev10.dist-info/licenses/LICENSE,sha256=UkEte8fOQVfqYou6rLiCngqcs8WPV_mRdhJryM8r_IU,1086
|
|
65
|
+
bitsandbytes_cpu_fork-0.50.2.dev10.dist-info/METADATA,sha256=KY_TkGnwz8p3DYlGd7Yjf4WC22KdQWEbWgZPP15JO-Q,22974
|
|
66
|
+
bitsandbytes_cpu_fork-0.50.2.dev10.dist-info/WHEEL,sha256=5s7VO_HUPfjwcO4LINqxGe8JSFZAGgaurQKPGA4cx_g,97
|
|
67
|
+
bitsandbytes_cpu_fork-0.50.2.dev10.dist-info/entry_points.txt,sha256=GqLu5Rm-j-9_CvhqX0jVecyJShA1XGmxRoPEiibJpcI,99
|
|
68
|
+
bitsandbytes_cpu_fork-0.50.2.dev10.dist-info/top_level.txt,sha256=l9ip7vjQq1JV6CB_ZGntWtjfxpkH119NDxupnJho9k0,34
|
|
69
|
+
bitsandbytes_cpu_fork-0.50.2.dev10.dist-info/RECORD,,
|
{bitsandbytes_cpu_fork-0.50.2.dev8.dist-info → bitsandbytes_cpu_fork-0.50.2.dev10.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|