README.md 5.31 KB
Newer Older
wanglch's avatar
wanglch committed
1
2
# DISC-FinLLM

wanglch's avatar
wanglch committed
3
**DISC-FinLLM 是一个专门针对金融场景下为用户提供专业、智能、全面的金融咨询服务的金融领域大模型,由[复旦大学数据智能与社会计算实验室 (Fudan-DISC)](http://fudan-disc.com) 开发并开源。**
wanglch's avatar
wanglch committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

## 论文

- [论文地址] [DISC-FinLLM: A Chinese Financial Large Language Model based on Multiple Experts Fine-tuning](https://arxiv.org/abs/2310.15205)

## 模型结构

<div align="center">
    <img src="./images/transformer.jpg"/>
</div>

## 算法原理
DISC-FinLLM是基于我们构建的高质量金融数据集DISC-Fin-SFT在通用领域中文大模型Baichuan-13B-Chat上进行LoRA指令微调得到的金融大模型。

<div align=center>
    <img src="./images/transformer.png"/>
</div>


## 环境配置
### Docker(方法一)
[光源](https://www.sourcefind.cn/#/service-details)拉取docker镜像的地址与使用步骤
```
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu22.04-dtk23.10.1-py310

docker run -it -v /path/your_code_data/:/path/your_code_data/ -v /opt/hyhal/:/opt/hyhal/:ro --shm-size=64G --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video --name DISC-FinLLM <your imageID> bash

cd /path/your_code_data/DISC-FinLLM_pytorch

pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
wanglch's avatar
wanglch committed
34
35

pip install bitsandbytes-0.43.0-py3-none-any.whl
wanglch's avatar
wanglch committed
36
37

pip install deepspeed-0.12.3+gitfe61783.abi0.dtk2310.torch2.1.0a0-cp310-cp310-manylinux2014_x86_64.whl
wanglch's avatar
wanglch committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
```

### Dockerfile(方法二)
```
cd /path/your_code_data/DISC-FinLLM_pytorch/docker

docker build --no-cache -t DISC-FinLLM:latest .

docker run --shm-size=64G --name DISC-FinLLM -v /opt/hyhal:/opt/hyhal:ro --privileged=true --device=/dev/kfd --device=/dev/dri/ --group-add video -v /path/your_code_data/:/path/your_code_data/ -it DISC-FinLLM bash
```

### Anaconda(方法三)

关于本项目DCU显卡所需的特殊深度学习库可从[光合](https://developer.hpccube.com/tool/)开发者社区下载安装。
```
DTK驱动:dtk23.10
python:python3.10
torch:2.1
torchvision: 0.16.0
apex: 1.1.0
deepspped: 0.12.3
wanglch's avatar
wanglch committed
59
bitsandbytes: 0.43.0
wanglch's avatar
wanglch committed
60
61
62
63
64
65
66
67
68
```
`Tips:以上dtk驱动、python、paddle等DCU相关工具版本需要严格一一对应`

```
conda create -n DISC-FinLLM python=3.10

cd /path/your_code_data/DISC-FinLLM_pytorch

pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple
wanglch's avatar
wanglch committed
69
70

pip install bitsandbytes-0.43.0-py3-none-any.whl
wanglch's avatar
wanglch committed
71
72

pip install deepspeed-0.12.3+gitfe61783.abi0.dtk2310.torch2.1.0a0-cp310-cp310-manylinux2014_x86_64.whl
wanglch's avatar
wanglch committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
```

## 数据集

**你可以在这里查看[资料分析评测](https://github.com/FudanDISC/DISC-FinLLM/tree/main/eval/computing_eval.json)、[时事分析评测](https://github.com/FudanDISC/DISC-FinLLM/tree/main/eval/retriever_eval.json)对应的数据集。**

### 自定义数据处理代码 
参考data_processor.py

```
import json

jsonl_file_path = '.../data/dataset_new.jsonl'
json_file_path = '../data/dataset_new.json'
data = []
with open(jsonl_file_path, 'r', encoding='utf-8') as file:
    for line in file:
        jsonl_data = json.loads(line)
        json_data = {
            "instruction": jsonl_data.get("context").split('\n')[0].replace('Instruction: ', ''),
            "input": jsonl_data.get("context").split('\n')[1].replace('Input: ', ''),
            "output": jsonl_data.get("target")
        }
        data.append(json_data)

with open(json_file_path, 'w', encoding='utf-8') as file:
    json.dump(data, file, ensure_ascii=False, indent=4)

print(data)
```

项目中已提供用于试验训练的迷你数据集,训练数据目录结构如下,用于正常训练的完整数据集请按此目录结构进行制备:
```
 ── data
    │   ├── computing_part.json
    │   ├── consulting_part.json
    │   ├── retrieval_part.json
    │   └── task_part.json
    │——————————
```

## 训练

### 单机多卡
```
bash multi_dcu_train.sh
```

### 单机单卡
```
bash sft_work_dtk.sh
```

## 推理
**运行推理代码时需将模型文件FinLLM中的文件替换下载的本地模型FinLLM文件,并且将cli_demo.py文件中的模型路径更换为本地模型路径。**

### 单机单卡
需将**cli_demo.py**中的**model_path**改为替换模型文件后的本地模型路径
```
python cli_demo.py
```
### web交互推理
需将**web_demo.py**中的**model_path**改为替换模型文件后的本地模型路径
```
python web_demo.py
```

## result

<div align=center>
    <img src="./images/result.png"/>
</div>

### 精度
测试数据:[retrieval_part](data/retrieval_part.json),使用的加速卡:V100S/K100。

根据测试结果情况填写表格:
| device | train_loss | train_runtime |eval_los |eval_runtime |
| :------: | :------: | :------: | :------: |:------: |
| V100s |  0.6173 | 458.827 | 0.6276 | 4.6428 |
| K100 | 0.6193 | 1424.4159 | 0.6269 | 14.4002 |

## 应用场景
### 算法类别
wanglch's avatar
wanglch committed
157
`金融咨询,金融计算,文本分析`
wanglch's avatar
wanglch committed
158
159

### 热点应用行业
wanglch's avatar
wanglch committed
160
`金融,教育,政府,科研`
wanglch's avatar
wanglch committed
161
162
163
164
165
166
167
168
169
170
171

## 预训练权重

- [Hugging Face Go4miii/DISC-FinLLM](https://huggingface.co/Go4miii/DISC-FinLLM) 下载全参模型权重。

## 源码仓库及问题反馈
- http://developer.hpccube.com/codes/modelzoo/disc-finllm_pytorch.git

## 参考资料
- 本项目gitlab地址[Go4miii/DISC-FinLLM](https://github.com/FudanDISC/DISC-FinLLM)