README.md 4.71 KB
Newer Older
zhouxiang's avatar
zhouxiang committed
1
2
3
4
5
6
# Yi

## 论文
- 暂无

## 模型结构
dcuai's avatar
dcuai committed
7
Yi系列模型结构与llama结构基本一致,以 Transformer 架构为基础:
zhouxiang's avatar
zhouxiang committed
8
9
10
11

![img](./docs/llama.png)

## 算法原理
zhouxiang's avatar
zhouxiang committed
12
13
14

Yi 系列模型以双语语言模型为目标,并在 3T 多语言语料库上进行训练,成为全球最强大的 LLM 模型之一,在语言理解、常识推理、阅读理解等方面显示出前景。

zhouxiang's avatar
zhouxiang committed
15
16
17
18
19
![img](./docs/llama_1.png)

## 环境配置

提供光源拉取推理的docker镜像:
xuxzh1's avatar
xuxzh1 committed
20
21
22
23
24

```bash
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu20.04-dtk24.04.1-py3.10(推荐)
docker pull image.sourcefind.cn:5000/dcu/admin/base/custom:lmdeploy0.0.13_dtk23.04_torch1.13_py38
# <Image ID>用上面拉取docker镜像的ID替换
zhouxiang's avatar
zhouxiang committed
25
26
# <Host Path>主机端路径
# <Container Path>容器映射路径
xuxzh1's avatar
xuxzh1 committed
27
docker run -it --name baichuan --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
zhouxiang's avatar
zhouxiang committed
28
```
xuxzh1's avatar
xuxzh1 committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

镜像版本依赖:

* DTK驱动:24.04.1
* Pytorch: 2.1.0
* python: python3.10

> [!NOTE]
>
> 使用lmdeploy0.0.13_dtk23.04_torch1.13_py38如果遇到 importError:libgemm multiB int4.so: cannot open shared obiect file: No such file or directory
>
> 解决方法:
>
> ```bash
> rm /usr/local/lib/python3.8/site-packages/_turbomind.cpython-38-x86_64-linux-gnu.so
> ```



zhouxiang's avatar
zhouxiang committed
48
## 数据集
xuxzh1's avatar
xuxzh1 committed
49

zhouxiang's avatar
zhouxiang committed
50
51
52
53
54


## 推理

### 源码编译安装
xuxzh1's avatar
xuxzh1 committed
55
```bash
zhouxiang's avatar
zhouxiang committed
56
57
58
59
60
61
62
63
git clone http://developer.hpccube.com/codes/modelzoo/yi_lmdeploy.git
cd yi_lmdeploy
git submodule init && git submodule update
cd lmdeploy
mkdir build && cd build
sh ../generate.sh
make -j 32
make install
zhouxiang's avatar
zhouxiang committed
64
cd .. && pip uninstall lmdeploy && python3 setup.py install
zhouxiang's avatar
zhouxiang committed
65
66
67
```
### 模型下载

dengjb's avatar
update  
dengjb committed
68
69
70
71
72
73
74
75
76
77
78
79
预训练权重快速下载中心:

[SCNet AIModels](http://113.200.138.88:18080/aimodels)

项目中的预训练权重快速通道下载地址:

[Yi-6B-Chat](http://113.200.138.88:18080/aimodels/Yi-6B-Chat)

[Yi-34B-Chat](http://113.200.138.88:18080/aimodels/Yi-34B-Chat)

官方下载地址:

zhouxiang's avatar
zhouxiang committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
[Yi-6B-Chat](https://huggingface.co/01-ai/Yi-6B-Chat)

[Yi-34B-Chat](https://huggingface.co/01-ai/Yi-34B-Chat) 

### 运行 
#### 模型转换
执行如下的命令,把模型权重转成 turbomind 要求的格式:

```shell
# 转模型格式,转换后的模型会生成在./workspace目录中
# 其中--tp设置为你需要使用的gpu数,tp需要设置为2^n,如果tp设置的不是1,则后续模型的运行命令中也需要带上这个参数与模型对应
lmdeploy convert yi /path/of/yi-34b/model --dst_path ./workspace_yi-34b --tp 4
```

#### bash界面运行
```shell
lmdeploy chat turbomind --model_path ./workspace_yi-34b --tp 4
```

#### web页面方式交互
zhouxiang's avatar
zhouxiang committed
100

zhouxiang's avatar
zhouxiang committed
101
102
103
104
105
106
107
108
109
110
111
```shell
lmdeploy serve gradio --model_path_or_server ./workspace_yi-34b --server_name {server_ip} --server_port {port} --batch_size 32 --tp 4 --restful_api False 
```
浏览器上打开 `http://{server_ip}:{server_port}`,即可进行对话
**需要保证'{server_ip}:{server_port}'在外部浏览器中的可访问性**

#### api-server
启动server:
```shell
# --instance_num: turbomind推理实例的个数。可理解为支持的最大并发数
# --tp: 在 tensor parallel时,使用的GPU数量
zhouxiang's avatar
zhouxiang committed
112
lmdeploy serve api_server ./workspace_yi-34b --server_name ${server_ip} --server_port ${server_port} --instance_num 32 --tp 4
zhouxiang's avatar
zhouxiang committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
```
浏览器上打开 `http://{server_ip}:{server_port}`,即可访问 swagger,查阅 RESTful API 的详细信息。

可以用命令行,在控制台与 server 通信(在新启的命令行页面下执行):
```shell
# restful_api_url 就是 api_server 产生的,即上述启动server的http://{server_ip}:{server_port}
lmdeploy serve api_client restful_api_url
```
或者,启动 gradio,在 webui 的聊天对话框中,与服务交流:
```shell
# restful_api_url 就是 api_server 产生的,比如 http://localhost:23333
# server_ip 和 server_port 是用来提供 gradio ui 访问服务的
# 例子: lmdeploy serve gradio http://localhost:23333 --server_name localhost --server_port 6006 --restful_api True
lmdeploy serve gradio restful_api_url --server_name ${server_ip} --server_port ${server_port} --restful_api True
```
**需要保证'{server_ip}:{server_port}'在外部浏览器中的可访问性**

关于 RESTful API的详细介绍,请参考[这份](https://developer.hpccube.com/codes/aicomponent/lmdeploy/-/blob/dtk23.04-v0.0.13/docs/zh_cn/restful_api.md)文档。

## result
zhouxiang's avatar
zhouxiang committed
133
![llama](docs/yi34b.gif)
zhouxiang's avatar
zhouxiang committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151

### 精度



## 应用场景

### 算法类别

`对话问答`


### 热点应用行业

`金融,科研,教育`


## 源码仓库及问题反馈
zhouxiang's avatar
zhouxiang committed
152
https://developer.hpccube.com/codes/modelzoo/yi_lmdeploy
zhouxiang's avatar
zhouxiang committed
153
154

## 参考资料
zhouxiang's avatar
zhouxiang committed
155
156
https://github.com/01-ai/Yi

dcuai's avatar
dcuai committed
157
https://github.com/InternLM/LMDeploy