Skip to content

How-ToGPU

How to Install llama-cpp-python With GPU Acceleration on Your PC

llama-cpp-python lets your own Python scripts run GGUF AI models locally, but getting it to use your graphics card trips many people up. Following the official README, we cover pre-built CUDA, AMD HIP, Vulkan and Metal wheels, building from source with CMAKE_ARGS, n_gpu_layers and common install fixes.

By , Systems & Technical Editor

4 min read

How to Install llama-cpp-python With GPU Acceleration on Your PC

llama-cpp-python is a free, MIT-licensed set of Python bindings for llama.cpp, the engine behind many local AI apps. It lets your own Python scripts load a GGUF model and generate text without a separate app running in the background. Getting it to use your graphics card is where most people struggle, so this guide covers the official install routes for NVIDIA, AMD and other GPUs. 3.38.

What you need

  • Python 3.8 or newer. That's the minimum the project lists. The pre-built CUDA and Metal wheels need Python 3.10, 3.11 or 3.12, so use one of those if you want to skip compiling.

  • A C compiler if you build from source. On Windows the README names Visual Studio or MinGW; on Linux gcc or clang; on a Mac Xcode.

  • A GGUF model file. If you're new to the format, our GGUF quantisation explainer covers which file to pick, and our guide to downloading models from Hugging Face shows where to get them.

It's best to work inside a Python virtual environment so a failed build doesn't affect anything else on your system.

Step 1: Decide between a pre-built wheel and a source build

A plain pip install llama-cpp-python builds llama.cpp from source on your PC. The project also publishes pre-built wheels. These are quicker to install and you don't need a compiler, but they only cover certain Python and CUDA versions. If something goes wrong, add --verbose to the pip command to see the full CMake build log.

Step 2: Install for your GPU

NVIDIA (CUDA), pre-built wheel. The README says a CUDA wheel works if your CUDA version is 11.8, 12.1, 12.2, 12.3, 12.4, 12.5, 13.0 or 13.2. For CUDA 12 wheels your GPU needs compute capability 6.0 or newer, and for CUDA 13 wheels 7.5 or newer. Add the index that matches your CUDA version, for example CUDA 12.4:

pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu124

Replace cu124 with cu118, cu121, cu122, cu123, cu125, cu130 or cu132 as needed.

NVIDIA (CUDA), from source. Set the CMake option before installing. In Windows PowerShell:

$env:CMAKE_ARGS = "-DGGML_CUDA=on"
pip install llama-cpp-python

AMD Radeon. On Windows, the project provides a HIP Radeon wheel (index .../whl/hip-radeon). On Linux there's a ROCm wheel (.../whl/rocm72). You can also build from source with -DGGML_HIP=on. Our guide to checking whether your AMD GPU supports ROCm is worth reading first.

Any Vulkan GPU. Vulkan wheels are available for Windows and Linux (index .../whl/vulkan), or you can build with -DGGML_VULKAN=on. This is a useful fallback for GPUs that don't have their own wheel. See CUDA vs ROCm vs Vulkan for local AI for the trade-offs.

Apple Silicon Mac. Use the Metal wheel (index .../whl/metal, macOS 11 or later) or build with -DGGML_METAL=on.

CPU only. A basic CPU wheel is available from the .../whl/cpu index.

Step 3: Load a model on the GPU

The setting that actually puts the model on your graphics card is n_gpu_layers. In the README's example it's commented out, so by default nothing is offloaded. Setting it to -1 offloads every layer:

from llama_cpp import Llama

llm = Llama(
    model_path="./models/your-model.gguf",
    n_gpu_layers=-1,   # put all layers on the GPU
    n_ctx=4096,        # context window
)
out = llm.create_chat_completion(
    messages=[{"role": "user", "content": "Explain what VRAM is in one sentence."}]
)
print(out["choices"][0]["message"]["content"])

If a model is too big for your VRAM, use a smaller number of layers so the rest runs on the CPU. Our VRAM guide for local AI explains how the context length adds to memory use. Responses come back in an OpenAI-style format. For chat, the library uses the chat template stored in the GGUF file's metadata unless you set chat_format yourself. Pass verbose=True to see which format it picked.

You can also download a model straight from Hugging Face with Llama.from_pretrained(repo_id=..., filename=...), which needs the huggingface-hub package installed.

Fixing common install problems

  • It installed but still runs on the CPU. First check you've set n_gpu_layers, because the default offloads nothing. If you have, you may have a CPU-only build. To rebuild, the README says to add --upgrade --force-reinstall --no-cache-dir to your pip command, with your CMAKE_ARGS set.

  • "Can't find nmake" or CMAKE_C_COMPILER on Windows. The README suggests extracting w64devkit and pointing CMAKE_GENERATOR and the compiler paths at it, or installing Visual Studio's C++ build tools.

  • Pre-built wheel not found. For CUDA wheels, check that your Python version is 3.10, 3.11 or 3.12 and that the CUDA index matches your installed CUDA version.

Do you need it?

If you just want to chat with a model, a ready-made app is simpler. See how to run AI models with Ollama or LM Studio. llama-cpp-python suits people writing their own Python tools who want the model loaded inside the script, with direct control over GPU layers and context. It also includes an OpenAI-compatible server, installed with pip install llama-cpp-python[server].

The bottom line

llama-cpp-python is the most direct way to run GGUF models from your own Python code. The main thing to get right is the install: pick the pre-built CUDA, HIP, Vulkan or Metal wheel that matches your Python and driver versions, or build from source with the right CMAKE_ARGS. Then set n_gpu_layers so the model actually loads onto your graphics card.

Sources

  1. 01llama-cpp-python official GitHub README
  2. 02llama-cpp-python on PyPI

About the author

Marcus Thorne

Systems & Technical Editor

Marcus writes Forge PC's step-by-step build, troubleshooting and system optimisation guides. His background spans Windows kernel and power-state diagnostics, UEFI/BIOS configuration, NVMe storage arrays, ATX 3.1 power delivery and running local AI and LLM workloads on consumer graphics cards.

More from Marcus Thorne

Read next

How to Add an Exclusion to Microsoft Defender in Windows 11 (Safely)

How-To

How to Add an Exclusion to Microsoft Defender in Windows 11 (Safely)

Microsoft Defender keeps flagging a file you trust? Rather than switching protection off, you can exclude a file, folder, file type or process in Windows Security. Following Microsoft's guidance, we show how to add and remove exclusions, use wildcards safely and what exclusions don't cover.

Marcus Thorne4 min

The Best NVIDIA App Features in 2026: What's Worth Using on a GeForce PC

Best Picks

The Best NVIDIA App Features in 2026: What's Worth Using on a GeForce PC

The NVIDIA App does far more than update drivers. Based on NVIDIA's official pages, we pick the features most worth using on a GeForce PC, from DLSS Override and Smooth Motion to Instant Replay, the performance overlay, RTX HDR and one-click GPU tuning, and explain who each suits.

Hannah Vance4 min