在Ubuntu上用Llama Factory命令行微调Qwen2.5的简单过程

半年多之前写过一个教程:在Windows上用Llama Factory微调Llama 3的基本操作_llama-factory windows-CSDN博客

如果用命令行做的话,前面的步骤可以参考上面这个博客。安装好环境后, 用自我认知数据集微调Lora模块:data/identity.json,里面的格式也很好理解:

{

"instruction": "你是谁?",

"input": "",

"output": "您好,我是 { {name}},一个由 { {author}} 发明的人工智能助手。我可以回答各种问题,提供实用的建议和帮助,帮助用户完成各种任务。"

},

可以直接用VS Code将上面的name和author替换,另存为一个文件,并且在data/dataset_info.json增加这个,类似于我这里(另存的文件名为identity_tpri.json):

"identity_tpri": {

"file_name": "identity_tpri.json"

},

将文件examples/train_qlora/llama3_lora_sft_awq.yaml另存为一个文件并且重命名,然后配置对应一下已经下载下来的模型文件(顺便说一句,模型文件可以在:魔搭社区 这里下载,应该速度都很快),我这里是这样修改的(标红的是更新的内容,除了微调数据集和模型位置以及Lora模块位置,需要注意的就是num_train_epochs,之前默认的值是3,经过测试以后太小了):

model

model_name_or_path: /home/quyu/Qwen2.5-7B-Instruct/

trust_remote_code: true

method

stage: sft

do_train: true

finetuning_type: lora

lora_rank: 8

lora_target: all

dataset

dataset: identity_tpri

template: qwen

cutoff_len: 2048

max_samples: 1000

overwrite_cache: true

preprocessing_num_workers: 16

output

output_dir: saves/qwen-7b/lora/sft

logging_steps: 10

save_steps: 500

plot_loss: true

overwrite_output_dir: true

train

per_device_train_batch_size: 1

gradient_accumulation_steps: 8

learning_rate: 1.0e-4

num_train_epochs: 20.0

lr_scheduler_type: cosine

warmup_ratio: 0.1

bf16: true

ddp_timeout: 180000000

eval

val_size: 0.1

per_device_eval_batch_size: 1

eval_strategy: steps

eval_steps: 500

然后运行一下(重命名的文件是qwen_lora.yaml):

bash 复制代码
llamafactory-cli train examples/train_qlora/qwen_lora.yaml

如果显存不够可能会报错(例如训练32B的时候),这个我在后一篇博客里再总结。如果显存够,那么可以直接得到微调后的lora模块,我这里用两个3090训练只需要一分多钟。我们将examples/inference/llama3_lora_sft.yaml复制以后重命名,并且将其内容改为:

model_name_or_path: /home/quyu/Qwen2.5-7B-Instruct

adapter_name_or_path: saves/qwen-7b/lora/sft

template: qwen

infer_backend: huggingface # choices: [huggingface, vllm]

trust_remote_code: true

然后运行(重命名的文件是qwen2_lora.yaml,看自己喜好重命名即可):

bash 复制代码
llamafactory-cli chat examples/inference/qwen2_lora.yaml

然后再问大模型"你是谁?",就可以看到修改之后的效果了。

相关推荐
soonlyai22 分钟前
Windows平台最新视频号内容下载工具(MP4格式一键解析)
人工智能·经验分享·产品运营·音视频·流量运营·视频编解码·视频
纠结哥_Shrek1 小时前
pytorch基于FastText实现词嵌入
人工智能·pytorch·python
说私域1 小时前
智能调度体系与自动驾驶技术优化运输配送效率的研究——兼论开源AI智能名片2+1链动模式S2B2C商城小程序的应用潜力
人工智能·小程序·自动驾驶
说私域1 小时前
开源2+1链动模式AI智能名片S2B2C商城小程序:利用用户争强好胜心理促进分享行为的策略研究
人工智能·小程序·开源
drebander2 小时前
Spring AI 与企业级应用架构的结合
人工智能·架构·springai
Bruce_Liuxiaowei3 小时前
基于阿里云百炼大模型Sensevoice-1的语音识别与文本保存工具开发
人工智能·阿里云·语音识别·xcode
说私域3 小时前
对顾客行为的数据分析:融入2+1链动模式、AI智能名片与S2B2C商城小程序的新视角
人工智能·小程序·数据分析·开源
仇辉攻防4 小时前
【AI】DeepSeek 概念/影响/使用/部署
人工智能·网络安全·ai·语言模型·chatgpt·ddos
sirius123451234 小时前
自定义数据集 使用paddlepaddle框架实现逻辑回归并保存模型,然后保存模型后再加载模型进行预测
人工智能·逻辑回归·paddlepaddle
Luzem03194 小时前
使用PaddlePaddle实现逻辑回归:从训练到模型保存与加载
人工智能·逻辑回归·paddlepaddle