惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Martin Fowler
Martin Fowler
I
InfoQ
腾讯CDC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
爱范儿
爱范儿
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
D
Docker
博客园 - 三生石上(FineUI控件)
Y
Y Combinator Blog
博客园 - Franky
Engineering at Meta
Engineering at Meta
B
Blog
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
Jina AI
Jina AI
V
Visual Studio Blog

StudyingLover's Blog

Diffusion Policy笔记 rwkv笔记 act笔记 nanovllm-block_manager opencode多智能体 nanobot-pre-train nanobot-rl nanobot-sft nanobot-checkpoint_manager nanobot-gpt nanobot-mid-train Vision Mamba (Vim)笔记 BPE演示 最后一遍学习Transformer YOLOv5 目标检测笔记 下载根服务器解析记录 Dynaseal A Backend-Controlled LLM API Key Distribution Scheme with Constrained Invocation Parameters 判断链表有环 王道25数据结构勘误 关于perplexity的open-sourcing-r1-1776 AI为什么不像人类一样进行多轮对话 新博客改造日记和功能测试 linuxqq只显示登陆背景图 数字设计和计算机体系结构(机械工业出版社)勘误(自制) Dynaseal:面向未来端侧llm agent的llm api key分发机制 A Definitive Guide to Markdown Style This post is using MDX, Where you can embed JSX and Astro components RT-Patch学习 pydantic实现的LLM ReAct fastapi 和 uvicorn 设置监听 ipv6
GPU部署llama-cpp-python(llama.cpp通用)
About the Author StudyingLover · 2023-08-07 · via StudyingLover's Blog

GPU部署llama-cpp-python(llama.cpp通用)

通用流程

我们的安装平台是Ubuntu20.04,Python 3.8.10,cuda 11.6。

首先确保自己是否已经安装了cuda,输入

nvcc -V

有类似下面的输出即可

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Fri_Dec_17_18:16:03_PST_2021
Cuda compilation tools, release 11.6, V11.6.55
Build cuda_11.6.r11.6/compiler.30794723_0

我们选用 cuBLAS 加速后端代理。直接按照下面命令安装

export LLAMA_CUBLAS=1
CMAKE_ARGS="-DLLAMA_CUBLAS=on" FORCE_CMAKE=1 pip install llama-cpp-python

不出意外的话就安装好了,但是你会出现很多意外,请你努力在一堆红色的报错中找出关键出错点,然后搜索,在最后我给出了几个我遇到的。

运行

运行和CPU直接运行相似,只是需要加入几个参数.

python3 -m llama_cpp.server --model llama-2-70b-chat.ggmlv3.q5_K_M.bin --n_threads 30 --n_gpu_layers 200

n_threads 是一个CPU也有的参数,代表最多使用多少线程。

n_gpu_layers 是一个GPU部署非常重要的一步,代表大语言模型有多少层在GPU运算,如果你的显存出现 out of memory 那就减小 n_gpu_layers

关于多卡

亲测多卡没有遇到什么大坑,只要torch.cuda.is_available()torch.cuda.device_count()正常就可以跑起来。

两张 Tesla T4 的卡推理70B大概半分钟就可以出结果。

报错解决

Check for working CUDA compiler: /usr/local/cuda/bin/nvcc - skipped

参考 https://github.com/ggerganov/llama.cpp/issues/1832 系统安装过程中没找到你的cuda在哪里,所以在pip安装之前先设置一个环境变量,把/usr/local/cuda-x.y改成你的cuda路径

export CUDA_PATH=/usr/local/cuda-x.y

’f16c’: expected a number

这是你的cuda版本太低了,升级到较新版本(11.6可用)。

或者参考 https://github.com/ggerganov/llama.cpp/issues/1467https://github.com/marella/ctransformers/issues/53 中提到的命令和构建(我没有尝试,有谁试了可以请我结果)。

Value ‘sm_30’ is not defined for option ‘gpu-name’ Tesla T

先运行下面的命令

apt-cache policy nvidia-cuda-toolkit

如果版本是1.0 那么请运行 sudo apt remove nvidia-cuda-toolkit