README.md 4.65 KB
Newer Older
xiabo's avatar
xiabo committed
1
2
# Qwen_lmdeploy
## 论文
lvhan028's avatar
lvhan028 committed
3

xiabo's avatar
xiabo committed
4
`Qwen-VL: A Frontier Large Vision-Language Model with Versatile Abilities`
RunningLeon's avatar
RunningLeon committed
5

xiabo's avatar
xiabo committed
6
https://arxiv.org/pdf/2308.12966.pdf
lvhan028's avatar
lvhan028 committed
7

xiabo's avatar
xiabo committed
8
## 模型结构
lvhan028's avatar
lvhan028 committed
9

xiabo's avatar
xiabo committed
10
通义千问(Qwen) 是阿里云研发的通义千问大模型系列的70/140亿参数规模的模型。Qwen是基于Transformer的大语言模型, 在超大规模的预训练数据上进行训练得到。预训练数据类型多样,覆盖广泛,包括大量网络文本、专业书籍、代码等。同时,在Qwen-7B的基础上,使用对齐机制打造了基于大语言模型的AI助手Qwen-7B-Chat。
lvhan028's avatar
lvhan028 committed
11

xiabo's avatar
xiabo committed
12
本项目主要针对Qwen-Chat在DCU平台的推理性能优化,达到DCU平台较快的对话效果。
13

xiabo's avatar
xiabo committed
14
![qwen](docs/dcu/transformer.jpg)
15
16


17

xiabo's avatar
xiabo committed
18
## 算法原理
19

xiabo's avatar
xiabo committed
20
Qwen的构建采用了类似LLaMA的架构。与标准transformer的主要差异有:1)使用非连接嵌入、2)使用旋转位置嵌入、3)在注意力中除了QKV外不使用偏置、4)使用RMSNorm代替LayerNorm、5)使用SwiGLU代替ReLU、以及6)采用快速注意力来加速训练。该模型共有32层,嵌入维度为4096,注意力头数为32。
21

xiabo's avatar
xiabo committed
22
![qwen](docs/dcu/qwen.png)
lvhan028's avatar
lvhan028 committed
23

xiabo's avatar
xiabo committed
24
25
## 环境配置
提供[光源](https://www.sourcefind.cn/#/service-details)拉取推理的docker镜像:
AllentDan's avatar
AllentDan committed
26
```
xiabo's avatar
xiabo committed
27
28
29
30
31
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
32
```
xiabo's avatar
xiabo committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
镜像版本依赖:
* 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
xiabo's avatar
xiabo committed
49
```
xiabo's avatar
xiabo committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 模型转换
# <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}即可进行对话
xiabo's avatar
xiabo committed
78
```
xiabo's avatar
xiabo committed
79
### 运行 Qwen-14B-chat
xiabo's avatar
xiabo committed
80
```
xiabo's avatar
xiabo committed
81
82
83
84
85
86
87
88
89
90
91
92
# 模型转换
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}即可进行对话
xiabo's avatar
xiabo committed
93
```
xiabo's avatar
xiabo committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
## result
![qwen推理](docs/dcu/qwen推理.gif)

### 精度



## 应用场景

### 算法类别

`对话问答`


### 热点应用行业

`医疗,科研,金融,教育`
111

lvhan028's avatar
lvhan028 committed
112

xiabo's avatar
xiabo committed
113
114
## 源码仓库及问题反馈
https://developer.hpccube.com/codes/modelzoo/qwen_lmdeploy
lvhan028's avatar
lvhan028 committed
115

xiabo's avatar
xiabo committed
116
117
## 参考资料
https://github.com/InternLM/LMDeploy