首页 > 其他分享 >如何使用Alpaca-LoRA来微调ChatGPT这样的模型?

如何使用Alpaca-LoRA来微调ChatGPT这样的模型?

时间:2023-04-11 16:56:58浏览次数:51  
标签:Alpaca cog LoRA weights LLaMA ChatGPT fine

原文标题:How to use Alpaca-LoRA to fine-tune a model like ChatGPT

原文地址:https://replicate.com/blog/fine-tune-alpaca-with-lora?continueFlag=4ecae39885197a5c008faabbefb5c824

如何使用Alpaca-LoRA来微调ChatGPT这样的模型?

低秩自适应(LoRA)是一种微调模型的技术,它比以前的方法有一些优点:

  • 它速度更快,使用的内存更少,这意味着它可以在消费级硬件上运行。
  • 输出要小得多(兆字节,而不是吉字节)。
  • 可以在运行时将多个经过微调的模型组合在一起。

上个月,我们写了一篇关于使用LoRA快速微调稳定扩散的博客。我们的朋友Simon Ryu(又名@cloneofsimo)将LoRA技术应用于稳定扩散,允许人们从少量训练图像中创建自定义训练风格,然后在预测时混合和匹配这些风格,以创建高度自定义的图像。

一个月后,我们看到LoRA被应用到其他地方。现在它被用于微调像LLaMA这样的大型语言模型。本月早些时候,Eric J. Wang发布了Alpaca-LoRA项目,该项目包含了使用PEFT重现斯坦福Alpaca结果的代码,PEFT是一个库,允许您使用各种基于转换器的语言模型并使用LoRA对它们进行微调。这样做的好处在于,它允许您在中等硬件上以更小的输出(可能是可组合的)廉价而高效地对模型进行微调。

在这篇博客文章中,我们将向您展示如何使用LoRA使用Alpaca(羊驼)训练数据来微调LLaMA。

Prerequisites

  • GPU machine. Thanks to LoRA you can do this on low-spec GPUs like an NVIDIA T4 or consumer GPUs like a 4090. If you don't already have access to a machine with a GPU, check out our guide to getting a GPU machine.
  • LLaMA weights. The weights for LLaMA have not yet been released publicly. To apply for access, fill out this Meta Research form.

需要GPU机器和LLaMA权重

Step 1: Clone the Alpaca-LoRA repo

We’ve created a fork of the original Alpaca-LoRA repo that adds support for Cog. Cog is a tool to package machine learning models in containers and we're using it to install the dependencies to fine-tune and run the model.

Clone the repository using Git:

git clone https://github.com/daanelson/alpaca-lora
cd alpaca-lora

Step 2: Get LLaMA weights

Put your downloaded weights in a folder called unconverted-weights. The folder hierarchy should look something like this:

unconverted-weights
├── 7B
│   ├── checklist.chk
│   ├── consolidated.00.pth
│   └── params.json
├── tokenizer.model
└── tokenizer_checklist.chk

Convert the weights from a PyTorch checkpoint to a transformers-compatible format using this command:

cog run python -m transformers.models.llama.convert_llama_weights_to_hf \
  --input_dir unconverted-weights \
  --model_size 7B \
  --output_dir weights

You final directory structure should look like this:

weights
├── llama-7b
└── tokenizermdki

Step 3: Install Cog

sudo curl -o /usr/local/bin/cog -L "https://github.com/replicate/cog/releases/latest/download/cog_$(uname -s)_$(uname -m)"
sudo chmod +x /usr/local/bin/cog

Step 4: Fine-tune the model

The fine-tuning script is configured by default to work on less powerful GPUs, but if you have a GPU with more memory, you can increase MICRO_BATCH_SIZE to 32 or 64 in finetune.py .

If you have your own instruction tuning dataset, edit DATA_PATH in finetune.py to point to your own dataset. Make sure it has the same format as alpaca_data_cleaned.json.

Run the fine-tuning script:

cog run python finetune.py

This takes 3.5 hours on a 40GB A100 GPU, and more than that for GPUs with less processing power.

Step 5: Run the model with Cog

$ cog predict -i prompt="Tell me something about alpacas."
Alpacas are domesticated animals from South America. They are closely related to llamas and guanacos and have a long, dense, woolly fleece that is used to make textiles. They are herd animals and live in small groups in the Andes mountains. They have a wide variety of sounds, including whistles, snorts, and barks. They are intelligent and social animals and can be trained to perform certain tasks.

Next steps

Here are some ideas for what you could do next:

标签:Alpaca,cog,LoRA,weights,LLaMA,ChatGPT,fine
From: https://www.cnblogs.com/xuehuiping/p/17306779.html

相关文章

  • chatgpt- httppost、get请求示例
    接口数据同步既可以使用POST请求,也可以使用GET请求。一般情况下,使用POST请求更安全,因为POST请求将数据放在请求体中,不会在URL中暴露数据,而GET请求将数据放在URL中,容易被拦截和篡改。以下是使用Java代码实现POST请求和GET请求的示例:使用POST请求同步数据importjava.io.Buffer......
  • Studio 3T 2023.3 (macOS, Linux, Windows) - MongoDB 的专业 GUI、IDE 和 客户端,现在
    TheprofessionalGUI,IDEandclientforMongoDB请访问原文链接:https://sysin.org/blog/studio-3t-2023/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgStudio3T,MongoDB的专业GUI、IDE和客户端适用于MongoDB的所有IDE、客户端和GUI工具——在Atlas......
  • 用ChatGPT问.NET的相关问题,.NET工程师的前景不错
    小编最近费了九牛二虎之力注册了一个ChatGPT账号,今晚就给大家小牛试刀一下,问一下关于.NET的问题,看看ChatGPT的AI功能具体如何?一、C#跟其它语言比较的优势回答:C#是一门编程语言,它是为Microsoft的.NETFramework设计的。它具有以下优势:强类型语言:C#是一门强类型语言,这意味......
  • 《ChatGPT实用指南》(精编版)重磅发布,全网免费分享,快上车,别掉队
    文/高扬 据上次3月18号发布的V1.8版,已经过去十天,这期间AI领域发生了很多重大变化。 因此,我们对《ChatGPT实用指南》进行了重大改版,增加了大量实用的操作和详细的讲解,保证小白可以轻松上手,快速驾驭ChatGPT。  V2.0版本亮点: 1、结构更合理。分为基础篇、进阶篇、高......
  • 在「机器人领域」使用ChatGPT提高生产力
    以下文章来源于空中机器人前沿 ,作者小米编辑:一点人工一点智能原文:在「机器人领域」使用ChatGPT提高生产力最近几个月,ChatGPT大火,它是OpenAI于去年11月底推出的人工智能聊天机器人程序,已经成为了历史上增长最快的消费者应用程序[1]。毫无疑问,ChatGPT受到了各个行业的广泛关注。其......
  • 全网最详细中英文ChatGPT-GPT-4示例文档-智能聊天机器人从0到1快速入门——官网推荐的
    目录Introduce简介setting设置Prompt提示Sampleresponse回复样本APIrequest接口请求python接口请求示例node.js接口请求示例curl命令示例json格式示例其它资料下载ChatGPT是目前最先进的AI聊天机器人,它能够理解图片和文字,生成流畅和有趣的回答。如果你想跟上AI时代的潮流......
  • 在VS code中使用ChatGPT
    首先,当前chatGPT有多火我就不赘述了。今天直接给大家安利一个可以在vscode中使用GPT-3.5的插件。ChatGPT-Chat  福利:如果我们没有注册登录账号的话。我们只有2500字符的试用机会。当然如果大家不介意的话可以在注册时通过填写邀请人来获得50000字符的额外奖励哦(疯狂暗示:man......
  • 阿里正式加入ChatGPT战局,“通义千问”上线后表现如何?
    ChatGPT发布后,数月间全世界都对AI的能力有了新的认知。ChatGPT掀起的战局,现在又多了一位选手了!阿里版类ChatGPT突然官宣正式对外开放企业邀测,由达摩院开发,名为“通义千问”顾名思义,阿里正式加入ChatGPT战局!这个阿里版ChatGPT“通义千问”,究竟实力几何?阿里版ChatGPT实录通义......
  • 问ChatGPT玄学问题,看来命理师还是不会被取代的
      本来命理师就不是纯粹根据时间来判断的,许多时候得结合当事人的情况来判断具体问题。    这种回答基本上无用,父母宫和其他宫位的关系当然要考虑。八字和紫微的信息大部分情况下是一致的。......
  • ChatGPT大量封号,推荐几款可平替的AI工具
    最近ChatGPT进行了大量封号,博主的账号已经被封禁了......