README.md 3.91 KB
Newer Older
dcuai's avatar
dcuai committed
1
# Qwen-7B
hepj987's avatar
hepj987 committed
2

hepj987's avatar
hepj987 committed
3
4
5
6
7
8
9
10
11
12
13
## 论文

Qwen-7B上增加视觉编码器得到Qwen-VL,论文与地址:

`Qwen-VL: A Frontier Large Vision-Language Model with Versatile Abilities`

https://arxiv.org/pdf/2308.12966.pdf

## 模型结构

![qwen](qwen.jpg)
hepj987's avatar
hepj987 committed
14
15
16
17
18

```
通义千问-7B(Qwen-7B) 是阿里云研发的通义千问大模型系列的70亿参数规模的模型。Qwen-7B是基于Transformer的大语言模型, 在超大规模的预训练数据上进行训练得到。预训练数据类型多样,覆盖广泛,包括大量网络文本、专业书籍、代码等。
```

hepj987's avatar
hepj987 committed
19
## 算法原理
hepj987's avatar
hepj987 committed
20

hepj987's avatar
hepj987 committed
21
![qwen](qwen.png)
hepj987's avatar
hepj987 committed
22
23

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

hepj987's avatar
hepj987 committed
27
## 环境配置
hepj987's avatar
hepj987 committed
28

hepj987's avatar
hepj987 committed
29
30
### Docker(方式一)

hepj987's avatar
hepj987 committed
31
32
33
推荐使用docker方式运行,提供[光源](https://www.sourcefind.cn/#/main-page)拉取的docker镜像:

```
dcuai's avatar
dcuai committed
34
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu20.04-dtk24.04.1-py3.10
hepj987's avatar
hepj987 committed
35

dcuai's avatar
dcuai committed
36
docker run -dit --network=host --name=qwen_pytorch -v /opt/hyhal:/opt/hyhal:ro --privileged --device=/dev/kfd --device=/dev/dri --ipc=host --shm-size=16G  --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -u root --ulimit stack=-1:-1 --ulimit memlock=-1:-1  image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu20.04-dtk24.04.1-py3.10
hepj987's avatar
hepj987 committed
37
38
39
40
41
42
43
44
docker exec -it qwen_pytorch /bin/bash
pip install -r requirements.txt  -i https://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com
```

## Dockerfile(方式二)

```
docker build -t qwen:latest .
dcuai's avatar
dcuai committed
45
docker run -dit --network=host --name=qwen_pytorch -v /opt/hyhal:/opt/hyhal:ro --privileged --device=/dev/kfd --device=/dev/dri --ipc=host --shm-size=16G  --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -u root --ulimit stack=-1:-1 --ulimit memlock=-1:-1 qwen:latest
hepj987's avatar
hepj987 committed
46
47
docker exec -it qwen_pytorch /bin/bash
pip install -r requirements.txt  -i https://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com
hepj987's avatar
hepj987 committed
48
49
```

hepj987's avatar
hepj987 committed
50
### conda(方式三)
dcuai's avatar
dcuai committed
51
其中apex、torch、deepspeed需要到[开发者社区](https://cancon.hpccube.com:65024/4/main/)下载对应版本
hepj987's avatar
hepj987 committed
52
53

```
dcuai's avatar
dcuai committed
54
conda create -n qwen python=3.10
hepj987's avatar
hepj987 committed
55
pip install -r requirements.txt  -i https://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com
hepj987's avatar
hepj987 committed
56
57
58
```


dcuai's avatar
dcuai committed
59
[torch2.1.0-dtk24.04.1](https://cancon.hpccube.com:65024/directlink/4/pytorch/DAS1.1/torch-2.1.0+das1.1.git3ac1bdd.abi1.dtk2404-cp310-cp310-manylinux_2_31_x86_64.whl)
dcuai's avatar
dcuai committed
60

dcuai's avatar
dcuai committed
61
62
[deepspeed0.12.3-dtk24.04.1](https://cancon.hpccube.com:65024/directlink/4/deepspeed/DAS1.1/deepspeed-0.12.3+gita724046.abi1.dtk2404.torch2.1.0-cp310-cp310-manylinux_2_31_x86_64.whl)

hepj987's avatar
hepj987 committed
63
64

Tips:以上dtk驱动、python、deepspeed等工具版本需要严格一一对应。
hepj987's avatar
hepj987 committed
65

hepj987's avatar
hepj987 committed
66

hepj987's avatar
hepj987 committed
67

hepj987's avatar
hepj987 committed
68
## 数据集
hepj987's avatar
hepj987 committed
69
70

```
hepj987's avatar
hepj987 committed
71
72
73
74
75
76
77
78
使用alpaca_gpt4_zh数据集,已经包含在data目录中,具体文件为alpaca_gpt4_data_zh.json
```

```
#数据集树目录
data
├── alpaca_gpt4_data_en.json
└── alpaca_gpt4_data_zh.json
hepj987's avatar
hepj987 committed
79
80
```

hepj987's avatar
hepj987 committed
81
82


dcuai's avatar
dcuai committed
83
### 模型下载
hepj987's avatar
hepj987 committed
84

chenzk's avatar
chenzk committed
85
[Qwen-7B-Chat](https://huggingface.co/Qwen/Qwen-7B-Chat)
hepj987's avatar
hepj987 committed
86

hepj987's avatar
hepj987 committed
87
## 训练
hepj987's avatar
hepj987 committed
88

hepj987's avatar
hepj987 committed
89
### 单节点
hepj987's avatar
hepj987 committed
90
91

```
hepj987's avatar
hepj987 committed
92
bash run-node.sh
hepj987's avatar
hepj987 committed
93
94
```

hepj987's avatar
hepj987 committed
95
### 多节点
hepj987's avatar
hepj987 committed
96

hepj987's avatar
hepj987 committed
97
98
99
100
```
#需要修改对应的节点名、加载对应虚拟环境以及模型路径等,修改hostfile为自己所用的节点
sh mpirun-nodes.sh
```
hepj987's avatar
hepj987 committed
101

hepj987's avatar
hepj987 committed
102
## result
hepj987's avatar
hepj987 committed
103

hepj987's avatar
hepj987 committed
104
![tuili](tuili.png)
hepj987's avatar
hepj987 committed
105

hepj987's avatar
hepj987 committed
106
### 精度
hepj987's avatar
hepj987 committed
107

hepj987's avatar
hepj987 committed
108
乌镇集群两节点八卡zero3训练
hepj987's avatar
hepj987 committed
109
110
111
112
113

|         train         |  loss  |
| :-------------------: | :----: |
| 1.44epoch(8780step) | 1.3917 |

hepj987's avatar
hepj987 committed
114
115
116
117
## 应用场景

### 算法类别

hepj987's avatar
hepj987 committed
118
`对话问答`
hepj987's avatar
hepj987 committed
119
120

### 热点应用行业
hepj987's avatar
hepj987 committed
121

hepj987's avatar
hepj987 committed
122
`科研,教育,政府,金融`
hepj987's avatar
hepj987 committed
123
124
125

## 源码仓库及问题反馈

chenzk's avatar
chenzk committed
126
https://developer.sourcefind.cn/codes/modelzoo/qwen-torch
hepj987's avatar
hepj987 committed
127

hepj987's avatar
hepj987 committed
128
## 参考资料
hepj987's avatar
hepj987 committed
129
130

https://github.com/hiyouga/LLaMA-Efficient-Tuning/tree/main