Geforce 50xx系显卡最低支持cuda128,llama_cpp_python官方源只有cpu版本,没有cuda版本,所以自己基于0.3.5版本源码编译一个RTX 30xx/40xx/50xx版本。
1. 前置条件
1. 访问https://developer.download.nvidia.cn/compute/cuda/12.8.0/local_installers/cuda_12.8.0_571.96_windows.exe安装cuda12.8 toolkit, 安装完成后在命令行输入“nvcc -V”确认如下信息:
Cuda compilation tools, release 12.8, V12.8.61
2. 使用visual studio installer 安装visual studio 2022,工作负荷选择【使用c++的桌面开发】,安装完成后将“VC\Tools\MSVC\<版本号>\bin\Hostx64\x64”对1应的路径加入环境变量;
3. 访问https://github.com/abetlen/llama-cpp-python/archive/refs/tags/v0.3.5-metal.tar.gz下载源码(国内镜像),下载后解压; 访问 https://github.com/ggml-org/llama.cpp/archive/refs/tags/b4831.tar.gz下载源码(国内镜像),下载后解压到 “llama_cpp_python\vendor\llama.cpp”;
4. 访问https://github.com/conda-forge/miniforge/releases/download/24.11.3-0/Miniforge3-Windows-x86_64.exe安装miniforge;
2. 编译
conda create llama_build
conda activate llama_build
conda install ccahce
pip install build wheel
set CMAKE_ARGS=-DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=86;89;120
cd C:\llama_cpp_python
python -m build --wheel