High severity intermediate · Fix: 15-30 min

RuntimeError

llamacpp.RuntimeError: CUDA build not found, CPU fallback

What this error means
llama.cpp failed to find a CUDA GPU build and fell back to CPU execution, causing slower performance.

Stack trace

traceback
RuntimeError: CUDA build not found, CPU fallback
  File "llamacpp.py", line 45, in load_model
    model = Llama(model_path, use_cuda=True)  # triggers error
  File "llamacpp.py", line 120, in __init__
    raise RuntimeError("CUDA build not found, CPU fallback")
QUICK FIX
Rebuild llama.cpp with CUDA support and verify CUDA drivers are installed to avoid CPU fallback.

Why it happens

llama.cpp requires a CUDA-enabled GPU build to run on GPU. If the CUDA build is missing or incompatible, it falls back to CPU execution. This happens when the environment lacks the proper CUDA toolkit, drivers, or the llama.cpp library was compiled without CUDA support.

Detection

Check logs for 'CUDA build not found' RuntimeError during model initialization. Monitor GPU usage; if zero, the model is running on CPU fallback.

Causes & fixes

1

llama.cpp library was compiled without CUDA support

✓ Fix

Rebuild or reinstall llama.cpp with CUDA enabled by following the official build instructions for GPU support.

2

CUDA toolkit or drivers are missing or incompatible on the system

✓ Fix

Install the correct CUDA toolkit and GPU drivers matching your GPU and llama.cpp CUDA build requirements.

3

Environment variable or configuration disables CUDA usage

✓ Fix

Ensure the llama.cpp initialization parameter 'use_cuda=True' is set and no environment variables disable GPU usage.

Code: broken vs fixed

Broken - triggers the error
python
from llamacpp import Llama

model = Llama("model.bin", use_cuda=True)  # triggers RuntimeError: CUDA build not found, CPU fallback
print("Model loaded")
Fixed - works correctly
python
import os
from llamacpp import Llama

# Ensure CUDA environment variables and drivers are set
os.environ["CUDA_VISIBLE_DEVICES"] = "0"

model = Llama("model.bin", use_cuda=True)  # fixed: CUDA build found and used
print("Model loaded with CUDA support")
Set environment variables and ensure llama.cpp is built with CUDA support so use_cuda=True activates GPU usage instead of CPU fallback.

Workaround

Run llama.cpp without use_cuda=True to explicitly use CPU mode until CUDA support is fixed, accepting slower performance.

Prevention

Set up continuous integration to verify llama.cpp builds with CUDA enabled and test GPU availability before deployment to prevent fallback.

Python 3.8+ · llamacpp >=0.1.0 · tested on 0.2.0
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.