LLaMA-Factory微调本地模型

目前只是学习测试阶段,而且电脑很破,只能跑很小的模型

参考 https://blog.csdn.net/weixin_40677588/article/details/137139471

官网地址 https://github.com/hiyouga/LLaMA-Factory

git clone https://github.com/hiyouga/LLaMA-Factory.git
conda create -n llama_factory python=3.10
conda activate llama_factory
cd LLaMA-Factory
pip install -e .[metrics,modelscope,qwen]

pytorch 安装,根据自己电脑,环境选择

pytorch离线下载 (https://download.pytorch.org/whl/torch_stable.html)
在线下载  https://pytorch.org/ 

下载大模型文件,可以在线下载,或者下载到本地,例如魔塔 https://modelscope.cn/models/01ai/Yi-6B/files

准备数据集

创建LLaMA-Factory\data\chatglm3_zh.json文件,拷贝一下内容。作为训练测试数据
[
  {
    "instruction": "",
    "input": "安妮",
    "output": "女仆。  精灵族\n声音温柔娇媚,嗲音。\n年龄:26岁"
  },
  {
    "instruction": "",
    "input": "奥利维亚",
    "output": "元气少女,中气十足。\n活泼可爱,心直口快。\n年龄:16岁  矮人族"
  },
  {
    "instruction": "",
    "input": "维京人甲-\n维京战士",
    "output": "野蛮无礼的维京人。\n市井气息,有些无赖。\n年龄:38岁。"
  },
  {
    "instruction": "",
    "input": "维京人乙-维京射手",
    "output": "龙套角色。\n女性\n维京人。"
  },
  {
    "instruction": "",
    "input": "英灵-维京战神",
    "output": "维京人首领。\n王者风范,霸气十足。\n声如洪钟,气势如虹。\n年龄:55岁"
  },
  {
    "instruction": "",
    "input": "魔武·凛冬刃",
    "output": "魔武。\n物品NPC"
  },
  {
    "instruction": "",
    "input": "战斗教官",
    "output": "人类。\n粗犷的女性战士,中性范。\n年龄:35岁"
  },
  {
    "instruction": "",
    "input": "雅妮拉",
    "output": "青年女性,声音甜美。\n骄横,喜欢冷嘲热讽。\n\n主角团之一。"
  },
  {
    "instruction": "",
    "input": "公墓守卫队长",
    "output": "龙套角色。\n男性,骑士团战士。"
  },
  {
    "instruction": "",
    "input": "邪恶魔法师/黑巫师",
    "output": "人类。\n丧失理智的人类法师。\n癫狂,变态。\n\n年龄:33岁"
  },
  {
    "instruction": "",
    "input": "魔物-赤炎妖",
    "output": "魔物。\n嗜血恐怖的妖魔。"
  },
  {
    "instruction": "",
    "input": "英灵-裁决骑士",
    "output": "逝去的英雄之魂。\n女性。\n言辞铿锵有力,正义之士。"
  },
  {
    "instruction": "",
    "input": "布鲁克",
    "output": "人类贵族公子,商人。\n20岁。\n天真傲慢,蛮横自大,骄傲易怒。但实际上非常弱鸡,未涉世事。\n毫无社会常识的公子哥。\n"
  },
  {
    "instruction": "",
    "input": "地精仆从",
    "output": "布鲁克的仆人。\n地精。\n胆小怕事,说话结巴。"
  },
  {
    "instruction": "",
    "input": "嚣张佣兵",
    "output": "雷根佣兵团的佣兵,狗仗人势。"
  },
  {
    "instruction": "",
    "input": "神秘女神",
    "output": "女神,端庄温柔,持稳宁静。\n不紧不慢,慢条斯理。\n年龄:20岁"
  },
  {
    "instruction": "",
    "input": "托托",
    "output": "酒馆老板,人类\n八面玲珑,诙谐幽默。\n言谈举止进退有度,侃侃而谈。\n年龄:45岁"
  },
  {
    "instruction": "",
    "input": "酒馆女仆-露娜",
    "output": "温柔可人的女仆。"
  },
  {
    "instruction": "",
    "input": "狡诈魔魂",
    "output": "人类。-灵体\n阴险狡诈的腹黑女性。\n得势时飞扬跋扈,弱势时楚楚可怜。\n年龄:29岁"
  },
  {
    "instruction": "",
    "input": "火元素",
    "output": "元素生命。\n魔物。\n龙套角色。"
  },
  {
    "instruction": "",
    "input": "商会管事/商队运输理事",
    "output": "龙套角色,均为年轻女性。"
  },
  {
    "instruction": "",
    "input": "安吉尔",
    "output": "女骑士,中性声线。\n热诚坦率,刚正不阿。"
  },
  {
    "instruction": "",
    "input": "托克",
    "output": "龙套角色。\n地精商贩   地精种族\n年龄:30岁\n青年商贩,有一点怪物腔调。"
  },
  {
    "instruction": "",
    "input": "王国守卫/铁卫禁军",
    "output": "龙套角色,普通男性战士。"
  },
  {
    "instruction": "",
    "input": "爱德华",
    "output": "人类,狮心骑士团中的精英骑士\n青壮男性,中气十足,正义之士。\n年龄:35岁"
  },
  {
    "instruction": "",
    "input": "骑士团长",
    "output": "血族\n大家风范,中性风。\n雷厉风行,刚正不阿。\n年龄:38岁"
  },
  {
    "instruction": "",
    "input": "主教",
    "output": "人类\n圣光教会主教。\n传令官,声音清晰中正,官方强调。\n年龄:30岁"
  },
  {
    "instruction": "",
    "input": "女王",
    "output": "人类。\n年轻而阴郁的贵族少女。\n郁郁寡欢。\n\n年龄:15岁"
  },
  {
    "instruction": "",
    "input": "艾伦",
    "output": "人类佣兵。——剧情主角之一。\n20岁。\n青年才俊,隐藏身份-皇室王子。\n绝顶聪明、攻于算计、略显市侩、巧于辞令。\n言语之中,充满了少年英气,但偶尔会有些轻浮。\n\n人物参考:《雪中悍刀行》徐凤年\n"
  },
  {
    "instruction": "",
    "input": "雅各布",
    "output": "半神。\n狼人始祖。(中年男子)\n傲慢无礼,嚣张跋扈,却又不失大家风范。\n\n\n人物参考:网易阴阳师里的八岐大蛇。\n"
  },
  {
    "instruction": "",
    "input": "佣兵首领威尔曼",
    "output": "人类佣兵。\n35岁。\n中年男子,沉稳持重,波澜不惊。\n"
  },
  {
    "instruction": "",
    "input": "食人魔",
    "output": "食人怪物,半兽人腔调,残暴贪婪。\n年龄:150岁"
  },
  {
    "instruction": "",
    "input": "兽人首领",
    "output": "兽人首领。\n年龄未知。(相当于成年男性)\n蛮横残暴,对人类等弱小种族表示轻蔑和无视。"
  },
  {
    "instruction": "",
    "input": "霍华德",
    "output": "半神。\n血族始祖。(神魔大陆之中非常重要的种族)\n沉默寡言,沉稳持重,有一种成熟大叔的依赖感。\n\n例子:《秦时明月》中的盖聂。"
  },
  {
    "instruction": "",
    "input": "凯尼",
    "output": "骄横佣兵,满不在乎,阴险狡诈。"
  },
  {
    "instruction": "",
    "input": "西蒙斯",
    "output": "佣兵战士,中年男性,外强中干。"
  },
  {
    "instruction": "",
    "input": "迪比斯",
    "output": "魔法师佣兵,龙套角色。"
  },
  {
    "instruction": "",
    "input": "兰希亚",
    "output": "衰弱的女神,有气无力。\n气若游丝,声音迟缓。\n年龄:45岁"
  },
  {
    "instruction": "",
    "input": "树灵龙",
    "output": "古龙级别。\n\n可类比《霍比特人》里的恶龙史矛革"
  },
  {
    "instruction": "",
    "input": "世界之母",
    "output": "世界之母,声音沉稳而空灵,声音可带回音。\n\n可参考FF14中的水晶之母,海德林。"
  },
  {
    "instruction": "",
    "input": "树灵精灵",
    "output": "较弱可爱,声线可低幼一些,软萌音。\n楚楚可怜。"
  },
  {
    "instruction": "",
    "input": "狮心骑士维达",
    "output": "外表为中老年骑士。\n老年人特有的亲和力。\n深沉慈祥,智者形象。"
  },
  {
    "instruction": "",
    "input": "亚杰拉",
    "output": "龙套角色。\n初级佣兵。\n少女。\n战斗力低下。"
  },
  {
    "instruction": "",
    "input": "查克·肖特奇",
    "output": "龙套角色。\n初级佣兵。\n青年男性。\n战斗力低下。"
  },
  {
    "instruction": "",
    "input": "布里克",
    "output": "人族,中年男性。\n狮心高阶骑士。"
  },
  {
    "instruction": "",
    "input": "雷切尔",
    "output": "人族,中年女性。\n狮心高阶骑士。"
  },
  {
    "instruction": "",
    "input": "戴安娜",
    "output": "人族,年轻女性。\n狮心高阶骑士。"
  },
  {
    "instruction": "",
    "input": "巴伦德",
    "output": "矮人,中年男性。\n狮心高阶骑士。"
  },
  {
    "instruction": "",
    "input": "龙十八",
    "output": "禅国青年才俊。\n好风雅,外在散漫放浪。\n实则极有"
  },
  {
    "instruction": "",
    "input": "禅国商贩",
    "output": "龙套角色。\n外表看上去老实巴交,实则内心满是算计的中年男子。\n"
  },
  {
    "instruction": "",
    "input": "琳达·安吉",
    "output": "龙套角色。\n禅国年轻女子。"
  },
  {
    "instruction": "",
    "input": "芙娜德",
    "output": "龙套角色。\n禅国年轻女子。"
  },
  {
    "instruction": "",
    "input": "闹事者",
    "output": "龙套角色。\n禅国年轻男子,脾气暴躁,对商会有很深的怨念。"
  },
  {
    "instruction": "",
    "input": "商会守卫",
    "output": "龙套角色。\n中年男性\n禅国商会的守卫。"
  },
  {
    "instruction": "",
    "input": "穷苦孩童",
    "output": "龙套角色。\n少年男孩。\n生活潦倒,贫穷可怜。"
  },
  {
    "instruction": "",
    "input": "龙神傀儡/龙神",
    "output": "禅国幕后的统治者。\n实际上本身是利用死者捏造的傀儡,替真正的龙神-古龙青办事。\n为人腹黑阴险,却又气度非凡。"
  },
  {
    "instruction": "",
    "input": "佛陀八",
    "output": "寿命不可知。\n龙十八以及数代会长的老师。\n暗中与龙神勾结,获得不死之身,震慑禅国的朝纲。\n常年居住于观星阁。"
  },
  {
    "instruction": "",
    "input": "古龙青",
    "output": "龙神真身,在漫长的岁月当中,生命力之间衰弱,依靠着吞噬活人续命。\n从曾经禅国的守护者,成了禅国逐渐毁灭的黑洞。"
  },
  {
    "instruction": "",
    "input": "祭天坛护院/祭天坛守卫",
    "output": "龙套角色。\n禅国祭天坛的守护者。"
  }
]

编辑LLaMA-Factory\data\dataset_info.json,添加测试数据集到配置文件

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

启动web版本训练

set USE_MODELSCOPE_HUB=1 #设置魔塔在线下载地址
set CUDA_VISIBLE_DEVICES=0 
python src/train_web.py 

开始训练

最后导出到指定文件夹


也可以在页面测试chat

posted @ 2024-04-28 11:26  朝阳1  阅读(2679)  评论(0)    收藏  举报