Win7编译GPU版llama.cpp部署deepseek-r1等大模型记录

发布于:2025-02-18 ⋅ 阅读:(37) ⋅ 点赞:(0)

概述

本文是一个测试记录,供参考。

目标是在Windows7系统下,实现llama.cpp的CPU编译、GPU编译,实现大模型的单机部署。

GPU编译运行成功,但运行时没有调用GPU。

感谢“一只喜欢摄影的程序猿”的评论,在Windows7确实可以安装 cuda 11.6,我的情况是安装过程没报错,但是cuda11.6无效。

参考链接

Win7本地化部署deepseek-r1等大模型详解

测试环境:

显卡:NVIDIA Geforce GTX 970
CPU: i7-4790K 
内存:32GB DDR3
系统:Windows7 旗舰版 X64 SP1

准备工作:

下载Win7镜像,U盘安装操作系统
下载geek uninstaller,删除乱七八糟软件
安装火绒杀毒,查杀系统,安装火绒商店
从火绒商店安装7zip、notepad--、手心输入法、CPU-Z、Everything、GPU-Z

从 https://developer.nvidia.com/cuda-10.2-download-archive 下载 cuda_10.2.89_441.22_windows.exe
从 https://developer.nvidia.com/cuda-11-6-0-download-archive 下载 cuda_11.6.0_511.23_windows.exe

安装:

w64devkit-x64-2.1.0.exe,自解压到 D:\dev\dev-tools\w64devkit\w64devkit.exe
cmake-3.31.5-windows-x86_64.msi,默认位置,C:\Program Files\CMake\
Git-2.45.2-64-bit.exe,默认位置,C:\Program Files\Git
Firefox 18.5.0.0.exe,默认位置,C:\Program Files\Mozilla Firefox

CPU版,MinGW64编译配置:

创建临时目录
    D:\dev\dev-tools\llama.cpp.win7.cpu
找到源码,llama.cpp.2025-02-08.4d3465c5aeca8be29cac77f1535c35f4fb274eca.zip,解压到上面的目录,解压后路径如下
    D:\dev\dev-tools\llama.cpp.win7.cpu\README.md
修改源码 
    D:\dev\dev-tools\llama.cpp.win7.cpu\examples\server\httplib.h
双击运行 D:\dev\dev-tools\w64devkit\w64devkit.exe
cd d:/dev/dev-tools/llama.cpp.win7.cpu/
cmake . -G "MinGW Makefiles"
cmake --build . --config Release -j 8

说明,由于测试机有8个CPU核心,所以可以用 -j 8 并行编译,快一些。

CPU版编译完成,程序在 D:\dev\dev-tools\llama.cpp.win7.cpu\bin 目录

测试

任意位置启动CMD.exe,输入 llama-server --model model_path, 打开火狐浏览器,输入 http://127.0.0.1:8080,可以问答

`D:\dev\dev-tools\llama.cpp.win7.cpu\bin\llama-server.exe --model D:\dev\deepseek-r1_1.5b.gguf --threads 8`
14token/s, deepseek-r1:1.5B

`D:\dev\dev-tools\llama.cpp.win7.cpu\bin\llama-server.exe --model D:\BaiduNetdiskDownload\sha256-6e9f90f02bb3b39b59e81916e8cfce9deb45aeaeb9a54a5be4414486b907dc1e --threads 8`
 2.4token/s deepseek-r1:14B 

`D:\dev\dev-tools\llama.cpp.win7.cpu\bin\llama-server.exe --model D:\BaiduNetdiskDownload\sha256-6150cb382311b69f09cc0f9a1b69fc029cbd742b66bb8ec531aa5ecf5c613e93 --threads 8`
1.1 token/s  deepseek-r1:30B

CPU版,VS2015编译配置

安装VS2019,用Visual Studio 2019 完整离线安装包,需要勾选C++桌面开发的推荐内容,另外勾选2015兼容工具

启动VS2019中的VS2015兼容性工具

VS2015 X64 X86兼容工具
set path=C:\Program Files\CMake\bin;C:\Program Files\Git\cmd;%path%
cd /d D:\dev\dev-tools\llama.cpp.win7.vs2015.cpu
cmake -B build
cmake --build build --config Release      大量警告

cd D:\dev\dev-tools\llama.cpp.win7.vs2015.cpu\build\bin\Release

llama-server --model D:\dev\deepseek-r1_1.5b.gguf
1.5B, 你好,18token/s

llama-server --model D:\BaiduNetdiskDownload\sha256-6e9f90f02bb3b39b59e81916e8cfce9deb45aeaeb9a54a5be4414486b907dc1e
14B, 你好, 2.6 token/s

CPU版,VS2019编译配置

启动VS2019中的VS2019兼容性工具

VS2019 X64 X86兼容工具
set path=C:\Program Files\CMake\bin;C:\Program Files\Git\cmd;%path%
cd /d D:\dev\dev-tools\llama.cpp.win7.vs2019.cpu
cmake -B build
cmake --build build --config Release      大量警告
cd D:\dev\dev-tools\llama.cpp.win7.vs2019.cpu\build\bin\Release

llama-server --model D:\dev\deepseek-r1_1.5b.gguf
1.5B, 你好,18.8token/s

GPU版,VS2019编译配置,成功一半

安装CUDA 10.2,Win7安装,可使用,支持Win7的最高CUDA版本
安装CUDA 11.6,Win7可安装,我的测试机是Win7无法使用cuda11.6的

启动VS2019中的VS2019兼容性工具

REM VS2019 X64 X86兼容工具 "Open Visual Studio 2019 Tools Command Prompt for targeting x86 with x64-hosted tools"

set path=C:\Program Files\CMake\bin;C:\Program Files\Git\cmd;%path%
cd /d D:\dev\dev-tools\llama.cpp.win7.vs2019.gpu
cmake -B build -DGGML_CUDA=ON
cmake --build build --config Release      
cd D:\dev\dev-tools\llama.cpp.win7.vs2019.gpu\build\bin\Release

llama-server --model D:\dev\deepseek-r1_1.5b.gguf -ngl 99
1.5B, 你好,19.2 token/s

可编译,可运行,但是Win7环境下,用GPU-Z监测显存用量,未见显存占用增加。 也就是说,编译出来的 llama-server,并未使用GPU。

GPU版,失败的尝试

安装:

visual studio 2015 professionnal,自定义安装,注意选C++语言
cuda_10.2.89_441.22_windows.exe,默认位置,C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2

配置:

创建临时目录
    D:\dev\dev-tools\llama.cpp.win7.gpu
找到源码,llama.cpp.2025-02-08.4d3465c5aeca8be29cac77f1535c35f4fb274eca.zip,解压到上面的目录,解压后路径如下
    D:\dev\dev-tools\llama.cpp.win7.gpu\README.md
修改源码 
    D:\dev\dev-tools\llama.cpp.win7.gpu\examples\server\httplib.h

启动CMD

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
cd /d D:\dev\dev-tools\llama.cpp.win7.gpu

cmake -B build -DGGML_CUDA=ON           fail, CUDA 10.2, VS2015不行
cmake --build build --config Release

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
D:\dev\dev-tools\w64devkit\w64devkit.exe
cd  D:/dev/dev-tools/llama.cpp.win7.gpu
cmake . -G "MinGW Makefiles" -DGGML_CUDA=ON   fail,消息多些
cmake --build . --config Release -j 8

网站公告

今日签到

点亮在社区的每一天
去签到