我们基于 LMDeploy 的 PytorchEngine,增加了华为昇腾设备的支持,目前支持的型号是Atlas 800T A3,Atlas 800T A2和Atlas 300I Duo。在华为昇腾上使用 LMDeploy 的方法与在英伟达 GPU 上使用 PytorchEngine 后端的方法几乎相同。在阅读本教程之前,请先阅读原版的快速开始。
支持的模型列表在这里.
Important
我们已经在阿里云上提供了构建完成的鲲鹏CPU版本的镜像。 请使用下面的命令来拉取镜像:
Atlas 800T A3:
docker pull crpi-4crprmm5baj1v8iv.cn-hangzhou.personal.cr.aliyuncs.com/lmdeploy_dlinfer/ascend:a3-latest
(Atlas 800T A3目前只支持Qwen系列的算子模式下运行)
Atlas 800T A2:
docker pull crpi-4crprmm5baj1v8iv.cn-hangzhou.personal.cr.aliyuncs.com/lmdeploy_dlinfer/ascend:a2-latest
Atlas 300I Duo:
docker pull crpi-4crprmm5baj1v8iv.cn-hangzhou.personal.cr.aliyuncs.com/lmdeploy_dlinfer/ascend:300i-duo-latest
(Atlas 300I Duo目前只支持非eager模式)
如果您希望自己构建环境,请参考这里的dockerfile来自己构建。
将device_type="ascend"加入PytorchEngineConfig的参数中。
from lmdeploy import pipeline
from lmdeploy import PytorchEngineConfig
pipe = pipeline("internlm/internlm2_5-7b-chat",
backend_config=PytorchEngineConfig(tp=1, device_type="ascend"))
question = ["Shanghai is", "Please introduce China", "How are you?"]
response = pipe(question)
print(response)将device_type="ascend"加入PytorchEngineConfig的参数中。
from lmdeploy import pipeline, PytorchEngineConfig
from lmdeploy.vl import load_image
pipe = pipeline('OpenGVLab/InternVL2-2B',
backend_config=PytorchEngineConfig(tp=1, device_type='ascend'))
image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
response = pipe(('describe this image', image))
print(response)将--device ascend加入到服务启动命令中。
lmdeploy serve api_server --backend pytorch --device ascend internlm/internlm2_5-7b-chat也可以运行以下命令启动容器运行LLM模型服务。
docker run -it --net=host crpi-4crprmm5baj1v8iv.cn-hangzhou.personal.cr.aliyuncs.com/lmdeploy_dlinfer/ascend:a2-latest \
bash -i -c "lmdeploy serve api_server --backend pytorch --device ascend internlm/internlm2_5-7b-chat"将--device ascend加入到服务启动命令中。
lmdeploy serve api_server --backend pytorch --device ascend OpenGVLab/InternVL2-2B也可以运行以下命令启动容器运行VLM模型服务。
docker run -it --net=host crpi-4crprmm5baj1v8iv.cn-hangzhou.personal.cr.aliyuncs.com/lmdeploy_dlinfer/ascend:a2-latest \
bash -i -c "lmdeploy serve api_server --backend pytorch --device ascend OpenGVLab/InternVL2-2B"将--device ascend加入到服务启动命令中。
lmdeploy chat internlm/internlm2_5-7b-chat --backend pytorch --device ascend也可以运行以下命令使启动容器后开启lmdeploy聊天
docker run -it crpi-4crprmm5baj1v8iv.cn-hangzhou.personal.cr.aliyuncs.com/lmdeploy_dlinfer/ascend:a2-latest \
bash -i -c "lmdeploy chat --backend pytorch --device ascend internlm/internlm2_5-7b-chat"运行下面的代码可以在Atlas 800T A2上对权重进行W4A16量化。
lmdeploy lite auto_awq $HF_MODEL --work-dir $WORK_DIR --device npu支持的模型列表请参考支持的模型。
运行下面的代码可以在Atlas 800T A2上对权重进行W8A8量化。
lmdeploy lite smooth_quant $HF_MODEL --work-dir $WORK_DIR --device npu支持的模型列表请参考支持的模型。
昇腾后端现在支持了在eager模式下的离线int8 KV-cache量化。
详细使用方式请请参考这篇文章。
- 只支持dtype=float16。
- 只支持图模式,请不要加上--eager-mode。