• Stars
    star
    656
  • Rank 68,231 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created over 1 year ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ChatGLM-6B 指令学习|指令数据|Instruct

InstructGLM

基于ChatGLM-6B+LoRA在指令数据集上进行微调

本项目主要内容:

  • 🚀 2023/4/9 发布了基于100万条由BELLE项目生成的中文指令数据的Lora权重,具体可见output/belle/chatglm-lora.pt
  • 🚀 2023/4/8 基于deepspeed支持多卡微调,速度相比单卡提升8-9倍具体设置可见 微调3 基于DeepSpeed进行Lora微调
  • 🚀 2023/3/28 开源了基于alpaca和belle数据指令微调后的lora权重,详情可见output
  • 🚀 2023/3/25 针对ChatGLM-6B模型基于LoRA技术进行微调
  • 🚀 2023/3/23 基于gradio的demo完善

Todo

  • deepspeed支持
  • 模型评估,如何评估微调后的模型效果

开源指令数据集

instruction:52K 条指令中的每一条都是唯一的,答案由text-davinci-003模型生成得到的

1百万数据:https://huggingface.co/datasets/BelleGroup/generated_train_1M_CN

生成方式基于种子prompt,调用openai的api生成中文指令

Guanaco 是在 Meta 的 LLaMA 7B 模型上训练的指令跟随语言模型。在 Alpaca 模型原始 52K 数据的基础上,我们添加了额外的 98,369 个条目,涵盖英语、简体中文、繁体中文(台湾)、繁体中文(香港)、日语、德语以及各种语言和语法任务。通过使用这些丰富的数据重新训练和优化模型,Guanaco 在多语言环境中展示了出色的性能和潜力。项目链接可以查看 https://guanaco-model.github.io/

与原始alpaca数据json格式相同,数据生成的方法是机器翻译和self-instruct

加入除了alpaca之外的其他中文聊天对话 人工微调,部分并不中文化的问题,我们将重新询问chatgpt或文心一言,重新获取回答并覆盖掉alpaca的回答

  • firefly-train-1.1M , 一份高质量的包含1.1M中文多任务指令微调数据集,包含23种常见的中文NLP任务的指令数据。对于每个任务,由人工书写若干指令模板,保证数据的高质量与丰富度。

微调1:alpaca英文指令数据

斯坦福羊驼52k数据,原始数据格式如下:

{
    "instruction": "Evaluate this sentence for spelling and grammar mistakes",
    "input": "He finnished his meal and left the resturant",
    "output": "He finished his meal and left the restaurant."
}

数据集地址:https://github.com/tatsu-lab/stanford_alpaca

1.数据预处理

转化alpaca数据集为jsonl,这一步可以执行设置数据转换后格式,比如:

###Instruction:xxx###Input:xxxx###Response:xxx
python cover_alpaca2jsonl.py \
    --data_path data/alpaca_data.json \
    --save_path data/alpaca_data.jsonl 

对文本进行tokenize,加快训练速度,文本长度可根据运行资源自行设置

python tokenize_dataset_rows.py \
    --jsonl_path data/alpaca_data.jsonl \
    --save_path data/alpaca \
    --max_seq_length 320

2. 模型训练

python train_lora.py \
    --dataset_path data/alpaca \
    --lora_rank 8 \
    --per_device_train_batch_size 2 \
    --gradient_accumulation_steps 1 \
    --max_steps 52000 \
    --save_steps 1000 \
    --save_total_limit 2 \
    --learning_rate 2e-5 \
    --fp16 \
    --remove_unused_columns false \
    --logging_steps 50 \
    --output_dir output

微调2:BELLE中文指令数据

包含543314条由BELLE项目生成的中文指令数据,数据格式如下:

input target
用一句话描述地球为什么是独一无二的。\n 地球上有适宜生命存在的条件和多样化的生命形式

数据集地址:https://huggingface.co/datasets/BelleGroup/generated_train_0.5M_CN

1.数据预处理

转化bell数据集为jsonl

python cover_alpaca2jsonl.py \
    --dataset_name BelleGroup/generated_train_0.5M_CN \
    --save_path data/belle_data.jsonl 

文本长度统计

count    543314.000000
mean         83.536944
std          95.665178
min           4.000000
25%          33.000000
50%          51.000000
75%          88.000000
90%         194.000000
max        4410.000000
Name: input_len, dtype: float64

count    543314.000000
mean        121.079030
std         165.472722
min           1.000000
25%          27.000000
50%          67.000000
75%         151.000000
90%         296.000000
max        9463.000000
Name: target_len, dtype: float64

分词处理

python tokenize_dataset_rows.py \
    --jsonl_path data/belle_data.jsonl \
    --save_path data/belle \
    --max_seq_length 320

转换后的数据:

                                           input_ids  seq_len                                                                                                                   
0  [20005, 92863, 20012, 20005, 83864, 87784, 871...       20
1  [20005, 92863, 20012, 20005, 91432, 86523, 885...       80
2  [20005, 92863, 20012, 104069, 85056, 86334, 89...       61
3  [20005, 92863, 20012, 91492, 89122, 83866, 852...       24
4  [20005, 92863, 20012, 20005, 83834, 99899, 927...       24

2. 模型训练

  • 基于原始chatglm-6b训练
python train_lora.py \
    --dataset_path data/belle \
    --lora_rank 8 \
    --per_device_train_batch_size 2 \
    --gradient_accumulation_steps 1 \
    --max_steps 52000 \
    --save_steps 1000 \
    --save_total_limit 2 \
    --learning_rate 2e-5 \
    --fp16 \
    --remove_unused_columns false \
    --logging_steps 50 \
    --output_dir output
  • 基于alpaca的lora继续微调
python train_lora.py \
    --dataset_path data/belle \
    --lora_rank 8 \
    --per_device_train_batch_size 8 \
    --gradient_accumulation_steps 1 \
    --max_steps 52000 \
    --save_steps 10000 \
    --save_total_limit 2 \
    --learning_rate 2e-5 \
    --fp16 \
    --remove_unused_columns false \
    --logging_steps 50 \
    --output_dir output/belle \
    --is_resume True \
    --resume_path output/alpaca/chatglm-lora.pt

微调3:基于DeepSpeed进行Lora微调

支持多卡+zero方案,训练速度可提高8倍左右

accelerate launch --config_file config/default_config.yaml train_deepspeed.py

实验环境

实验结果

  • 训练好的lora权重
└─output
    ├─alpaca:基于52k微调的lora权重
    ├─belle::基于52k微调的lora权重+belle微调的权重52000steps
    └─belle_raw:belle微调的权重104000steps


链接:https://pan.baidu.com/s/1c-zRSEUn4151YLoowPN4YA?pwd=hxbr
提取码:hxbr
--来自百度网盘超级会员V3的分享
  • alpaca数据微调效果

  • belle数据微调效果

Reference

非常感谢以下作者的无私开源

Bugs

  • gcc版本升级
yum install centos-release-scl -y
yum install devtoolset-9 -y

#临时覆盖系统原有的gcc引用
scl enable devtoolset-9 bash

# 查看gcc版本
gcc -v

More Repositories

1

Chinese-LangChain

中文langchain项目|小必应,Q.Talk,强聊,QiangTalk
Python
2,671
star
2

sentence-similarity

问题句子相似度计算,即给定客服里用户描述的两句话,用算法来判断是否表示了相同的语义。
Python
363
star
3

NLP-Interview-Notes

📚 专门为自然语言处理(NLP)面试准备的学习笔记与资料
Jupyter Notebook
341
star
4

how-to-train-tokenizer

怎么训练一个LLM分词器
Python
122
star
5

char-rnn-writer

基于Char RNN实现的“作家”应用,可以写诗也可以生成名字,看起来还👌
Python
83
star
6

GoGPT

GoGPT:基于Llama/Llama 2训练的中英文增强大模型|Chinese-Llama2
Python
78
star
7

text-cluster

🍡 文本聚类 k-means算法及实战
Python
50
star
8

ner-english

💻 英文命名实体识别(NER)的研究
Python
49
star
9

quincy-python

📖 学习python过程中的知识积累
Jupyter Notebook
46
star
10

pyspider-project

Python爬虫项目集合
Jupyter Notebook
41
star
11

daguan

2018达观杯文本智能处理挑战赛:基于ML、DL实现文本分类
Python
38
star
12

20newsgroups-text-classification

对20 newsgroups 数据集 进行文本分类
Python
27
star
13

quincy-python-v2

python学习过程中的积累
Jupyter Notebook
24
star
14

Text-Classification-Application

🎒 基于CNN实现的文本分类应用
Python
24
star
15

transformers-tutorial

Jupyter Notebook
21
star
16

baidu-search

vue实现百度下拉搜索
JavaScript
20
star
17

Product-Entity-Recognition

商品标题实体识别
Jupyter Notebook
20
star
18

Data-Finance-Cup

2019厦门国际银行“数创金融杯”数据建模大赛 复赛第六
Jupyter Notebook
19
star
19

amp-pytorch

Pytorch自动混合精度训练模板
Python
17
star
20

seq2seq-nmt

😺 基于Keras实现seq2seq,进行英文到中文的翻译
Python
17
star
21

competion-zoo

比赛中的通用方法和模板
Jupyter Notebook
16
star
22

KDD2024-WhoIsWho-Top3

KDD2024-WhoIsWho-Top3
Python
14
star
23

Ashare-Industry-Trends

公开新闻预测A股行业板块动向
Python
11
star
24

tree2retriever

Recursive Abstractive Processing for Tree-Organized Retrieval
Python
11
star
25

Food-Safety-Review

O2O商铺食品安全相关评论发现
Python
11
star
26

triple_extraction

基于依存句法与语义角色标注的三元组抽取
Python
10
star
27

GoGPT-Instruction

GoGPT中文指令数据集构造
Python
10
star
28

TensorFlow-MNIST-WEBAPP

使用tensorflow实现手写字体分类以及web应用
JavaScript
10
star
29

textclassify

文本分类:bow(词袋特征)、tfidf、word2vec、sklearn
Python
8
star
30

exploratory-data-analysis

🎅 Exploratory Data Analysis 探索性数据分析
Jupyter Notebook
8
star
31

message-board

vue2.0+php实现交互的留言墙
JavaScript
7
star
32

Cityproperty-Rent-Forecast

城市-房产租金预测
Jupyter Notebook
7
star
33

shence-cup

🐇 “神策杯”关键词提取
Python
7
star
34

LLaMA-Instruct-Learning

Python
6
star
35

text-summarization-tensorflow

文本摘要
Python
6
star
36

bond-prospectus

债券募集说明书
Python
5
star
37

game-knowledge-graph

🎮 关于游戏的知识图谱
Python
5
star
38

yanqiangmiffy

5
star
39

keras_bert_ner

bert实现命名实体识别
Python
5
star
40

huggingface-dl

Command-line program to download models from huggingface.co
Python
4
star
41

llm-finetune

开源大模型微调
Python
4
star
42

Chinese-NER-GOLD

如何把中文实体识别做好
3
star
43

rnn-by-numpy

使用numpy实现rnn和语言模型
Python
3
star
44

daguan-information-extraction

“达观杯”文本智能信息抽取挑战赛
Python
3
star
45

Loan-Default-Prediction

零基础入门金融风控-贷款违约预测
Jupyter Notebook
3
star
46

keyword-finder

关键词提取
Python
3
star
47

tibetan-mnist

基于TibetanMNIST图像分类与图像匹配
Python
3
star
48

quincy-keras

keras学习资料/教程
Jupyter Notebook
3
star
49

poteman

2
star
50

Nezha-Pytorch

Python
2
star
51

sent_match

Python
2
star
52

ctrip14-learning

携程出行产品未来14个月销量预测
2
star
53

rucweibo

《应用系统开发实践》----微博系统RucWeibo
Java
2
star
54

bank-marketing

线上 0.94098 49/1551
Jupyter Notebook
1
star
55

char-rnn-pytorch

🌊 基于pytorch实现char rnn,生成英文名字
Python
1
star
56

spider-projects

爬虫项目
Jupyter Notebook
1
star
57

CS224n-NLP-DL

斯坦福cs224n:自然语言处理与深度学习
1
star
58

dog_vs_cat

猫狗大战
Python
1
star
59

Noun-Phrase-Extraction

Jupyter Notebook
1
star
60

loan-prediction-iii

贷款预测根据用户的详细信息来预测贷款是否发放
Jupyter Notebook
1
star
61

text-sentiment-classification

文本情感分类
Jupyter Notebook
1
star
62

personal-credit-evaluation

个人房产信用评估模型
Jupyter Notebook
1
star
63

GoDocs

针对RAG系统问答的文档解析工具库
Jupyter Notebook
1
star
64

GovDoc-Generator

基于大模型GoGPT微调的公文生成器
1
star
65

Weibo-Analysis

Python
1
star