Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

bitsandbytes

License Downloads Nightly Unit Tests GitHub Release PyPI - Python Version

bitsandbytes enables accessible large language models via k-bit quantization for PyTorch. We provide three main features for dramatically reducing memory consumption for inference and training:

  • 8-bit optimizers uses block-wise quantization to maintain 32-bit performance at a small fraction of the memory cost.
  • LLM.int8() or 8-bit quantization enables large language model inference with only half the required memory and without any performance degradation. This method is based on vector-wise quantization to quantize most features to 8-bits and separately treating outliers with 16-bit matrix multiplication.
  • QLoRA or 4-bit quantization enables large language model training with several memory-saving techniques that don't compromise performance. This method quantizes a model to 4-bits and inserts a small set of trainable low-rank adaptation (LoRA) weights to allow training.

The library includes quantization primitives for 8-bit & 4-bit operations, through bitsandbytes.nn.Linear8bitLt and bitsandbytes.nn.Linear4bit and 8-bit optimizers through bitsandbytes.optim module.

System Requirements

bitsandbytes has the following minimum requirements for all platforms:

  • Python 3.10+
  • PyTorch 2.4+
    • Note: While we aim to provide wide backwards compatibility, we recommend using the latest version of PyTorch for the best experience.

Accelerator support:

Note: this table reflects the status of the current development branch. For the latest stable release, see the document in the 0.50.0 tag.

Legend:

🚧 = Planned | 〰️ = Partially Supported | ✅ = Supported | ❌ = Not Supported

Platform Accelerator Hardware Requirements LLM.int8() QLoRA 4-bit 8-bit Optimizers
🐧 Linux, glibc >= 2.24
x86-64 ◻️ CPU Minimum: AVX2
Optimized: AVX512F, AVX512BF16
✅ ✅ ✅
🟩 NVIDIA GPU
cuda
SM60+ minimum
SM75+ recommended
✅ ✅ ✅
🟥 AMD GPU
cuda
CDNA: gfx908, gfx90a, gfx942, gfx950, gfx1250
RDNA: gfx103X, gfx110X, gfx115X, gfx120X
✅ ✅ ✅
🟦 Intel GPU
xpu
Data Center GPU Max Series
Arc A-Series (Alchemist)
Arc B-Series (Battlemage)
✅ ✅ ✅
🟪 Intel Gaudi
hpu
Gaudi2, Gaudi3 ✅ 〰️ ❌
aarch64 ◻️ CPU ✅ * ✅ ✅
🟩 NVIDIA GPU
cuda
SM75+ ✅ ✅ ✅
🪟 Windows 11 / Windows Server 2022+
x86-64 ◻️ CPU AVX2 ✅ ✅ ✅
🟩 NVIDIA GPU
cuda
SM60+ minimum
SM75+ recommended
✅ ✅ ✅
🟥 AMD GPU
cuda
RDNA: gfx103X, gfx110X, gfx115X, gfx120X ✅ ✅ ✅
🟦 Intel GPU
xpu
Arc A-Series (Alchemist)
Arc B-Series (Battlemage)
✅ ✅ ✅
arm64 ◻️ CPU ✅ ✅ ✅
🟩 NVIDIA GPU
cuda
SM121 ✅ ✅ ✅
🍎 macOS 14+
arm64 ◻️ CPU Apple M1+ ✅ * ✅ ✅
⬜ Metal
mps
Apple M1+ ✅ * ✅ 🚧
* While supported, these marked features may lack in performance optimizations.

📖 Documentation

💻 CPU Backend Extensions (this fork)

This fork adds training-grade CPU kernels to the bitsandbytes CPU backend, for machines without NVIDIA GPUs (AVX2 only / ARM64 NEON, e.g. consumer laptops, Mini-PCs). The upstream CPU backend is inference-oriented; these extensions make pure-CPU LoRA / quantization / diffusion training practical.

📚 Docs (docs_cpu/):

  • TECHNICAL_GUIDE.md — 技术文档:改了什么、每个内核的架构与细节(面向技术人员)
  • QUICKSTART.md — 快速入门手册:命令、用途与参数(面向首次使用者)
  • TECH_REPORT.md — 技术报告:完整方法论、实验数据与结论(含负面结论)
  • 灾难恢复指南已并入 QUICKSTART.md §9。
  • 🌐 English: 英文为独立文件 —— QUICKSTART_EN.md、TECHNICAL_GUIDE_EN.md、 TECH_REPORT_EN.md(内容与中文版对应,以中文为准;灾难恢复同样在 QUICKSTART_EN.md §9)。

🌐 English README: see README_EN.md.

关于硬盘均衡负载:它能在内存紧张时帮助维持训练,但不能替代 Windows 虚拟内存。 训练期间仍建议保留至少 1GB 虚拟内存以应对突发内存峰值。

What's added

Kernel Entry point Purpose
Gated DeltaNet fwd/bwd gdn_fwd_cpu / gdn_bwd_cpu (csrc/cpu_gdn.cpp) Fused Gated DeltaNet (Qwen3-Next/3.5 linear attention) — ~35× vs per-step Python loop; chunk-checkpointed backward
Fused 8-bit blockwise dequant GEMM cgemm_8bit_inference_cpu_fp32 (bitsandbytes::gemm_8bit, bnb.functional.fused_dequant_linear_8bit) out = A @ dequant8(B) with weights kept uint8 (¼ DRAM traffic), no fp32 temporary
Fused 8-bit optimizer coptimizer_update_8bit_blockwise_cpu (bnb.optim.AdamW8bit etc.) Single-pass dequant→update→requant; optimizer state memory ≈ 1/3.8 of fp32
Blockwise 8/4-bit quant & dequant cquantize_blockwise_cpu_* / cdequantize_blockwise_cpu_* AVX2 LUT quantize + dequantize; NF4/FP4 kernels with NEON/AVX2 paths
4-bit inference GEMV cgemv_4bit_inference_cpu_* Fused 4-bit dequant GEMV/GEMM for AVX2 machines (symbol alias fixed)
GDN runtime patch bitsandbytes/gdn_cpu.py patch_transformers() / patch_fla() — route transformers GDN slow paths to the fused kernel
iGPU (DirectML) block-level executor gpu_scheduler.py (IgpuExecutor, train.py --igpu) Experimental: frozen weights resident on the DirectML iGPU, forward/backward on-device, one sync per step; off by default — measured +30~35% for GEMM-dense seq≤256 training, negative at long sequences (driver limits)

Build

# Linux (x86_64 AVX2 or aarch64 NEON, g++/clang + OpenMP)
# deps: sudo apt install g++ libomp-dev   (Debian/Ubuntu)
bash build_linux.sh            # -> bitsandbytes/libbitsandbytes_cpu.so
bash build_linux.sh --selftest # also build+run torch-free C self-test

# Windows (MSVC, manual cl build, no CMake)
build_manual\build_manual.bat amd   # (in VS x64 Native Tools prompt)

.gitattributes 强制 C/C++ 源码与构建脚本用 LF 换行,clone 到 Windows/Linux 均可 直接编译(CRLF 会让 MSVC 吞行、Linux g++ 报 bad interpreter)。 disk_balancer(--flash)跨平台:Windows 用 ctypes,Linux/WSL 用 psutil。

Prebuilt wheels (optional)

预编译的 wheel(pip install bitsandbytes-<ver>-py3-none-<platform>.whl)可从 Release 获取,无需自己编译(Windows win_amd64 / Linux linux_x86_64 / aarch64 linux_aarch64)。wheel 内含 bitsandbytes/ 包 + 编译好的 native 库 (.dll/.so),安装即用。

Self-test (no torch required)

# C-level kernel self-test: quantize roundtrip / gemm_8bit / 4bit GEMV / 8bit optimizer
bash build_linux.sh --selftest

Notes

  • This fork is based on bitsandbytes v0.45.1 (MIT, Facebook) and keeps the upstream MIT license. See NOTICE.md for contributions.
  • The CPU backend keeps the upstream NEON/AVX paths for plain quant/dequant; the fused training kernels (GDN, gemm_8bit, 8-bit optimizer) are the addition of this fork.
  • Not recommended for use without the compiled native library — build first (Windows: build_manual\build_manual.bat amd, Linux: build_linux.sh).

❤️ Sponsors

The continued maintenance and development of bitsandbytes is made possible thanks to the generous support of our sponsors. Their contributions help ensure that we can keep improving the project and delivering valuable updates to the community.

Hugging Face

License

bitsandbytes is MIT licensed.

How to cite us

If you found this library useful, please consider citing our work:

QLoRA

@article{dettmers2023qlora,
  title={Qlora: Efficient finetuning of quantized llms},
  author={Dettmers, Tim and Pagnoni, Artidoro and Holtzman, Ari and Zettlemoyer, Luke},
  journal={arXiv preprint arXiv:2305.14314},
  year={2023}
}

LLM.int8()

@article{dettmers2022llmint8,
  title={LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale},
  author={Dettmers, Tim and Lewis, Mike and Belkada, Younes and Zettlemoyer, Luke},
  journal={arXiv preprint arXiv:2208.07339},
  year={2022}
}

8-bit Optimizers

@article{dettmers2022optimizers,
  title={8-bit Optimizers via Block-wise Quantization},
  author={Dettmers, Tim and Lewis, Mike and Shleifer, Sam and Zettlemoyer, Luke},
  journal={9th International Conference on Learning Representations, ICLR},
  year={2022}
}

Metadata

Release files for bitsandbytes-cpu-fork 0.50.2.dev0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bitsandbytes-cpu-fork 0.50.2.dev0
File Size Uploaded Provenance Actions
bitsandbytes_cpu_fork-0.50.2.dev0.tar.gz 923.1 kB Without provenance Details for bitsandbytes_cpu_fork-0.50.2.dev0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bitsandbytes-cpu-fork 0.50.2.dev0
File Interpreter ABI Platform Actions
bitsandbytes_cpu_fork-0.50.2.dev0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for bitsandbytes_cpu_fork-0.50.2.dev0-py3-none-win_amd64.whl

Total release size: 1.3 MB

Release files / bitsandbytes_cpu_fork-0.50.2.dev0.tar.gz

Download URL bitsandbytes_cpu_fork-0.50.2.dev0.tar.gz
Size 923.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1829cb77065386d4d62961bd5c91b0bf5003ab370a4e8c07f6ff455a8bb7fefb
BLAKE2b-256 checksum
How to use checksums
54ab474c0409697c8e22a25f2e7c035acddb963caaaa02c2070d562acc996d09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.3

Release files / bitsandbytes_cpu_fork-0.50.2.dev0-py3-none-win_amd64.whl

Download URL bitsandbytes_cpu_fork-0.50.2.dev0-py3-none-win_amd64.whl
Size 400.2 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
eefdccd126006cfd31df816b5b11ee21052d88997387b885318422bbb7737d80
BLAKE2b-256 checksum
How to use checksums
94d0e8a59b31e9783dd912582efe0414449f729cf146c0e5c113a4bdc1667413
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.3

Security for bitsandbytes-cpu-fork 0.50.2.dev0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page