README.md 3.46 KB
Newer Older
xiabo's avatar
xiabo committed
1
# Baichuan
xiabo's avatar
xiabo committed
2
## 论文
xiabo's avatar
xiabo committed
3
4


xiabo's avatar
xiabo committed
5

xiabo's avatar
xiabo committed
6
## 模型结构
xiabo's avatar
xiabo committed
7
Baichuan系列模型是由百川智能开发的开源大规模预训练模型,包含7B和13B等规模。其中,Baichuan-7B在大约1.2万亿tokens上训练的70亿参数模型,支持中英双语,上下文窗口长度为4096。
xiabo's avatar
xiabo committed
8
9
10
11
12
13

模型具体参数:

| 模型名称 | 隐含层维度 | 层数 | 头数 | 词表大小 | 总参数量 | 训练数据(tokens) | 位置编码 | 最大长 |
| -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
| Baichuan-7B | 4,096 | 32 | 32 | 64,000 | 7,000,559,616 | 1.2万亿 | RoPE | 4096 |
xiabo's avatar
xiabo committed
14

xiabo's avatar
xiabo committed
15

xiabo's avatar
xiabo committed
16
![img](./docs/baichuan.jpg)
xiabo's avatar
xiabo committed
17
18

## 算法原理
xiabo's avatar
xiabo committed
19
Baichuan整体模型基于标准的Transformer结构,采用了和LLaMA一样的模型设计。其中,Baichuan-7B在结构上采用Rotary Embedding位置编码方案、SwiGLU激活函数、基于RMSNorm的Pre-Normalization。
xiabo's avatar
xiabo committed
20
![img](./docs/baichuan.png)
xiabo's avatar
xiabo committed
21
22
23
24


## 环境配置

xiabo's avatar
xiabo committed
25
提供光源拉取推理的docker镜像:
xuxzh1's avatar
xuxzh1 committed
26
27
```bash
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu20.04-dtk24.04.1-py3.10(推荐)
xiabo's avatar
xiabo committed
28
29
30
# <Image ID>用上面拉取docker镜像的ID替换
# <Host Path>主机端路径
# <Container Path>容器映射路径
shantf's avatar
shantf committed
31
docker run -it --name baichuan --shm-size=1024G  --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
xiabo's avatar
xiabo committed
32
33
```
镜像版本依赖:
xuxzh1's avatar
xuxzh1 committed
34
35
36
37
38
* DTK驱动:24.04.1
* Pytorch: 2.1.0
* python: python3.10


xiabo's avatar
xiabo committed
39
40
41
42

## 数据集


xiabo's avatar
xiabo committed
43
44
## 推理

xiabo's avatar
xiabo committed
45
### 源码编译安装
xuxzh1's avatar
xuxzh1 committed
46
```bash
xiabo's avatar
xiabo committed
47
# 若使用光源的镜像,可以跳过源码编译安装,镜像里面安装好了lmdeploy。
chenzk's avatar
chenzk committed
48
git clone http://developer.sourcefind.cn/codes/modelzoo/baichuan_lmdeploy.git
xiabo's avatar
xiabo committed
49
50
cd llama_lmdeploy
git submodule init && git submodule update
xiabo's avatar
xiabo committed
51
cd lmdeploy
xiabo's avatar
xiabo committed
52
53
54
55
56
57
58
mkdir build && cd build
sh ../generate.sh
make -j 32
make install
cd .. && python3 setup.py install
```
### 模型下载
shantf's avatar
shantf committed
59
60

官方下载地址:
xiabo's avatar
xiabo committed
61
[baichuan-7b](https://huggingface.co/baichuan-inc/Baichuan-7B)
xiabo's avatar
xiabo committed
62

xiabo's avatar
xiabo committed
63
[baichuan2-7b-chat](https://huggingface.co/baichuan-inc/Baichuan2-7B-Chat)
xiabo's avatar
xiabo committed
64

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

```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
```

xiabo's avatar
xiabo committed
75

xiabo's avatar
xiabo committed
76
### 运行 baichuan-7b-chat
xuxzh1's avatar
xuxzh1 committed
77
```bash
xiabo's avatar
xiabo committed
78
79
# <tp> 用于张量并行的GPU数量应该是2^n
# bash界面运行
shantf's avatar
shantf committed
80
lmdeploy chat turbomind  ./path_to_baichuan7b --tp 1     # 输入问题后执行2次回车进行推理
xiabo's avatar
xiabo committed
81
82
83

# 服务器网页端运行
在bash端运行:
xuxzh1's avatar
update  
xuxzh1 committed
84
85
# <server-name> gradio服务器的ip地址
# <server-port> gradio服务器的ip的端口
xiabo's avatar
xiabo committed
86
# <tp> 用于张量并行的GPU数量应该是2^n (和模型转换的时候保持一致)
shantf's avatar
shantf committed
87
lmdeploy serve gradio  ./path_to_baichuan7b --server-name {ip} --server-port {port} --tp 1
xiabo's avatar
xiabo committed
88

xuxzh1's avatar
xuxzh1 committed
89
在网页上输入{ip}:{port}即可进行对话
xiabo's avatar
xiabo committed
90
91
```

xiabo's avatar
xiabo committed
92
### 运行 baichuan2-7b
xuxzh1's avatar
xuxzh1 committed
93
```bash
xiabo's avatar
xiabo committed
94
# bash界面运行
shantf's avatar
shantf committed
95
lmdeploy chat turbomind ./path_to_baichuan2-7b --tp 1
xiabo's avatar
xiabo committed
96
97
98
99

# 服务器网页端运行

在bash端运行:
shantf's avatar
shantf committed
100
lmdeploy serve gradio ./path_to_baichuan2-7b --server-name {ip} --server-port {port} --tp 1
xiabo's avatar
xiabo committed
101

xuxzh1's avatar
xuxzh1 committed
102
在网页上输入{ip}:{port}即可进行对话
xiabo's avatar
xiabo committed
103
104
105
```

## result
xiabo's avatar
xiabo committed
106
![baichuan](docs/baichuan.gif)
xiabo's avatar
xiabo committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120

### 精度



## 应用场景

### 算法类别

`对话问答`


### 热点应用行业

xiabo's avatar
xiabo committed
121
`医疗,教育,科研,金融`
xiabo's avatar
xiabo committed
122
123

## 源码仓库及问题反馈
chenzk's avatar
chenzk committed
124
https://developer.sourcefind.cn/codes/modelzoo/baichuan_lmdeploy
xiabo's avatar
xiabo committed
125
126
127

## 参考资料
https://github.com/InternLM/LMDeploy