Commit 4fae534d authored by zhaoying1's avatar zhaoying1
Browse files

Update README.md

parent 3191e623
...@@ -6,9 +6,8 @@ ...@@ -6,9 +6,8 @@
## 模型结构 ## 模型结构
ChatGLM-6B 是清华大学开源的开源的、支持中英双语的对话语言模型,基于 [General Language Model (GLM)](https://github.com/THUDM/GLM) 架构,具有 62 亿参数。ChatGLM-6B 使用了和 ChatGPT 相似的技术,针对中文问答和对话进行了优化。经过约 1T 标识符的中英双语训练,辅以监督微调、反馈自助、人类反馈强化学习等技术的加持,62 亿参数的 ChatGLM-6B 已经能生成相当符合人类偏好的回答。 ChatGLM-6B 是清华大学开源的开源的、支持中英双语的对话语言模型,基于 [General Language Model (GLM)](https://github.com/THUDM/GLM) 架构,具有 62 亿参数。ChatGLM-6B 使用了和 ChatGPT 相似的技术,针对中文问答和对话进行了优化。经过约 1T 标识符的中英双语训练,辅以监督微调、反馈自助、人类反馈强化学习等技术的加持,62 亿参数的 ChatGLM-6B 已经能生成相当符合人类偏好的回答。
<div align="center"> <div align="center">
<img src="ptuning/media/GLM.png" width="550" height="200"> <img src="ptuning/media/GLMblock.png" width="550" height="200">
</div> </div>
以下是ChatGLM-6B的主要网络参数配置: 以下是ChatGLM-6B的主要网络参数配置:
...@@ -21,6 +20,9 @@ ChatGLM-6B 是清华大学开源的开源的、支持中英双语的对话语言 ...@@ -21,6 +20,9 @@ ChatGLM-6B 是清华大学开源的开源的、支持中英双语的对话语言
## 算法原理 ## 算法原理
ChatGLM-6B基于GLM架构开发。GLM是一种基于Transformer的语言模型,以自回归空白填充为训练目标, 同时具备自回归和自编码能力。 ChatGLM-6B基于GLM架构开发。GLM是一种基于Transformer的语言模型,以自回归空白填充为训练目标, 同时具备自回归和自编码能力。
<div align="center">
<img src="ptuning/media/GLM.png" width="550" height="200">
</div>
## 环境配置 ## 环境配置
...@@ -32,6 +34,7 @@ docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk ...@@ -32,6 +34,7 @@ docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk
进入docker,安装docker中没有的依赖: 进入docker,安装docker中没有的依赖:
``` ```
docker run -dit --network=host --name=chatglm --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:1.13.1-centos7.6-dtk-23.04-py38-latest
pip install transformers==4.28.0 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com pip install transformers==4.28.0 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
pip install accelerate sentencepiece mdtex2html gradio rouge_chinese nltk jieba datasets protobuf peft -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com pip install accelerate sentencepiece mdtex2html gradio rouge_chinese nltk jieba datasets protobuf peft -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
``` ```
...@@ -73,23 +76,25 @@ pip install -r requirements.txt ...@@ -73,23 +76,25 @@ pip install -r requirements.txt
Hugging Face模型下载地址: Hugging Face模型下载地址:
[ChatGLM-6B](https://huggingface.co/THUDM/chatglm-6b) [ChatGLM-6B](https://huggingface.co/THUDM/chatglm-6b)
## P-tuning v2 微调训练 ## 训练
### P-tuning v2 微调训练
本仓库实现了对于ChatGLM-6B模型基于[P-Tuning v2](https://github.com/THUDM/P-tuning-v2)的微调。P-Tuning v2是由清华大学提出的一种高效参数微调方法。 本仓库实现了对于ChatGLM-6B模型基于[P-Tuning v2](https://github.com/THUDM/P-tuning-v2)的微调。P-Tuning v2是由清华大学提出的一种高效参数微调方法。
### 单机多卡训练 #### 单机多卡训练
``` ```
cd ptuning cd ptuning
bash ptuning_train.sh bash ptuning_train.sh
``` ```
注意:请根据自己的需求配置其中的模型路径、数据集路径、batchsize、学习率等参数; 注意:请根据自己的需求配置其中的模型路径、数据集路径、batchsize、学习率等参数;
### 推理测评 #### 推理测评
在 P-tuning v2 训练时模型只保存 PrefixEncoder 部分的参数,所以在推理时需要同时加载原 ChatGLM-6B 模型以及 PrefixEncoder 的权重,可直接运行一下命令: 在 P-tuning v2 训练时模型只保存 PrefixEncoder 部分的参数,所以在推理时需要同时加载原 ChatGLM-6B 模型以及 PrefixEncoder 的权重,可直接运行一下命令:
``` ```
cd ptuning cd ptuning
bash evaluate_ptuning.sh bash evaluate_ptuning.sh
``` ```
### Results #### Results
- 训练Loss - 训练Loss
<div align="center"> <div align="center">
<img src="./ptuning/media/6B_ds_pt_bs16_accum1_4cards_zero2_5e-3.jpg" width="400" height="300"> <img src="./ptuning/media/6B_ds_pt_bs16_accum1_4cards_zero2_5e-3.jpg" width="400" height="300">
...@@ -101,29 +106,29 @@ Hugging Face模型下载地址: ...@@ -101,29 +106,29 @@ Hugging Face模型下载地址:
| :------: | :------: |:------: | :------: |:------: | :------: | | :------: | :------: |:------: | :------: |:------: | :------: |
| 2000 steps |  3.57 | 7.9777 | 31.0344 |  6.981 | 24.7393 | | 2000 steps |  3.57 | 7.9777 | 31.0344 |  6.981 | 24.7393 |
## Finetune全参数微调 ### Finetune全参数微调
### 单机多卡训练 #### 单机多卡训练
``` ```
cd ptuning cd ptuning
bash ft_train.sh bash ft_train.sh
``` ```
注意:请根据自己的需求配置其中的模型路径、数据集路径、batchsize、学习率等参数; 注意:请根据自己的需求配置其中的模型路径、数据集路径、batchsize、学习率等参数;
### 集群训练 #### 集群训练
``` ```
cd ptuning/slurm_scripts cd ptuning/slurm_scripts
bash run.shi bash run.sh
``` ```
注意:请根据自己的需求配置其中的模型路径、数据集路径、batchsize、学习率等参数; 注意:请根据自己的需求配置其中的模型路径、数据集路径、batchsize、学习率等参数;
### 推理测评 #### 推理测评
``` ```
cd ptuning cd ptuning
bash evaluate_ft.sh bash evaluate_ft.sh
``` ```
### Results #### Results
- 训练Loss - 训练Loss
<div align="center"> <div align="center">
<img src="./ptuning/media/6B_ds_ft_bs32_accum1_4cards_zero3_5e-5.jpg" width="400" height="300"> <img src="./ptuning/media/6B_ds_ft_bs32_accum1_4cards_zero3_5e-5.jpg" width="400" height="300">
...@@ -146,13 +151,13 @@ Hugging Face模型下载地址: ...@@ -146,13 +151,13 @@ Hugging Face模型下载地址:
| Training Loss | 3.00 | 3.57 | 3.32 | --> | Training Loss | 3.00 | 3.57 | 3.32 | -->
## LoRA 微调训练 ### LoRA 微调训练
### 单机多卡训练 #### 单机多卡训练
``` ```
cd ptuning cd ptuning
bash lora_train.sh bash lora_train.sh
``` ```
### LoRA推理 #### LoRA推理
``` ```
python infer_lora.py python infer_lora.py
``` ```
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment