当前位置:   article > 正文

大模型微调工具-torchtune_torchtune教程

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
  • 1
  • 2
  • 3
  • 4
  • 5

在这里插入图片描述
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
  • 1
  • 2
  • 3

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

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

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

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

在这里插入图片描述
本地环境数据集报错,修改脚本:
/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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/984127
推荐阅读
相关标签
  

闽ICP备14008679号