非默认推理后端
使用 vllm 作为 inference backend
Byzer-LLM 其实支持 Transformers, vLLM, Deepspeed Inference, Aviary/TGI 等多种backend。 这篇文章我们介绍 如何在 Byzer-LLM 中使用 vLLM 作为推理后端。
已经通过实机测试模型(会持续更新):
- falcon 系列
- llama/llama2 以及衍生系列
- baichuan2
如何使用 vLLM 启动模型
!byzerllm setup single;
!byzerllm setup "num_gpus=8";
!byzerllm setup "infer_backend=ray/vllm";
-- include http.`project.LLMs.clear_nodes`;
run command as LLM.`` where
action="infer"
and localModelDir="/home/byzerllm/models/f40-dog-trans-lr3-chat-lr1.5/"
and pretrainedModelType="custom/auto"
and udfName="vllm_falcon_40b_chat"
and modelTable="command";
相比 Transformers 作为 bakcend, 如果想切换使用 vLLM 作为 backend,需要调整两个参数:
- 需要显示用
!byzerllm指定推理后端。 pretrainedModelType固定设置为custom/auto, 也就是让 backend 自己自动设置模型类型。
注意:vllm 切分模型是根据模型里的 heads 数来确定的,比如 num_gpus=8, 那么 8 需要能够被 heads 整除。不同模型 heads 不相同,可以根据 模型的 heads 数来调整 num_gpus 的值,或者根据报错修改该值。
一些性能参考
以 Falcon 40B 为例,在输入 2-4k tokens的情况下, latency 在5-15s 之间,八卡 3090 token 生成速度可以稳定在 20-25之间每秒,理论上 QPS 也会提升比较明显。
使用 Deepspeed 作为 inference backend
Byzer-LLM 其实支持 Transformers, vLLM, Deepspeed Inference, Aviary/TGI 等多种backend。 这篇文章我们介绍 如何在 Byzer-LLM 中使用 Deepspeed 作为推理后端。
已经通过实机测试模型(会持续更新):
- llama 以及衍生系列
如何使用 Deepspeed 启动模型
!byzerllm setup single;
!byzerllm setup "num_gpus=4";
!byzerllm setup "infer_backend=ray/deepspeed";
-- include http.`project.LLMs.clear_nodes`;
run command as LLM.`` where
action="infer"
and localModelDir="/home/byzerllm/models/llama-30b-cn/"
and pretrainedModelType="custom/auto"
and udfName="deepspeed_chat"
and reconnect="false"
and modelTable="command";
相比 Transformers 作为 bakcend, 如果想切换使用 Deepspeed 作为 backend,需要调整两个参数:
- 需要显示用
!byzerllm指定推理后端。 pretrainedModelType固定设置为custom/auto, 也就是让 backend 自己自动设置模型类型。
一些限制说明
Deepspeed 加载模型对内存要求极高,这也导致加载很慢, num_gpus 设置的越高,需要的临时内存就越多,内存不足会导致模型加载失败。 譬如加载 30B 的 llama 模型,如果 num_gpus 设置为 8, 那么 1T 内存都不够。 num_gpus设置为 4, 大概最高峰需要占用 600G 内存。 加载时间大约需要 5-10分钟。
因为高内存需求,你可能需要禁止 RAY 的 OOM Killer, 以防止模型加载失败。可以在 Ray start 之前添加 RAY_memory_monitor_refresh_ms=0 来禁止,比如:
RAY_memory_monitor_refresh_ms=0 CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 ray start --head
此外 Deepspeed 需要有C++编译器:
Centos 8 可以按如下方式安装:
sudo dnf install gcc-c++
Ubuntu 则可以这样安装:
sudo apt-get install build-essential
一些性能说明
Deepspeed 的推理性能 latency, 推理时常大约只需要 Transformers 的 1/3 左右,甚至更少。
更多推荐

所有评论(0)