Quick answer
"bitsandbytes CUDA Setup failed" means bitsandbytes could not find a CUDA binary that matches your setup, so it fell back to the CPU-only library. Fix it in order: confirm torch.cuda.is_available() is True, because bitsandbytes needs a CUDA build of PyTorch; upgrade bitsandbytes with pip install -U bitsandbytes, which resolves most modern cases; then, if libcudart still isn't found, add the CUDA libraries to LD_LIBRARY_PATH or set BNB_CUDA_VERSION to override the detected version.
You try to load a model in 8-bit or 4-bit (QLoRA, load_in_4bit=True) and
bitsandbytes stops you:
RuntimeError: CUDA Setup failed despite GPU being available. Please run the
following command to get more information: python -m bitsandbytesOlder versions dump a wall of CUDA SETUP: lines and, crucially, a line like:
CUDA SETUP: Loading binary .../libbitsandbytes_cpu.so...That _cpu.so line is the whole story. bitsandbytes ships different compiled
binaries for different CUDA versions. When it can't find one that matches your
setup, it falls back to the CPU-only binary — which can't run GPU
quantization, so it raises this error.
So this is not really a mysterious CUDA bug. It's "bitsandbytes couldn't find its GPU binary." This guide fixes that in the order that resolves the most cases with the least effort — and the first real fix is usually just an upgrade.
Quick Answer
bitsandbytes CUDA Setup failed means no matching CUDA binary was found, so
bitsandbytes loaded the CPU library. Fix it in order: confirm
torch.cuda.is_available() is True (bitsandbytes needs a CUDA PyTorch),
pip install -U bitsandbytes (resolves most modern cases), then if
libcudart still isn't found, add the CUDA libs to LD_LIBRARY_PATH or set
BNB_CUDA_VERSION.
TL;DR
- The signal:
libbitsandbytes_cpu.soloaded → no CUDA binary matched. - Fix 1 (most cases):
pip install -U bitsandbytes. - Prerequisite: a CUDA build of PyTorch —
torch.cuda.is_available()must beTrue. - libcudart missing? Add CUDA libs to
LD_LIBRARY_PATH, runldconfig. - Version mismatch / multiple toolkits?
BNB_CUDA_VERSION=122+ matching path. - Windows: upgrade to official wheels; the old
bitsandbytes-windowsfork is dead. - Diagnose:
python -m bitsandbytesprints a full setup report.
The Signal: Which Binary Loaded
When you import bitsandbytes, it detects your GPU and the CUDA version that
PyTorch was built with, then looks for a compiled binary named like
libbitsandbytes_cuda121.so. Two outcomes:
- Match found → the CUDA binary loads, and 8-bit/4-bit kernels work.
- No match → it loads
libbitsandbytes_cpu.soand reports CUDA Setup failed.
So the fix is always "make a matching CUDA binary loadable." Everything below is a different reason that match is failing.
First, Run the Built-in Diagnostic
bitsandbytes ships a self-check. Run it before changing anything:
python -m bitsandbytesIt reports your PyTorch CUDA version, the detected GPU, which binary it's trying
to load, and whether it found libcudart. Read the last few lines — they usually
name the exact problem (no CUDA torch, missing libcudart, or version mismatch).
Step-by-step Solution
Step 1: Confirm PyTorch actually has CUDA
bitsandbytes rides on PyTorch's CUDA. If PyTorch itself is CPU-only, bitsandbytes can never succeed — fix that first:
import torch
print(torch.cuda.is_available()) # must be True
print(torch.version.cuda) # must be a version, not NoneIf this is False or None, stop here and fix PyTorch — see
fixing torch.cuda.is_available() returns False.
Chasing bitsandbytes while PyTorch is CPU-only wastes hours.
This is the most common misdiagnosis. People see "bitsandbytes" in the error and
reinstall bitsandbytes ten times, when the real problem is a CPU-only PyTorch
wheel one layer down. Check torch.cuda.is_available() first, every time.
Step 2: Upgrade bitsandbytes (the fix for most cases)
Older bitsandbytes had fragile CUDA detection and shipped binaries for only a handful of CUDA versions. Modern releases detect the environment far better and bundle binaries for the full CUDA 11–12 range, so an upgrade alone resolves the majority of these reports:
pip install -U bitsandbytes
python -m bitsandbytes # re-check: should now find a CUDA binary-U→ upgrade to the latest release.- If you're on a locked version for another dependency, upgrade to the newest one that dependency allows — even a minor bump often fixes detection.
Step 3: Make libcudart findable
If the diagnostic says libcudart.so not found in any environmental path,
bitsandbytes can't locate the CUDA runtime. Point the loader at it:
# Find the CUDA runtime library
find / -name "libcudart.so*" 2>/dev/null
# Add its directory to the library path (adjust the path to your CUDA install)
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
sudo ldconfig # refresh the linker cacheLD_LIBRARY_PATH→ tells the dynamic loader where to findlibcudart.ldconfig→ rebuilds the linker cache so the change takes effect.- Put the
exportin your shell profile or job script so it persists.
Step 4: Override the CUDA version for mismatches
If you have multiple CUDA toolkits installed, or bitsandbytes picks a version that doesn't match what's actually available, override the detection:
export BNB_CUDA_VERSION=122 # e.g. force the CUDA 12.2 binary
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-12.2/lib64BNB_CUDA_VERSION=122→ forces bitsandbytes to load thecuda122binary instead of PyTorch's default.- Always pair it with an
LD_LIBRARY_PATHthat actually contains that version's libraries, or you've just picked a binary that still can't find its runtime.
Platform-Specific Notes
Windows
The historical answer — "install the bitsandbytes-windows fork" — is obsolete
and wrong now. Current bitsandbytes provides official Windows wheels:
pip uninstall -y bitsandbytes bitsandbytes-windows
pip install -U bitsandbytesThe LD_LIBRARY_PATH and ldconfig steps are Linux-only. On Windows, a current
wheel plus a working CUDA PyTorch is normally all you need.
WSL2
Treat WSL2 as Linux, but the driver comes from Windows (see the WSL notes in
the torch.cuda guide). Once
nvidia-smi and torch.cuda.is_available() work inside WSL2, upgrade
bitsandbytes and it typically resolves.
Docker / clusters
- Base your image on an official CUDA image (
nvidia/cuda:...-runtimeor PyTorch's CUDA image) solibcudartis present. - Run with
--gpus all. - On HPC clusters,
module load cuda/12.xbefore running, and confirm you're on a GPU node — a login node has no GPU and bitsandbytes will fall back to CPU.
Colab / Kaggle
Usually just an upgrade: pip install -U bitsandbytes, then restart the
runtime so the new binary is imported. Re-running the cell without restarting
keeps the old, failed import cached.
Verification Steps
python -m bitsandbytesreports a CUDA binary loaded (not_cpu.so) and no errors.- A real 4-bit load succeeds:
import torch
from transformers import AutoModelForCausalLM, BitsAndBytesConfig
bnb = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.float16)
model = AutoModelForCausalLM.from_pretrained(
"facebook/opt-350m", quantization_config=bnb, device_map="auto",
)
print(next(model.parameters()).device) # cuda:0- The model's parameters report
cuda:0, andnvidia-smishows GPU memory in use. - No
CUDA Setup failedand no_cpu.soline on import.
Green state: python -m bitsandbytes loads a cudaXXX binary, a 4-bit model
lands on cuda:0, and nvidia-smi shows the memory. That's the full path
working end to end.
The Diagnostic Ladder
Follow it top to bottom — each rung is more effort than the last, and most people never get past rung 2:
torch.cuda.is_available()False? Fix PyTorch first.- bitsandbytes out of date?
pip install -U bitsandbytes. libcudartnot found?LD_LIBRARY_PATH+ldconfig.- Multiple toolkits / mismatch?
BNB_CUDA_VERSION+ matching path. - Still failing? Reinstall in the active environment.
Prevention
- Pin a recent
bitsandbytesin requirements; don't inherit an ancient one. - Install a CUDA PyTorch from the correct index before bitsandbytes.
- In Docker, start from an official CUDA base image so
libcudartexists. - Keep bitsandbytes, PyTorch, and the driver upgrades together, not piecemeal.
- Run
python -m bitsandbytesin CI to catch a broken setup before deploy. - On Windows, use official wheels — never the deprecated fork.
- Restart the runtime/kernel after upgrading so the new binary is imported.
Troubleshooting Matrix
| Symptom | Likely cause | Fix |
|---|---|---|
Loads libbitsandbytes_cpu.so | No matching CUDA binary | Upgrade bitsandbytes |
torch.cuda.is_available() False | CPU-only PyTorch | Fix PyTorch first |
libcudart.so not found | Runtime not on path | LD_LIBRARY_PATH + ldconfig |
Works after BNB_CUDA_VERSION set | Version mismatch | Keep the override + matching path |
| Fails on Windows | Old/forked package | Official wheels via pip install -U |
| Fails on a cluster login node | No GPU on that node | Run on a GPU node |
| Fails after upgrade in a notebook | Old import cached | Restart the runtime |
| Fine locally, fails in Docker | No CUDA runtime in image | Use a CUDA base image |
Related Guides
- Fix torch.cuda.is_available() returns False
- Resolve CUDA error: device-side assert triggered
- Resolve OSError: Can't load tokenizer
- Resolve Hugging Face 401 Unauthorized
- A practical guide to 4-bit QLoRA fine-tuning
External References
- bitsandbytes documentation
- bitsandbytes — installation & troubleshooting
- bitsandbytes releases (GitHub)
- PyTorch — Get Started (install selector)
FAQs
Why does the error say "despite GPU being available"?
Because bitsandbytes can see a GPU — the driver and nvidia-smi are fine — but
it still couldn't load a CUDA binary that matches. The GPU being present rules out
"no hardware"; the failure is in the binary/runtime match, not the card.
I upgraded and it still fails — what next?
Run python -m bitsandbytes and read the last lines. If it names libcudart, do
Step 3. If it shows a version mismatch, do Step 4. Also confirm you upgraded in
the same environment you're running — a different venv is a common miss.
Can I run bitsandbytes without a GPU?
Not for GPU quantization. The CPU fallback exists but does not provide the 8-bit
and 4-bit CUDA kernels, so load_in_4bit/load_in_8bit require a working CUDA
setup.
Does bitsandbytes need to match my PyTorch CUDA version exactly?
It needs a compatible binary, not a byte-exact match. Modern releases bundle a
range and detect the right one. When detection is wrong, BNB_CUDA_VERSION lets
you force the correct binary.
Is python -m bitsandbytes safe to run in production images?
Yes — it's a read-only diagnostic. Running it during the Docker build is a good
way to fail fast if the CUDA setup is broken before the image ships.
Key takeaways
- •The error means no matching CUDA binary was found, so bitsandbytes loaded the CPU-only library instead.
- •Seeing libbitsandbytes_cpu.so load is the diagnostic signal — it confirms CUDA detection failed.
- •Upgrading with pip install -U bitsandbytes fixes the majority of modern cases thanks to better detection and bundled binaries.
- •bitsandbytes needs a CUDA build of PyTorch first — if torch.cuda.is_available() is False, fix that before anything else.
- •If libcudart is not found, add the CUDA runtime libraries to LD_LIBRARY_PATH and run ldconfig.
- •For multiple CUDA toolkits or a version mismatch, override detection with BNB_CUDA_VERSION and a matching LD_LIBRARY_PATH.
Frequently asked questions
What does "bitsandbytes CUDA Setup failed" mean?
It means bitsandbytes could not load a CUDA binary that matches your GPU and CUDA runtime, so it fell back to the CPU-only library and refused to run GPU quantization. The cause is almost always an outdated bitsandbytes, a CPU-only PyTorch, or CUDA runtime libraries that are not on the library path.
How do I fix bitsandbytes CUDA Setup failed?
First run python -c "import torch; print(torch.cuda.is_available())" — if it is False, fix PyTorch first. Then upgrade: pip install -U bitsandbytes, which resolves most cases. If it still fails, run python -m bitsandbytes; if libcudart is missing, add the CUDA libs to LD_LIBRARY_PATH and run ldconfig.
Why does bitsandbytes load libbitsandbytes_cpu.so?
Because it could not find a CUDA binary that matches your setup. The CPU library is the fallback. Loading it is the signal that CUDA detection failed — the GPU kernels are not available, which is why 8-bit and 4-bit loading errors out.
Does bitsandbytes need the CUDA Toolkit installed?
Modern bitsandbytes ships prebuilt CUDA binaries, so a full system CUDA Toolkit is usually unnecessary — but it does need the CUDA runtime libraries (libcudart) reachable, which normally come with your NVIDIA driver or PyTorch. It also requires a CUDA build of PyTorch. Upgrading bitsandbytes handles most binary mismatches automatically.
How do I fix bitsandbytes on Windows?
Upgrade to a current bitsandbytes release, which provides official Windows wheels — pip install -U bitsandbytes. Do not use the old unofficial bitsandbytes-windows fork; it is obsolete. LD_LIBRARY_PATH advice is Linux-only and does not apply on Windows.
What does BNB_CUDA_VERSION do?
It overrides the CUDA version bitsandbytes detects from PyTorch. If you have multiple CUDA toolkits or a mismatch, set BNB_CUDA_VERSION to your target version (for example 122 for CUDA 12.2) and add that toolkit's libraries to LD_LIBRARY_PATH so bitsandbytes loads the matching binary.