Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

ggml_cuda_init: failed to initialize CUDA: (null) on Windows with CUDA 12.9

未关闭
#2,062 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
c, cmake, python

调研方向

该 issue 涉及在使用 CUDA 12.9 的 Windows 上 CUDA 初始化失败的问题。首先检查构建日志和 CMake 配置(GGML_CUDA 标志)。检查 llama.cpp 源代码中的 ggml_cuda_init 函数,以了解 CUDA runtime 检查。验证 CUDA toolkit 的安装、驱动兼容性和环境变量。在库外运行一个简单的 CUDA 测试程序有助于隔离问题。

由索引模型根据 Issue 内容生成。

描述

System Information:

  • OS: Windows
  • GPU: NVIDIA GeForce RTX 5060 Ti
  • NVIDIA Driver Version: 577.00
  • CUDA Version (from nvidia-smi): 12.9
  • Python Version: 3.12
  • Visual Studio: Visual Studio 2019 with "Desktop development with C++" workload

Problem Description:
I am unable to get llama-cpp-python to use my GPU. When I run a script to load a model with n_gpu_layers=-1, I get the error ggml_cuda_init: failed to initialize CUDA: (null), and all layers are
loaded on the CPU.

Troubleshooting Steps Taken:

  1. Installed llama-cpp-python using the following command in the "x64 Native Tools Command Prompt for VS 2019" with a Python virtual environment activated:
    1 set CMAKE_ARGS="-DGGML_CUDA=on" && pip install --upgrade --force-reinstall llama-cpp-python --no-cache-dir
  2. Verified that the command completes successfully, but the resulting installation does not use the GPU.
  3. Tried using the deprecated LLAMA_CUBLAS flag, which resulted in a build error (as expected).
  4. Performed a full cleanup of the environment:
    • pip uninstall llama-cpp-python
    • pip cache purge
    • Manually deleted leftover ~* directories from site-packages.
  5. Reinstalled after the cleanup, but the problem persists.
  6. Installed PyTorch with CUDA 12.1 support (pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121) before reinstalling llama-cpp-python, but this did not
    resolve the issue.
  7. Confirmed that the correct Python interpreter and virtual environment are being used.
  8. The run_with_llama_cpp.py script being used is:
1     from llama_cpp import Llama
2 
3     llm = Llama(
4       model_path="models/mistral-7b-instruct-v0.2.Q4_K_M.gguf",
5       n_gpu_layers=-1,
6       n_ctx=4096,
7       verbose=True
8     )
9 

10 output = llm(
11 "AI is going to ",
12 max_tokens=32,
13 stop=["."],
14 echo=True
15 )
16
17 print(output)

Request:
Could you please provide any insights into why the CUDA initialization might be failing, or suggest any further diagnostic steps? I can provide the full verbose build log if needed.

主要语言
Python
星标
10.6k
派生
1.5k
平均合并
3 小时 57 分钟
30 天内合并 PR
4

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

abetlen/llama-cpp-python 的其他 Issue

查看 abetlen/llama-cpp-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。