AI知识库

53AI知识库

学习大模型的前沿技术与行业应用场景


LlamaFactory进行llama3微调,有Colab教程可上手体验学习
发布日期:2024-04-26 07:59:58 浏览次数: 2534


最近,大模型领域最受关注的事件就是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=sharing
from 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! I am Llama-3, an AI assistant developed by LLaMA Factory. How can I assist you today?"},{"instruction": "hello","input": "","output": "Hello! I am Llama-3, an AI assistant developed by LLaMA Factory. How can I assist you today?"},{"instruction": "Who are you?","input": "","output": "I am Llama-3, an AI assistant developed by LLaMA Factory. How can I assist you today?"},...

更多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
同时,黑马Groq也推出了自己的微调教程。
地址:https://colab.research.google.com/drive/1RmC3vZT2LqH4TZsG-5yVUlbcyvAtCWIQ?usp=sharing



53AI,企业落地应用大模型首选服务商

产品:大模型应用平台+智能体定制开发+落地咨询服务

承诺:先做场景POC验证,看到效果再签署服务协议。零风险落地应用大模型,已交付160+中大型企业

联系我们

售前咨询
186 6662 7370
预约演示
185 8882 0121

微信扫码

与创始人交个朋友

回到顶部

 
扫码咨询