使用autodl服务器,在A40显卡上运行, Yi-34B-Chat-int4模型,并使用vllm优化加速,显存占用42G,速度18 words/s

1,演示视频

https://www.bilibili.com/video/BV1gu4y1c7KL/

使用autodl服务器,在A40显卡上运行, Yi-34B-Chat-int4模型,并使用vllm优化加速,显存占用42G,速度18 words/s

2,关于A40显卡,48GB 显存,安培架构

2020年,英伟达发布 A40 专业显卡,配备 48GB 显存。

采用了 GA102 GPU,拥有 10752 个 CUDA 核心。而 A40 是用于服务器的。A40 都配备了四个 DP 1.4 接口,都搭载了 48GB 的 GDDR6 显存,最大带宽为 696 GB/s。显卡的功耗为 300W,采用了全新的 8 pin 接口。

环境使用:
CPU :15 核心
内存:80 GB
GPU :NVIDIA A40, 1个

3,关于 Yi-34B 模型

11月24日,零一万物基正式发布并开源微调模型 Yi-34B-Chat,可申请免费商用。同时,零一万物还为开发者提供了 4bit/8bit 量化版模型,Yi-34B-Chat 4bit 量化版模型可以直接在消费级显卡(如RTX3090)上使用。

官方网站:
https://www.lingyiwanwu.com/

模型下载地址:
https://huggingface.co/01-ai/Yi-34B-Chat-8bits

github地址:
https://github.com/01-ai/Yi

下载后占空间:
68G Yi-34B-Chat-8bits

经测试:Yi-34B-Chat-4bits 没有启动成功,8bits启动成功了。
下模型文件花费时间比较多。

3,安装相关依赖,先安装最新的torch版本

apt update && apt install -y git-lfs net-tools
#
git clone https://www.modelscope.cn/01ai/Yi-34B-Chat-4bits.git


# 1,安装 torch 模块,防止依赖多次下载
pip3 install torch==2.1.0

# 2,安装 vllm 模块:
pip3 install vllm

# 最后安装 
pip3 install "fschat[model_worker,webui]" auto-gptq optimum

安装完成之后就可以使用fastchat启动了。

4,使用 vllm 进行加速,可以加速 Yi-34B-Chat-4bits 模型

https://docs.vllm.ai/en/latest/getting_started/installation.html

官方网站:https://github.com/vllm-project/vllm

说明模型不支持这个 vllm ,需要切换成 Yi-34B-Chat-4bits 可以启动

ValueError: Unknown quantization method: gptq. Must be one of ['awq', 'squeezellm'].

增加参数:fastchat.serve.vllm_worker –quantization awq
就可以切换成 fastchat 的 vllm 模式:

# run_all_vllm_yi.sh

# 清除全部 fastchat 服务
ps -ef | grep fastchat.serve | awk '{print$2}' | xargs kill -9
sleep 3

rm -f *.log

# 首先启动 controller :
nohup python3 -m fastchat.serve.controller --host 0.0.0.0 --port 21001 > controller.log 2>&1 &

# 启动 openapi的 兼容服务 地址 8000
nohup python3 -m fastchat.serve.openai_api_server --controller-address http://127.0.0.1:21001 \
  --host 0.0.0.0 --port 8000 > api_server.log 2>&1 &

# 启动 web ui
nohup python -m fastchat.serve.gradio_web_server --controller-address http://127.0.0.1:21001 \
 --host 0.0.0.0 --port 8000 > web_server.log 2>&1 &


# 然后启动模型: 说明,必须是本地ip --load-8bit 本身已经是int4了
# nohup python3 -m fastchat.serve.model_worker  --model-names yi-34b \
#   --model-path ./Yi-34B-Chat-8bits --controller-address http://${IP_ADDR}:21001 \
#   --worker-address http://${IP_ADDR}:8080 --host 0.0.0.0 --port 8080 > model_worker.log 2>&1 &

## 
nohup python3 -m fastchat.serve.vllm_worker --quantization awq --model-names yi-34b \
  --model-path ./Yi-34B-Chat-4bits --controller-address http://127.0.0.1:21001 \
  --worker-address http://127.0.0.1:8080 --host 0.0.0.0 --port 8080 > model_worker.log 2>&1 &

然后在测试下 token 效果:

python3 -m fastchat.serve.test_throughput --controller-address http://127.0.0.1:21001 --model-name yi-34b --n-thread 1

throughput: 18.678158839922936 words/s.

5,总结

测试效果还可以,但是偶尔出现英文,需要说明强制转换成中文:

curl http://localhost:6006/v1/chat/completions   -H "Content-Type: application/json"   -d '{
     "model": "chatglm3-6b",
     "messages": [{"role": "user", "content": "北京景点,使用中文回答"}],
     "temperature": 0.7
   }'

版权声明:本文为博主作者:fly-iot原创文章,版权归属原作者,如果侵权,请联系我们删除!

原文链接:https://blog.csdn.net/freewebsys/article/details/134698597

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
扎眼的阳光的头像扎眼的阳光普通用户
上一篇 2024年4月16日
下一篇 2024年4月16日

相关推荐