README.md 3.85 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
![img](./docs/llama_1.png)

## 环境配置

dcuai's avatar
dcuai committed
19
### Docker
zhouxiang's avatar
zhouxiang committed
20
提供光源拉取推理的docker镜像:
xuxzh1's avatar
xuxzh1 committed
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(推荐)
# <Image ID>用上面拉取docker镜像的ID替换
zhouxiang's avatar
zhouxiang committed
25
26
# <Host Path>主机端路径
# <Container Path>容器映射路径
dcuai's avatar
dcuai committed
27
docker run -it --name yi --shm-size=64G  --device=/dev/kfd --device=/dev/dri/ --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v /opt/hyhal:/opt/hyhal:ro --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

镜像版本依赖:
* DTK驱动:24.04.1
* Pytorch: 2.1.0
* python: python3.10


zhouxiang's avatar
zhouxiang committed
36
## 数据集
xuxzh1's avatar
xuxzh1 committed
37

zhouxiang's avatar
zhouxiang committed
38
39
40
41
42


## 推理

### 源码编译安装
xuxzh1's avatar
xuxzh1 committed
43
```bash
dcuai's avatar
dcuai committed
44
45
#若使用光源的镜像,可以不用源码编译,镜像里面安装好了lmdeploy,可跳过源码编译安装
# 获取源码,编译并安装
chenzk's avatar
chenzk committed
46
git clone http://developer.sourcefind.cn/codes/modelzoo/yi_lmdeploy.git
zhouxiang's avatar
zhouxiang committed
47
48
49
50
51
52
53
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
54
cd .. && pip uninstall lmdeploy && python3 setup.py install
zhouxiang's avatar
zhouxiang committed
55
56
```
### 模型下载
dengjb's avatar
update  
dengjb committed
57
58
官方下载地址:

zhouxiang's avatar
zhouxiang committed
59
60
61
62
[Yi-6B-Chat](https://huggingface.co/01-ai/Yi-6B-Chat)

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

xuxzh1's avatar
update  
xuxzh1 committed
63
64
65
66
67
68
69
70
71
72
### 运行前

```bash
#step 1
cd lmdeploy
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
#step 2
source /opt/dtk/cuda/env.sh
```

zhouxiang's avatar
zhouxiang committed
73
74
### 运行 
```shell
xuxzh1's avatar
update  
xuxzh1 committed
75
lmdeploy chat turbomind  ./path_to_yi-34b --tp 4
zhouxiang's avatar
zhouxiang committed
76
77
78
```

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

zhouxiang's avatar
zhouxiang committed
80
```shell
dcuai's avatar
dcuai committed
81
lmdeploy serve gradio ./path_to_yi-34b --server-name {server_ip} --server-port {port} --backend turbomind  --tp 4 
zhouxiang's avatar
zhouxiang committed
82
83
84
85
86
87
88
89
90
```
浏览器上打开 `http://{server_ip}:{server_port}`,即可进行对话
**需要保证'{server_ip}:{server_port}'在外部浏览器中的可访问性**

#### api-server
启动server:
```shell
# --instance_num: turbomind推理实例的个数。可理解为支持的最大并发数
# --tp: 在 tensor parallel时,使用的GPU数量
dcuai's avatar
dcuai committed
91
lmdeploy serve api_server ./path_to_yi-34b --server-name {server_ip} --server-port {server_port} --tp 4
zhouxiang's avatar
zhouxiang committed
92
93
94
95
96
97
98
99
100
101
102
103
```
浏览器上打开 `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 访问服务的
dcuai's avatar
dcuai committed
104
105
# 例子: lmdeploy serve gradio http://localhost:23333 --server-name localhost --server-port 6006
lmdeploy serve gradio restful_api_url --server-name {server_ip} --server-port {server_port} 
zhouxiang's avatar
zhouxiang committed
106
107
108
```
**需要保证'{server_ip}:{server_port}'在外部浏览器中的可访问性**

chenzk's avatar
chenzk committed
109
关于 RESTful API的详细介绍,请参考[这份](https://developer.sourcefind.cn/codes/aicomponent/lmdeploy/-/blob/dtk23.04-v0.0.13/docs/zh_cn/restful_api.md)文档。
zhouxiang's avatar
zhouxiang committed
110
111

## result
zhouxiang's avatar
zhouxiang committed
112
![llama](docs/yi34b.gif)
zhouxiang's avatar
zhouxiang committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

### 精度



## 应用场景

### 算法类别

`对话问答`


### 热点应用行业

`金融,科研,教育`


## 源码仓库及问题反馈
chenzk's avatar
chenzk committed
131
https://developer.sourcefind.cn/codes/modelzoo/yi_lmdeploy
zhouxiang's avatar
zhouxiang committed
132
133

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

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