在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.https://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环境:

python 复制代码
conda create -n llama_factory python=3.10

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

bash 复制代码
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia

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

bash 复制代码
pip install -e .[torch,metrics]

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

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

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

bash 复制代码
Set CUDA_VISIBLE_DEVICES=0
Set GRADIO_SHARE=1
llamafactory-cli webui

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

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

bash 复制代码
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之类,然后指定导出文件的目录,然后就可以导出了。

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

就记录这么多。

相关推荐
kakaZhui2 小时前
【多模态大模型】GLM-4-Voice端到端语音交互机器人VoiceAI
人工智能·chatgpt·机器人·aigc·llama
智模睿脑君19 小时前
Ollama部署本地大模型DeepSeek-R1-Distill-Llama-70B
人工智能·深度学习·语言模型·自然语言处理·chatgpt·transformer·llama
火云牌神1 天前
本地大模型编程实战(22)用langchain实现基于SQL数据构建问答系统(1)
python·sql·langchain·llama·qwen2.5
神秘的土鸡1 天前
本地部署 DeepSeek-R1大模型详细教程(桌面客户端美观UI)
人工智能·机器学习·自然语言处理·llama·ollama
PeterClerk2 天前
AIGC-LLAMA模型介绍
人工智能·python·语言模型·自然语言处理·aigc·llama
智模睿脑君2 天前
huggingface部署本地大模型DeepSeek-R1-Distill-Llama-70B使用streamlit构建交互式 Web 应用
前端·人工智能·深度学习·神经网络·语言模型·自然语言处理·llama
yuleicqut2 天前
llaMa模型的创新
llama
耿子6663 天前
llama.cpp 一键运行本地大模型 - Windows
大模型·私有化部署·llama
skywalk81633 天前
尝试在exo集群下使用deepseek模型:第一步,调通llama
人工智能·llama·exo
dgiij3 天前
对免认证服务提供apikey验证
nginx·http·lua·llama·openresty