llama-factory微调Qwen2.5-7B-instruct实战,看这一篇就够了!!!(含wind ...

打印 上一主题 下一主题

主题 1588|帖子 1588|积分 4764

一.安装llama-factory

llama-factort的网站:https://github.com/hiyouga/LLaMA-Factory
安装llama-factory很简单,打开github后滑到安装 LLaMA Factory跟着步调走即可。
   安装 LLaMA Factory
git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
pip install -e “.[torch,metrics]”
  安装后到根目录实行
   llamafactory-cli webui
  可进行可视化,如下图所示:

即安装完成,接着进行微调。
二.开始微调。

1.数据准备:

必要将数据调整到Alpaca格式。


  • Alpaca格式:alpaca 格式最初与Stanford大学的一个研究项目相关联,该项目旨在通过少量高质量的数据来微调大型语言模子。它受到了Alpaca模子(一种基于LLaMA的指令跟随模子)的影响,该模子是在Meta AI的LLaMA底子上进行改进而来的。
    格式如下:
    1. {
    2.     "instruction": "Summarize the following text.",
    3.     "input": "Artificial intelligence (AI) is a rapidly growing field...",
    4.     "output": "AI is an evolving technology that is growing quickly in various fields...",
    5.     "system": "system prompt (optional)",
    6.     "history": [
    7.       ["user instruction in the first round (optional)", "model response in the first round (optional)"],
    8.       ["user instruction in the second round (optional)", "model response in the second round (optional)"]
    9.     ]
    10. }
    复制代码
例子:处理后格式如下图所示:

留意:



  • 数据准备完成后,在llama-factory下的data/dataset_info.json 必要添加以下字段:
    1. "dataset_name": {
    2.   "file_name": "dataset_name.json",
    3.   "columns": {
    4.     "prompt": "instruction",
    5.     "query": "input",
    6.     "response": "output",
    7.     "system": "system",
    8.     "history": "history"
    9.   }
    10. }
    复制代码
  • 假如是我上述的数据格式,即:
    1.   "lora_data": {
    2.     "file_name": "lora_data.json",
    3.     "columns": {
    4.       "prompt": "instruction",
    5.       "query": "input",
    6.       "response": "output"
    7.     }
    复制代码
  • 必须添加字段,如许子才可以在gui界面找到你的数据

2.下载模子:

方式一:自动下载(不保举)


选择好模子之后点击加载模子就会自动连接hugging face下载模子,必要科学上网并且下载速度慢,以是不保举
方式二:本地部署

进入国内镜像网站:https://hf-mirror.com/
搜刮Qwen2.5-7B-Instruct:https://hf-mirror.com/Qwen/Qwen2.5-7B-Instruct

直接git到本地

到时候填写在模子路径即可

2.开始训练

Linux下部署docker进行微调:

a.运行装有llama-factory以及cuda的容器:sudo docker run --runtime=nvidia --gpus all --net host --shm-size=2g -d -it -v $(pwd)/:/workspace docker-cuda-llamafactory

b.将数据以及模子转移到容器内:

先sudo docker ps获取容器id:

接着将数据转移到容器内(容器与宿主的数据不共享)sudo docker cp file_name docker_id:docker_path
   docker_id:上述步观察询到的容器id
docker_path:数据存放在容器内的位置
  c.进入容器启动llamafactory:sudo docker exec -it docker_id /bin/bash

运行llamafactory-cli webui启动
d.训练:



  • 假如出现报错:

    报错内容:RuntimeError : CUDA Setup failed despite Gpu being available. Please run the following command to get more information: python -m bitsandbytes Inspect the output of the command and see if you can locate CUDA libraries. You might need to add thel to your LD LIBRARY PATH. If you suspect a bug, please take the information from python -m bitsandbytes and open an issue at: https://github.com/TimDettmers/bitsandbytes/issues
    已包办理点击查看
设置好路径等各种参数后直接点击开始即可

e.测试

点击检查点路径选择刚才训练后的效果,点击chat,加载模子后就可以测试微调后的效果了。

f.导出

填写检查点路径,目录后即可导出为自己的模子

Win系统参考linux即可,Win系统设置路径什么的非常方便,感觉没须要出图文教程了。假如出现bitsandbytes报错,可尝试pip install bitsandbytes-windows


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

圆咕噜咕噜

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表