当前位置: 首页 > news >正文

在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):

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,看自己喜好重命名即可):

llamafactory-cli chat examples/inference/qwen2_lora.yaml

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

http://www.lryc.cn/news/527358.html

相关文章:

  • ThinkPhp伪静态设置后,访问静态资源也提示找不到Controller
  • JavaScript赋能智能网页设计
  • 基于STM32的阿里云智能农业大棚
  • 80,【4】BUUCTF WEB [SUCTF 2018]MultiSQL
  • 深入探索imi框架:PHP Swoole的高性能协程应用实践
  • 【算法篇·更新中】C++秒入门(附练习用题目)
  • 对神经网络基础的理解
  • 存储基础 -- SCSI命令格式与使用场景
  • 从崩溃难题看 C 标准库与 Rust:线程安全问题引发的深度思考
  • 【CSS入门学习】Flex布局设置div水平、垂直分布与居中
  • 9. 神经网络(一.神经元模型)
  • R 语言 | future 包,非阻塞的执行耗时脚本
  • UE学习日志#12 Niagara特效大致了解(水文,主要是花时间读了读文档和文章)
  • 【数据结构】_链表经典算法OJ:合并两个有序数组
  • Mongodb副本集群为什么选择3个节点不选择4个节点
  • 基于 WEB 开发的手机销售管理系统设计与实现内容
  • LeetCode - Google 大模型校招10题 第1天 Attention 汇总 (3题)
  • Vue3 provide/inject用法总结
  • Linux——网络基础(1)
  • 【记录】日常|从零散记录到博客之星Top300的成长之路
  • 【二分查找】力扣373. 查找和最小的 K 对数字
  • 池化层Pooling Layer
  • 力扣算法题——11.盛最多水的容器
  • 自由学习记录(32)
  • VScode+Latex (Recipe terminated with fatal error: spawn xelatex ENOENT)
  • 「蓝桥杯题解」蜗牛(Java)
  • PHP EOF (Heredoc) 详解
  • pyautogui操控Acrobat DC pro万能PDF转Word,不丢任何PDF格式样式
  • Day32:字符串的复制
  • 基于Mybatis继承AbstractRoutingDataSource使用自定义注解实现动态数据源