InstructGLM 基于ChatGLM-6B+LoRA在指令數據集上進行微調 https://github.com/yanqiangmiffy/InstructGLM 本項目主要內容: ?? 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 [x] deepspeed支持 [ ] 模型評估,如何評估微調后的模型效果 開源指令數據集 斯坦福52k英文指令數據 instruction:52K 條指令中的每一條都是唯一的,答案由text-davinci-003模型生成得到的 BELLE項目生成的中文指令數據:0.5m&1m 1百萬數據:https:///datasets/BelleGroup/generated_train_1M_CN 生成方式基于種子prompt,調用openai的api生成中文指令 GuanacoDataset 多語言指令數據集 Guanaco 是在 Meta 的 LLaMA 7B 模型上訓練的指令跟隨語言模型。在 Alpaca 模型原始 52K 數據的基礎上,我們添加了額外的 98,369 個條目,涵蓋英語、簡體中文、繁體中文(臺灣)、繁體中文(香港)、日語、德語以及各種語言和語法任務。通過使用這些豐富的數據重新訓練和優化模型,Guanaco 在多語言環境中展示了出色的性能和潛力。項目鏈接可以查看 https://guanaco-model./ alpaca中文指令微調數據集 與原始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:xxxpython 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項目生成的中文指令數據,數據格式如下:inputtarget 用一句話描述地球為什么是獨一無二的。\n 地球上有適宜生命存在的條件和多樣化的生命形式 數據集地址:https:///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_new.py 實驗環境 安裝所需要的包:pip install -r requirements.txt -i https://pypi.tuna./simple 顯卡:2xA100 80G 實驗結果 訓練好的lora權重└─output ├─alpaca:基于52k微調的lora權重 ├─belle::基于52k微調的lora權重+belle微調的權重52000steps └─belle_raw:belle微調的權重104000steps 鏈接:https://pan.baidu.com/s/1c-zRSEUn4151YLoowPN4YA?pwd=hxbr --來自百度網盤超級會員V3的分享 alpaca數據微調效果 ![]() belle數據微調效果 ![]() Reference 非常感謝以下作者的無私開源 https://github.com/mymusise/ChatGLM-Tuning https:///BelleGroup/BELLE-7B-2M https://github.com/LianjiaTech/BELLE https:///datasets/BelleGroup/generated_train_0.5M_CN https:///datasets/JosephusCheung/GuanacoDataset https://guanaco-model./ https://github.com/carbonz0/alpaca-chinese-dataset https://github.com/THUDM/ChatGLM-6B https:///THUDM/chatglm-6b https://github.com/lich99/ChatGLM-finetune-LoRA Bugs gcc版本升級yum install centos-release-scl -y yum install devtoolset-9 -y #臨時覆蓋系統原有的gcc引用 scl enable devtoolset-9 bash # 查看gcc版本 gcc -v |
|