CUDA wheel installs, but GPU is never used on Windows 11 (Python 3.11, CUDA 12.1, torch finds GPU)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
该 issue 是在使用 CUDA 12.1 的 Windows 上静默回退到 CPU。首先检查 llama_cpp Python 绑定,尤其是 GPU 层分配逻辑和 Windows 特定的 DLL 加载。检查 cu121 wheel 的构建配置,并查找可能禁用 GPU 使用的环境变量或运行时检查。验证模型加载日志,查看是否请求了 GPU 层但被忽略。
由索引模型根据 Issue 内容生成。
描述
On Windows 11, with Python 3.11 and a CUDA 12.1-compatible NVIDIA GPU, I can successfully install llama-cpp-python via pip from the cu121 wheel, but no matter what, all model layers are always assigned to CPU only.
torch works and finds the GPU (torch.cuda.is_available() == True).
All paths and DLLs appear correct.
No errors, just silent fallback to CPU for every layer, even with n_gpu_layers set. Tried -1 and 32
I have confirmed this across multiple clean venvs and installs.
System Info
OS: Windows 11 Pro
GPU: NVIDIA RTX 4060 Ti, 16 GB VRAM
NVIDIA Driver Version: NVIDIA-SMI, 581.57
CUDA Toolkit Version: 12.1 (from PATH and NVIDIA tools)
Python Version: 3.11.x
llama-cpp-python Version: 0.3.16 (from pip show llama-cpp-python)
Installation Command:
pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu121
Model Used: Mistral 7B Q5_K GGUF (4.7GB)
What I Tried
Fresh venv (python -m venv envgpu311)
Confirmed correct Python version: where python → E:\envgpu311\Scripts\python.exe
pip list shows torch 2.5.1+cu121, llama-cpp-python 0.3.16
System PATH contains correct CUDA 12.1 bin directory
cudart64_121.dll is present in CUDA bin
Test script:
from llama_cpp import Llama
llm = Llama(model_path="E:/Python/Models/Mistral/lucian_model.gguf", n_ctx=512, n_gpu_layers=32, verbose=True)
print(llm("Hello, world!"))
Logs never mention CUDA or GPU, only assigned to device CPU for every layer.
torch tests pass:
import torch
print(torch.version) # 2.5.1+cu121
print(torch.cuda.is_available()) # True
Tried uninstalling all other venvs, cleaning PATH, and purging pip cache.
Also tried n_gpu_layers=-1 and 32 as stated above
What Happens
Model loads, runs, and produces output—but all layers go to CPU, no GPU assignment or CUDA logs, and performance matches CPU.
What I Expected
Layers assigned to GPU, CUDA logs in output, and at least some portion of the model running on GPU
Other Details
No error messages, just silent fallback to CPU.
Issue persists across all wheels and source builds tested.
pip show llama-cpp-python:
Name: llama_cpp_python
Version: 0.3.16
Location: E:\envgpu311\Lib\site-packages
Requires: diskcache, jinja2, numpy, typing-extensions
torch and other CUDA tools/apps detect GPU fine.
Latest NVIDIA driver installed 10/15/2025
- 主要语言
- Python
- 星标
- 10.7k
- 派生
- 1.5k
- 平均合并
- 1 小时 40 分钟
- 30 天内合并 PR
- 5
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
abetlen/llama-cpp-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
abetlen/llama-cpp-python#2424 ·
维护者通常 1 天内回复
-
Seven llama_sampler_init_* bindings admit keyword arguments that the ctypes function object silently drops可能已有人在做 @Belal0066 于 59 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
abetlen/llama-cpp-python#2371 ·
维护者通常 1 天内回复
-
uv add llama-cpp-python wheels fails for versions above 0.3.30可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
abetlen/llama-cpp-python#2352 · 1 条评论 · 3 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
abetlen/llama-cpp-python#2314 ·
维护者通常 1 天内回复
-
Llama.embed() calls LlamaBatch.add_sequence with old 3-arg signature; missing logits_array可能重新可做 @lxcxjxhx 于 136 天前认领,目前没有进行中的 PR。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
abetlen/llama-cpp-python#2211 · 2 条评论 ·
维护者通常 1 天内回复
查看 abetlen/llama-cpp-python 的全部 Issue
相似的 Issue
-
Bug IronPython Python 3
难度 2/5 1-3 小时 新手友好度 72/100
pyrevitlabs/pyRevit#4184 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 74/100
jqueryscript/awesome-claude-code#1009 ·
-
tests
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 74/100