在Windows上用Llama Factory微调Llama 3的基本操作

这篇博客参考了一些文章,例如:教程:利用LLaMA_Factory微调llama3:8b大模型_llama3模型微调保存-CSDN博客

也可以参考Llama Factory的Readme:GitHub - hiyouga/LLaMA-Factory: Unify Efficient Fine-Tuning of 100+ LLMsUnify Efficient Fine-Tuning of 100+ LLMs. Contribute to hiyouga/LLaMA-Factory development by creating an account on GitHub.icon-default.png?t=N7T8https://github.com/hiyouga/LLaMA-Factory?tab=readme-ov-file#installation首先将Llama Factory clone到本地:GitHub - hiyouga/LLaMA-Factory: Unify Efficient Fine-Tuning of 100+ LLMs 

其次创建一个conda环境:

conda create -n llama_factory python=3.10

激活环境后首先安装pytorch,具体参考这个页面:Start Locally | PyTorch,例如:

conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia

而后进入到LLaMA-Factory文件夹,参考其Readme,运行:

pip install -e .[torch,metrics]

同时,按照其Readme,在Windows系统上还需要运行:

pip install https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.2.post2-py3-none-win_amd64.whl

具体原因我就不展开讲了。然后依次运行:

Set CUDA_VISIBLE_DEVICES=0
Set GRADIO_SHARE=1
llamafactory-cli webui

就可以看到其webui了。不过这时候还没有模型参数文件,对于国内用户而言,可以在这里https://modelscope.cn/organization/LLM-Researchicon-default.png?t=N7T8https://modelscope.cn/organization/LLM-Research

进行下载,例如可以下载Llama3中文版本(如果没有git lfs可以用前两个命令安装):

conda install git-lfs
git-lfs install
git lfs clone https://www.modelscope.cn/LLM-Research/Llama3-8B-Chinese-Chat.git

下载好之后,可以构造自己的微调数据集,具体而言,按照这里的介绍:

https://github.com/hiyouga/LLaMA-Factory/tree/main/data

Llama Factory支持alpaca and sharegpt的格式,前者类似于这种格式:

[
  {
    "instruction": "human instruction (required)",
    "input": "human input (optional)",
    "output": "model response (required)",
    "system": "system prompt (optional)",
    "history": [
      ["human instruction in the first round (optional)", "model response in the first round (optional)"],
      ["human instruction in the second round (optional)", "model response in the second round (optional)"]
    ]
  }
]

我们构造数据集的时候,最简单的方法就是只构造instruction和output。把生成的json文件放到LLaMA-Factory\data目录下,然后打开dataset_info.json文件,增加这个文件名记录即可,例如我这里增加:

  "private_train": {
    "file_name": "private_train.json"
  },

选择自己的私有数据集,可以预览一下,然后就可以开始训练了。

训练完成后切换到Export,然后在上面的“微调方法”——“检查点路径”中选择刚才存储的目录Train_2024_xxxx之类,然后指定导出文件的目录,然后就可以导出了。

导出之后我们可以加载微调之后的模型并测试了。当然,如果训练数据集比较小的话,测试的效果也不会太好。如果大家只是想对微调效果和特定问题进行展示,可以训练模型到过拟合,呵呵呵。

就记录这么多。

  • 16
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值