|
 最近,大模型领域最受关注的事件就是meta发布了llama3,前段时间我们介绍的LlamaFactory也第一时间支持了llama3,并且发布了自己的Colab微调实战案例,并对外推出了两个社区中文微调版本:Llama3-8B-Chinese-Chat,首个使用 ORPO 算法微调的中文 Llama3 模型,文章介绍:https://zhuanlan.zhihu.com/p/693905042(可点原文链接阅读) Llama3-Chinese,首个使用 DoRA 和 LoRA+ 算法微调的中文 Llama3 模型,仓库地址:https://github.com/seanzhang-zhichen/llama3-chinese
下面我们一起来看看它的微调案例(可以直接在Colab上使用免费GPU运行),整个流程与其他模型微调基本一致: 地址:https://colab.research.google.com/drive/1d5KQtbemerlSDSxZIfAaWXhKr30QypiK?usp=sharingfrom llmtuner import run_exp
%cd /content/LLaMA-Factory/
run_exp(dict(stage="sft",do_train=True,model_name_or_path="unsloth/llama-3-8b-Instruct-bnb-4bit",dataset="identity,alpaca_gpt4_en,alpaca_gpt4_zh",template="llama3",finetuning_type="lora",lora_target="all",output_dir="llama3_lora",per_device_train_batch_size=2,gradient_accumulation_steps=4,lr_scheduler_type="cosine",logging_steps=10,warmup_ratio=0.1,save_steps=1000,learning_rate=5e-5,num_train_epochs=3.0,max_samples=500,max_grad_norm=1.0,quantization_bit=4,loraplus_lr_ratio=16.0,use_unsloth=True,fp16=True,))
训练数据集:
[{"instruction":"hi","input":"","output":"Hello!IamLlama-3,anAIassistantdevelopedbyLLaMAFactory.HowcanIassistyoutoday?"},{"instruction":"hello","input":"","output":"Hello!IamLlama-3,anAIassistantdevelopedbyLLaMAFactory.HowcanIassistyoutoday?"},{"instruction":"Whoareyou?","input":"","output":"IamLlama-3,anAIassistantdevelopedbyLLaMAFactory.HowcanIassistyoutoday?"},...更多llama3数据集(huggingface&魔搭): https://huggingface.co/datasets?sort=trending&search=llama3 值得一提的是,llamafactory的微调方案利用unsloth加速,而unsloth也在更早的时候发布了自己的微调方案,感兴趣的读者可以体验。 unsloth(https://github.com/unslothai/unsloth)是一个用于加速深度学习模型训练的开源工具。它可以实现5倍到30倍的训练速度提升,同时还能减少50%的内存占用。 地址:https://colab.research.google.com/drive/1mPw6P52cERr93w3CMBiJjocdTnyPiKTX#scrollTo=IqM-T1RTzY6C地址:https://colab.research.google.com/drive/1RmC3vZT2LqH4TZsG-5yVUlbcyvAtCWIQ?usp=sharing
|