Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
Qwen_lmdeploy
Commits
26265a69
Commit
26265a69
authored
Nov 22, 2023
by
xiabo
Browse files
Update README.md
parent
40e07381
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
106 deletions
+96
-106
README.md
README.md
+96
-106
No files found.
README.md
View file @
26265a69
# <div align="center"><strong>LMdeploy</strong></div>
## 简介
LMDeploy 由
[
MMDeploy
](
https://github.com/open-mmlab/mmdeploy
)
和
[
MMRazor
](
https://github.com/open-mmlab/mmrazor
)
团队联合开发,是涵盖了 LLM 任务的全套轻量化、部署和服务解决方案。
这个强大的工具箱提供以下核心功能:
# Qwen_lmdeploy
## 论文
-
**高效推理引擎 TurboMind**
:基于
[
FasterTransformer
](
https://github.com/NVIDIA/FasterTransformer
)
,我们实现了高效推理引擎 TurboMind,支持 InternLM、LLaMA、vicuna等模型在 NVIDIA GPU 上的推理。
`Qwen-VL: A Frontier Large Vision-Language Model with Versatile Abilities`
-
**交互推理方式**
:通过缓存多轮对话过程中 attention 的 k/v,记住对话历史,从而避免重复处理历史会话。
https://arxiv.org/pdf/2308.12966.pdf
-
**多 GPU 部署和量化**
:我们提供了全面的模型部署和量化支持,已在不同规模上完成验证。
## 模型结构
-
**persistent batch 推理**
:进一步优化模型执行效率
。
通义千问(Qwen) 是阿里云研发的通义千问大模型系列的70/140亿参数规模的模型。Qwen是基于Transformer的大语言模型, 在超大规模的预训练数据上进行训练得到。预训练数据类型多样,覆盖广泛,包括大量网络文本、专业书籍、代码等。同时,在Qwen-7B的基础上,使用对齐机制打造了基于大语言模型的AI助手Qwen-7B-Chat
。
persistent batch 推理:进一步优化模型执行效率。
LMdeploy官方github地址:
[
https://github.com/InternLM/lmdeploy
](
https://github.com/InternLM/lmdeploy
)
本项目主要针对Qwen-Chat在DCU平台的推理性能优化,达到DCU平台较快的对话效果。
## 安装

### 使用源码编译方式安装
#### 编译环境准备
提供2种环境准备方式:
1.
基于光源pytorch基础镜像环境:镜像下载地址:
[
https://sourcefind.cn/#/image/dcu/pytorch
](
https://sourcefind.cn/#/image/dcu/pytorch
)
,根据pytorch、python、dtk及系统下载对应的镜像版本。
```
shell
pip
install
-r
requirements.txt
pip
install
transformers
==
4.33.2
pip
install
urllib3
==
1.24
yum
install
rapidjson
```
## 算法原理
2.
基于现有python环境:安装pytorch,pytorch whl包下载目录:
[
https://cancon.hpccube.com:65024/4/main/pytorch/dtk23.04
](
https://cancon.hpccube.com:65024/4/main/pytorch/dtk23.04
)
,根据python、dtk版本,下载对应pytorch的whl包。安装命令如下:
```
shell
pip
install
torch
*
(
下载的torch的whl包
)
pip
install
-r
requirements.txt
pip
install
transformers
==
4.33.2
pip
install
urllib3
==
1.24
yum
install
rapidjson
```
Qwen的构建采用了类似LLaMA的架构。与标准transformer的主要差异有:1)使用非连接嵌入、2)使用旋转位置嵌入、3)在注意力中除了QKV外不使用偏置、4)使用RMSNorm代替LayerNorm、5)使用SwiGLU代替ReLU、以及6)采用快速注意力来加速训练。该模型共有32层,嵌入维度为4096,注意力头数为32。
#### 源码编译安装
-
代码下载
```
shell
git clone http://10.0.54.20/xiabo/lmdeploy.git
# 根据编译需要切换分支 默认develop分支
```
-
提供2种源码编译方式(进入mmcv目录):
```
1. 源码编译安装
mkdir build && cd build
sh ../generate.sh
make -j 32 && make install
cd .. && python3 setup.py install
2. 编译成whl包安装
mkdir build && cd build
sh ../generate.sh
make -j 32 && make install
cd .. && python3 setup.py bdist_wheel
cd dist && pip3 install lmdeploy*
```
## 模型服务

### 部署 [LLaMA-2](https://github.com/facebookresearch/llama) 服务
请从
[
这里
](
https://huggingface.co/meta-llama
)
下载 llama2 模型,参考如下命令部署服务:
以7B为例:
```
1、模型转换
python3 -m lmdeploy.serve.turbomind.deploy llama2 path/to/chinese-llama2-7b-hf hf path/to/chinese-llama2-7b-hf/tokenizer.model ./workspace_llama
2、运行
- 在命令行界面运行:
python3 -m lmdeploy.turbomind.chat ./workspace_llama
- 在服务器界面运行:
python3 -m lmdeploy.serve.gradio.app ./workspace_llama 10.6.10.67
打开网页输入10.6.10.67:6006
## 环境配置
提供
[
光源
](
https://www.sourcefind.cn/#/service-details
)
拉取推理的docker镜像:
```
### 部署 [internlm](https://huggingface.co/internlm/) 服务
请从
[
这里
](
https://huggingface.co/internlm
)
下载 llama2 模型,参考如下命令部署服务:
以7B为例:
docker pull docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:lmdeploy0.0.13_dtk23.04_torch1.13_py38
# <Image ID>用上面拉取docker镜像的ID替换
# <Host Path>主机端路径
# <Container Path>容器映射路径
docker run -it --name qwen --shm-size=1024G --device=/dev/kfd --device=/dev/dri/ --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --ulimit memlock=-1:-1 --ipc=host --network host --group-add video -v <Host Path>:<Container Path> <Image ID> /bin/bash
```
1、模型转换
python3 -m lmdeploy.serve.turbomind.deploy path/to/internlm-chat-7b internlm-chat-7b hf None ./workspace_intern
2、运行
- 在命令行界面运行:
python3 -m lmdeploy.turbomind.chat ./workspace_intern
- 在服务器界面运行:
python3 -m lmdeploy.serve.gradio.app ./workspace_intern 10.6.10.67
打开网页输入10.6.10.67:6006
```
### 部署 [baichuan](https://huggingface.co/baichuan-inc) 服务
请从
[
这里
](
https://huggingface.co/baichuan-inc
)
下载 baichuan 模型,参考如下命令部署服务:
以7B为例:
镜像版本依赖:
*
DTK驱动:dtk23.04
*
Pytorch: 1.13
*
python: python3.8
## 数据集
无
## 推理
### 模型下载
[
Qwen-7B-chat
](
https://huggingface.co/Qwen/Qwen-7B-Chat/tree/main
)
[
Qwen-14B-chat
](
https://huggingface.co/Qwen/Qwen-14B-Chat/tree/main
)
### 运行 Qwen-7B-chat
```
1、模型转换
python3 -m lmdeploy.serve.turbomind.deploy baichuan2-7b-chat baichuan2-7b-chat hf baichuan2-7b-chat/tokenizer.model ./workspace_baichuan
2、运行
- 在命令行界面运行:
python3 -m lmdeploy.turbomind.chat ./workspace_baichuan
- 在服务器界面运行:
python3 -m lmdeploy.serve.gradio.app ./workspace_baichuan 10.6.10.67
打开网页输入10.6.10.67:6006
# 模型转换
# <model_name> 模型的名字 ('base', 'llama', 'internlm', 'vicuna', 'internlm-chat-7b', 'internlm-chat', 'internlm-chat-7b-8k', 'internlm-chat-20b', 'internlm-20b', 'baichuan-7b', 'baichuan2-7b', 'puyu', 'llama2', 'qwen-7b', 'qwen-14b', 'codellama', 'solar')
# <model_path> 模型路径
# <model_format> 模型的格式 ('llama', 'hf', 'qwen')
# <tokenizer_path> tokenizer模型的路径
# <model_format> 保存输出的目标路径(默认./workspace)
# <tp> 用于张量并行的GPU数量应该是2^n
# <quant_path> 量化模型的路径,可以为None(用于int4量化,使用默认None)
# <group_size> AWQ中用于将fp16权重量化为4位的参数(用于int4量化,使用默认'0')
mdeploy convert --model_name qwen-7b --model_path /path/to/model --model_format qwen --tokenizer_path None --dst_path ./workspace_qwe7b --tp 1 --quant_path None --group_size 0
# bash界面运行
lmdeploy chat turbomind --model_path ./workspace_qwe7b --tp 1 # 输入问题后执行2次回车进行推理
# 服务器网页端运行
在bash端运行:
# <model_path_or_server> 部署模型的路径或tritonserver URL或restful api URL。前者用于与gradio直接运行服务。后者用于默认情况下使用tritonserver运行。如果输入URL是restful api。请启用另一个标志“restful_api”。
# <server_name> gradio服务器的ip地址
# <server_port> gradio服务器的ip的端口
# <batch_size> 于直接运行Turbomind的batch大小 (默认32)
# <tp> 用于张量并行的GPU数量应该是2^n (和模型转换的时候保持一致)
# <restful_api> modelpath_or_server的标志(默认是False)
lmdeploy serve gradio --model_path_or_server ./workspace_qwe7b --server_name {ip} --server_port {pord} --batch_size 32 --tp 1 --restful_api False
在网页上输入{ip}:{pord}即可进行对话
```
### 部署 [qwen](https://huggingface.co/Qwen) 服务
请从
[
这里
](
https://huggingface.co/Qwen
)
下载 qwen 模型,参考如下命令部署服务:
以7B为例:
### 运行 Qwen-14B-chat
```
1、模型转换
python3 -m lmdeploy.serve.turbomind.deploy qwen-7b qwen-7b-chat qwen qwen-7b-chat/tokenizer.model ./workspace_qwen
2、运行
- 在命令行界面运行:
python3 -m lmdeploy.turbomind.chat ./workspace_qwen
- 在服务器界面运行:
python3 -m lmdeploy.serve.gradio.app ./workspace_qwen 10.6.10.67
打开网页输入10.6.10.67:6006
# 模型转换
mdeploy convert --model_name qwen-7b --model_path /path/to/model --model_format qwen --tokenizer_path None --dst_path ./workspace_qwe7b --tp 2 --quant_path None --group_size 0
# bash界面运行
lmdeploy chat turbomind --model_path ./workspace_qwe7b --tp 2
# 服务器网页端运行
在bash端运行:
lmdeploy serve gradio --model_path_or_server ./workspace_qwe7b --server_name {ip} --server_port {pord} --batch_size 32 --tp 1 --restful_api False
在网页上输入{ip}:{pord}即可进行对话
```
### 详细可参考 [docs](./docs/zh_cn/serving.md)
## 版本号查询
-
python -c "import lmdeploy; lmdeploy.
\_\_
version__",版本号与官方版本同步,查询该软件的版本号,例如0.0.6;
## result

### 精度
无
## 应用场景
### 算法类别
`对话问答`
### 热点应用行业
`医疗,科研,金融,教育`
## Known Issue
-
无
##
Note
+
若使用pip install下载安装过慢,可添加pypi清华源:-i https://pypi.tuna.tsinghua.edu.cn/simple/
##
源码仓库及问题反馈
https://developer.hpccube.com/codes/modelzoo/qwen_lmdeploy
## 其他参考
-
[
README_origin
](
README_origin.md
)
-
[
README_zh-CN
](
README_zh-CN.md
)
## 参考资料
https://github.com/InternLM/LMDeploy
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment