forked from pengxiao-song/LaWGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pengxiao-song#31 from pengxiao-song/dev
Update source code
- Loading branch information
Showing
24 changed files
with
240 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,19 @@ | ||
./data | ||
__pycache__/ | ||
*.npy | ||
*.npz | ||
*.pyc | ||
*.pyd | ||
*.so | ||
*.ipynb | ||
.ipynb_checkpoints | ||
models/base_models/* | ||
!models/base_models/.gitkeep | ||
models/lora_weights/* | ||
!models/lora_weights/.gitkeep | ||
outputs/* | ||
!outputs/.gitkeep | ||
data/* | ||
!data/.gitkeep | ||
wandb/ | ||
flagged/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ LaWGPT 是一系列基于中文法律知识的开源大语言模型。 | |
本项目持续开展,法律领域数据集及系列模型后续相继开源,敬请关注。 | ||
|
||
## 更新 | ||
- 🛠️ 2023/05/22:项目主分支结构调整,详见[项目结构](https://github.com/pengxiao-song/LaWGPT#项目结构) | ||
|
||
- 🪴 2023/05/15:发布 [中文法律数据源汇总(Awesome Chinese Legal Resources)](https://github.com/pengxiao-song/awesome-chinese-legal-resources) 和 [法律领域词表](https://github.com/pengxiao-song/LaWGPT/blob/main/resources/legal_vocab.txt) | ||
|
||
|
@@ -44,13 +45,25 @@ LaWGPT 是一系列基于中文法律知识的开源大语言模型。 | |
1. 准备代码,创建环境 | ||
|
||
```bash | ||
# 下载代码 | ||
git clone [email protected]:pengxiao-song/LaWGPT.git | ||
cd LaWGPT | ||
|
||
# 创建环境 | ||
conda create -n lawgpt python=3.10 -y | ||
conda activate lawgpt | ||
pip install -r requirements.txt | ||
|
||
# 启动可视化脚本(自动下载预训练模型约15GB) | ||
bash ./scripts/webui.sh | ||
``` | ||
|
||
2. 合并模型权重(可选) | ||
2. 访问 http://127.0.0.1:7860 : | ||
<p align="center"> | ||
<img src="./assets/demo/demo.png" width="80%" > | ||
</p> | ||
|
||
3. 合并模型权重(可选) | ||
|
||
**如果您想使用 LaWGPT-7B-alpha 模型,可跳过改步,直接进入步骤3.** | ||
|
||
|
@@ -61,44 +74,28 @@ LaWGPT 是一系列基于中文法律知识的开源大语言模型。 | |
本项目给出[合并方式](https://github.com/pengxiao-song/LaWGPT/wiki/%E6%A8%A1%E5%9E%8B%E5%90%88%E5%B9%B6),请各位获取原版权重后自行重构模型。 | ||
|
||
|
||
3. 启动示例 | ||
|
||
启动本地服务: | ||
|
||
```bash | ||
conda activate lawgpt | ||
cd LaWGPT | ||
sh src/scripts/generate.sh | ||
``` | ||
|
||
接入服务: | ||
|
||
<p align="center"> | ||
<img src="./assets/demo/demo.png" width="80%" > | ||
</p> | ||
|
||
|
||
## 项目结构 | ||
|
||
```bash | ||
```bash | ||
LaWGPT | ||
├── assets # 项目静态资源 | ||
├── data # 语料及精调数据 | ||
├── tools # 数据清洗等工具 | ||
├── assets # 静态资源 | ||
├── resources # 项目资源 | ||
├── models # 基座模型及 lora 权重 | ||
│ ├── base_models | ||
│ └── lora_weights | ||
├── outputs # 指令微调的输出权重 | ||
├── data # 实验数据 | ||
├── scripts # 脚本目录 | ||
│ ├── finetune.sh # 指令微调脚本 | ||
│ └── webui.sh # 启动服务脚本 | ||
├── templates # prompt 模板 | ||
├── tools # 工具包 | ||
├── utils | ||
├── train_clm.py # 二次训练 | ||
├── finetune.py # 指令微调 | ||
├── webui.py # 启动服务 | ||
├── README.md | ||
├── requirements.txt | ||
└── src # 源码 | ||
├── finetune.py | ||
├── generate.py | ||
├── models # 基座模型及 Lora 权重 | ||
│ ├── base_models | ||
│ └── lora_weights | ||
├── outputs | ||
├── scripts # 脚本文件 | ||
│ ├── finetune.sh # 指令微调 | ||
│ └── generate.sh # 服务创建 | ||
├── templates | ||
└── utils | ||
└── requirements.txt | ||
``` | ||
|
||
|
||
|
@@ -119,13 +116,13 @@ LawGPT 系列模型的训练过程分为两个阶段: | |
|
||
### 二次训练流程 | ||
|
||
1. 参考 `src/data/example_instruction_train.json` 构造二次训练数据集 | ||
2. 运行 `src/scripts/train_lora.sh` | ||
1. 参考 `resources/example_instruction_train.json` 构造二次训练数据集 | ||
2. 运行 `scripts/train_clm.sh` | ||
|
||
### 指令精调步骤 | ||
|
||
1. 参考 `src/data/example_instruction_tune.json` 构造指令微调数据集 | ||
2. 运行 `src/scripts/finetune.sh` | ||
1. 参考 `resources/example_instruction_tune.json` 构造指令微调数据集 | ||
2. 运行 `scripts/finetune.sh` | ||
|
||
### 计算资源 | ||
|
||
|
@@ -222,4 +219,4 @@ LawGPT 系列模型的训练过程分为两个阶段: | |
|
||
## 引用 | ||
|
||
如果您觉得我们的工作对您有所帮助,请考虑引用该项目 | ||
如果您觉得我们的工作对您有所帮助,请考虑引用该项目 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"instruction": "酒驾撞人要判多久?", | ||
"input": "", | ||
"output": "《刑法》第一百三十三条规定:违反交通运输管理法规,因而发生重大事故,致人重伤、死广或者使公私财产遭受重大损失的,处三年以下有期徒刑或者拘役;交通运输肇事后逃逸,致人重伤的,处三年以上七年以下有期徒刑。交通肇事后逃逸致人死亡的,处七年以上有期徒刑。" | ||
}, | ||
{ | ||
"instruction": "偷狗被派出所抓到,会怎么处理?", | ||
"input": "", | ||
"output": "取决于偷盗的狗的价值,可能按盗窃罪的罪名处理。如果价值达到犯罪标准,就构成盗窃罪,要承担刑事责任;如果不到犯罪标准,就是治安处罚、罚款或者拘留治安处罚这会涉嫌构成盗窃。如果不到一千元,则不会构成犯罪。如果超过一千元,则可能会是构成犯罪的。" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
export WANDB_MODE=disabled # 禁用wandb | ||
|
||
# 使用chinese-alpaca-plus-7b-merged模型在law_data.json数据集上finetune | ||
experiment_name="chinese-alpaca-plus-7b-law-e1" | ||
|
||
# 单卡或者模型并行 | ||
python finetune.py \ | ||
--base_model "minlik/chinese-alpaca-plus-7b-merged" \ | ||
--data_path "./data/finetune_law_data.json" \ | ||
--output_dir "./outputs/"${experiment_name} \ | ||
--batch_size 64 \ | ||
--micro_batch_size 8 \ | ||
--num_epochs 20 \ | ||
--learning_rate 3e-4 \ | ||
--cutoff_len 256 \ | ||
--val_set_size 0 \ | ||
--lora_r 8 \ | ||
--lora_alpha 16 \ | ||
--lora_dropout 0.05 \ | ||
--lora_target_modules "[q_proj,v_proj]" \ | ||
--train_on_inputs True \ | ||
--add_eos_token True \ | ||
--group_by_length False \ | ||
--wandb_project \ | ||
--wandb_run_name \ | ||
--wandb_watch \ | ||
--wandb_log_model \ | ||
--resume_from_checkpoint "./outputs/"${experiment_name} \ | ||
--prompt_template_name "alpaca" \ | ||
|
||
|
||
# 多卡数据并行 | ||
# WORLD_SIZE=8 CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 torchrun --nproc_per_node=8 --master_port=1234 finetune.py \ | ||
# --base_model "minlik/chinese-alpaca-plus-7b-merged" \ | ||
# --data_path "./data/finetune_law_data.json" \ | ||
# --output_dir "./outputs/"${experiment_name} \ | ||
# --batch_size 64 \ | ||
# --micro_batch_size 8 \ | ||
# --num_epochs 20 \ | ||
# --learning_rate 3e-4 \ | ||
# --cutoff_len 256 \ | ||
# --val_set_size 0 \ | ||
# --lora_r 8 \ | ||
# --lora_alpha 16 \ | ||
# --lora_dropout 0.05 \ | ||
# --lora_target_modules "[q_proj,v_proj]" \ | ||
# --train_on_inputs True \ | ||
# --add_eos_token True \ | ||
# --group_by_length False \ | ||
# --wandb_project \ | ||
# --wandb_run_name \ | ||
# --wandb_watch \ | ||
# --wandb_log_model \ | ||
# --resume_from_checkpoint "./outputs/"${experiment_name} \ | ||
# --prompt_template_name "alpaca" \ |
Oops, something went wrong.