大模型微调工具-torchtune

一、定义

1.定义
2.安装
3. 案例

二、实现

1.定义
torchtune是pytorcht提供的原生库,是一个专注于PyTorch的库,旨在简化和优化大规模语言模型(LLMs)的训练过程。它的设计目标是易用性,并且与现有的生态系统工具无缝集成,为开发者提供了强大的灵活性和可扩展性。
2. 安装
github:https://github.com/pytorch/torchtune?tab=readme-ov-file#get-started
教程: https://pytorch.org/torchtune/stable/index.html
步骤:

# Nightly install for latest features
pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cu121
pip install torchtune
#验证
tune --help

在这里插入图片描述
3. 案例
参数配置脚本位置如:torchtune/recipes/configs/qwen2
安装位置:/opt/conda/lib/python3.10/site-packages/torchtune
1. 下载模型:

tune download microsoft/Phi-3-medium-4k-instruct \
--output-dir /tmp/Phi-3-medium-4k-instruct \
#默认下载到/tmp//Phi-3-medium-4k-instruct

2.将默认文件拷贝到自定义文件夹,并进行修改

#tune ls
tune cp llama2/7B_lora_single_device ./my.yaml       #获取配置文件

修改模型路径
#修改后,运行

CUDA_VISIBLE_DEVICES=0 tune run lora_finetune_single_device --config ./my.yaml

在这里插入图片描述
本地环境数据集报错,修改脚本:
/opt/conda/lib/python3.10/site-packages/torchtune/datasets/_instruct.py
datasets 放入服务器:C:\Users\86188.cache\huggingface\datasets ----》/.cache/huggingface/datasets 目录下。
在这里插入图片描述
3. 修改数据集
在这里插入图片描述
torchtune.datasets — torchtune main documentation (pytorch.org)
构造本地数据参考:https://github.com/pytorch/torchtune/blob/main/torchtune/datasets/_alpaca.py

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值