llama2 lora fine tuning
1.0.0
ปรับแต่งโมเดล Llama-2-7B-Chat บน P100S สองตัว (16G)
แหล่งข้อมูลใช้รูปแบบ ALPACA และประกอบด้วยแหล่งข้อมูลสองแหล่ง: รถไฟและการตรวจสอบความถูกต้อง
หน่วยความจำวิดีโอ 16G ขึ้นไป (P100 หรือ T4 ขึ้นไป) หนึ่งบล็อกขึ้นไป
git clone https://github.com/git-cloner/llama2-lora-fine-tuning
cd llama2-lora-fine-tuning # 创建虚拟环境
conda create -n llama2 python=3.9 -y
conda activate llama2
# 下载github.com上的依赖资源(需要反复试才能成功,所以单独安装)
export GIT_TRACE=1
export GIT_CURL_VERBOSE=1
pip install git+https://github.com/PanQiWei/AutoGPTQ.git -i https://pypi.mirrors.ustc.edu.cn/simple --trusted-host=pypi.mirrors.ustc.edu.cn
pip install git+https://github.com/huggingface/peft -i https://pypi.mirrors.ustc.edu.cn/simple
pip install git+https://github.com/huggingface/transformers -i https://pypi.mirrors.ustc.edu.cn/simple
# 安装其他依赖包
pip install -r requirements.txt -i https://pypi.mirrors.ustc.edu.cn/simple
# 验证bitsandbytes
python -m bitsandbytespython model_download.py --repo_id daryl149/llama-2-7b-chat-hf # 使用了https://github.com/ymcui/Chinese-LLaMA-Alpaca.git的方法扩充中文词表
# 扩充完的词表在merged_tokenizes_sp(全精度)和merged_tokenizer_hf(半精度)
# 在微调时,将使用--tokenizer_name ./merged_tokenizer_hf参数
python merge_tokenizers.py
--llama_tokenizer_dir ./models/daryl149/llama-2-7b-chat-hf
--chinese_sp_model_file ./chinese_sp.modelมีพารามิเตอร์หลายตัวที่สามารถปรับได้:
| พารามิเตอร์ | อธิบาย | รับค่า |
|---|---|---|
| load_in_bits | ความแม่นยำของแบบจำลอง | 4 และ 8. หากหน่วยความจำวิดีโอไม่ล้นให้ลองเลือกความแม่นยำสูง 8 |
| block_size | ความยาวสูงสุดของโทเค็น | ตัวเลือกแรก 2048, หน่วยความจำล้น, 1024, 512 ฯลฯ |
| per_device_train_batch_size | จำนวนแบทช์ต่อการ์ดที่โหลดในแต่ละครั้งในระหว่างการฝึกอบรม | ตราบใดที่หน่วยความจำไม่ล้นลองไปที่การเลือกตั้งทั่วไป |
| per_device_eval_batch_size | จำนวนแบทช์ต่อการ์ดที่โหลดในแต่ละครั้งในระหว่างการประเมินผล | ตราบใดที่หน่วยความจำไม่ล้นลองไปที่การเลือกตั้งทั่วไป |
| รวม | ลำดับกราฟิกการ์ดที่ใช้ | ตัวอย่างเช่นสองชิ้น: localhost: 1,2 (โปรดทราบว่าลำดับไม่จำเป็นต้องเหมือนกับที่ Nvidia-Smi เห็น) |
| num_train_epochs | จำนวนรอบการฝึกอบรม | อย่างน้อย 3 รอบ |
chmod +x finetune-lora.sh
# 微调
./finetune-lora.sh
# 微调(后台运行)
pkill -9 -f finetune-lora
nohup ./finetune-lora.sh > train.log 2>&1 &
tail -f train.logCUDA_VISIBLE_DEVICES=0 python generate.py
--base_model ' ./models/daryl149/llama-2-7b-chat-hf '
--lora_weights ' output/checkpoint-2000 '
--load_8bit #不加这个参数是用的4bit