Fix bitsandbytes CUDA Setup Failed Despite GPU Being Available & NF4 4-Bit Quantization OOM
RuntimeError: CUDA Setup failed despite GPU being available. Please run the following command to get more information
Root Cause & Memory Allocation Mechanics
Historically, `bitsandbytes` (`load_in_4bit=True` NF4 and `load_in_8bit=True` LLM.int8()) dynamically searched `LD_LIBRARY_PATH` at import time to dlopen `libcudart.so`. Whenever a Conda virtualenv or Docker container mixed system CUDA toolkit paths (e.g., `/usr/local/cuda-12.1`) with PyTorch's bundled pip runtime (`nvidia-cuda-runtime-cu12`), `libbitsandbytes_cuda*.so` failed to link and raised `CUDA Setup failed despite GPU being available`. A second trap occurs during `BitsAndBytesConfig(load_in_4bit=True)` loading: if you load a 16-bit FP16 checkpoint to quantize on-the-fly without `device_map='auto'`, Transformers stages full FP16 weights into VRAM before compressing them to 4-bit NF4, causing an instant OOM on 12GB–16GB GPUs!
Exact CLI Remediation Commands
# Run pre-quantized 4-bit models directly in Ollama without Python bitsandbytes compilation
ollama run llama3.1:8b-instruct-q4_K_M
# Upgrade bitsandbytes inside your project virtualenv and run its built-in diagnostics:
./.venv/bin/pip install -U "bitsandbytes>=0.45.3" "accelerate>=1.2.0" "transformers>=4.48.0"
./.venv/bin/python -m bitsandbytes
# Serve pre-quantized BitsAndBytes or AWQ checkpoints in vLLM without FP16 staging OOM:
vllm serve unsloth/Llama-3.1-8B-Instruct-bnb-4bit \
--quantization bitsandbytes \
--load-format bitsandbytes \
--max-model-len 8192
Upgrade VRAM on Amazon
If software quantization cannot bridge your memory deficit, explore 16GB–24GB GPUs.
Frequently Asked Questions
Why do I get a CUDA out of memory error while loading a 4-bit bitsandbytes model that should only take 6GB?
Quantizing an unquantized FP16 checkpoint on-the-fly loads each shard in 16-bit before converting it to 4-bit NF4. Download a pre-quantized `-bnb-4bit` repository (from `unsloth/` or HuggingFace) and always pass `device_map='auto'` and `bnb_4bit_compute_dtype=torch.bfloat16`.
Does bitsandbytes work natively on Windows 11 and AMD ROCm GPUs now?
Yes! Official `bitsandbytes >= 0.43.2+` includes native Windows `cudart64` wheels (no third-party `bitsandbytes-windows` fork needed—uninstall `bitsandbytes-windows` if present!) and multi-backend support for AMD ROCm HIP.
Verify Your Hardware Memory Math
Use the GPU Garden Matchmaker to calculate exact KV-cache footprints and avoid future OOM crashes.
Open Interactive Calculator →