bitsandbytes
Use bitsandbytes for k-bit PyTorch quantization, Hugging Face quantized model loading, 8-bit and paged optimizers, direct quantized layers/functions, and backend installation diagnostics.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- bitsandbytes
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Use bitsandbytes for k-bit PyTorch quantization, Hugging Face quantized model loading, 8-bit and paged optimizers, direct quantized layers/functions, and backend installation diagnostics.
- disable-model-invocation
- true
02 资源文件 6
- 参考文档references/installation-compatibility.md1.9 KB
- 参考文档references/performance-and-benchmarks.md1.7 KB
- 参考文档references/repo-provenance.md1.8 KB
- 参考文档references/repo-routing-metadata.json561 B
- 参考文档references/troubleshooting.md2.4 KB
- 脚本scripts/check-bitsandbytes-install.py1.6 KB
03 SKILL.md 正文
bitsandbytes
Use this repo skill when a task involves bitsandbytes, k-bit PyTorch quantization, LLM.int8(), QLoRA, 4-bit/NF4/FP4 layers, 8-bit optimizers, paged optimizers, or bitsandbytes install/backend failures.
Start Here
-
For any new environment, install with
pip install bitsandbytesand verify with:python -c "import bitsandbytes as bnb; print(bnb.__version__)" python -m bitsandbytes -
If import or backend diagnostics fail, route first to
sub-skills/installation-diagnostics/SKILL.md. -
If the user is using Hugging Face
BitsAndBytesConfig, route tosub-skills/transformers-integrations/SKILL.md. -
If the user is replacing layers or calling
bitsandbytes.functional, route tosub-skills/quantized-modules-functions/SKILL.md. -
If the user is choosing or debugging
bitsandbytes.optim, route tosub-skills/optimizers-training/SKILL.md.
Route Map
| User asks about | Use | Why |
|---|---|---|
pip install bitsandbytes, import bitsandbytes, python -m bitsandbytes, CUDA/ROCm/XPU/HPU/MPS/CPU support, missing libbitsandbytes_*, source builds, BNB_CUDA_VERSION, BNB_ROCM_VERSION |
sub-skills/installation-diagnostics/SKILL.md |
Owns install/backend compatibility and native library troubleshooting. |
Transformers, Diffusers, PEFT, Accelerate, BitsAndBytesConfig, load_in_8bit, load_in_4bit, NF4, QLoRA, FSDP-QLoRA |
sub-skills/transformers-integrations/SKILL.md |
Owns Hugging Face model-loading and finetuning integration patterns. |
Linear8bitLt, Linear4bit, LinearNF4, Embedding8bit, Params4bit, Int8Params, QuantState, quantize_4bit, int8 vectorwise quantization, direct matmul |
sub-skills/quantized-modules-functions/SKILL.md |
Owns direct module/function API usage and state-dict caveats. |
Adam8bit, AdamW8bit, PagedAdamW8bit, Lion8bit, AdEMAMix8bit, GlobalOptimManager, StableEmbedding, optimizer memory savings |
sub-skills/optimizers-training/SKILL.md |
Owns optimizer selection, training-loop integration, and state checks. |
Shared References and Scripts
- Read
references/repo-provenance.mdbefore deciding whether this skill matches a current bitsandbytes checkout or should be refreshed. - Read
references/troubleshooting.mdfor cross-cutting routing from symptoms to the right sub-skill. - Read
references/installation-compatibility.mdfor public install requirements and backend support summary. - Read
references/performance-and-benchmarks.mdbefore interpreting memory or speed claims. - Run
scripts/check-bitsandbytes-install.py --jsonfor a safe import/backend report that delegates to the bundled installation diagnostic helper.
Common Decision Points
BitsAndBytesConfigbelongs to Transformers, not to thebitsandbytespackage. Use the Transformers integration sub-skill for those configs.- CPU-only environments can validate imports, signatures, and some construction paths, but they do not prove CUDA/ROCm/XPU kernels or memory savings.
- Direct quantized layers usually quantize when moved to a real device with
.to(device). Construction on CPU is not the same as executing quantized kernels. - 8-bit optimizer memory savings depend on optimizer-state size; small tensors below
min_8bit_size=4096intentionally remain 32-bit. - Paged optimizers and many quantized model-loading paths need supported accelerator behavior and should not be promised from CPU-only checks.
Safe Validation Commands
python scripts/check-bitsandbytes-install.py --json
python sub-skills/installation-diagnostics/scripts/backend-report.py --json
python sub-skills/quantized-modules-functions/scripts/quantized-module-smoke.py --json
python sub-skills/optimizers-training/scripts/cpu-optimizer-smoke.py --optimizer adam8bit --steps 3
python sub-skills/transformers-integrations/scripts/transformers-bnb-config-check.py --mode qlora --json
Only run GPU or model-loading checks after confirming hardware, optional dependencies, model access, and that downloads or cache use are allowed.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).