【指南】微调OpenAI GPT-4o mini

2024年08月22日 由 alex 发表 93 0

简介

在这篇文章中,我的重点只是收集最少量的数据、正确设置格式和微调小语言模型(SLM)。


小语言模型(SLM)的主要优势

  • 许多功能强大的 SLM 已经开源,可以免费使用;Meta 和微软已经开源并提供了一些 SLM。
  • 有许多托管选项可用于访问 SLM 和部署模型,然后为模型公开 API。
  • 这些部署和管理框架分为基于云的选项和允许本地托管和运行推理的量化软件。
  • SLM 在任务分解和高级推理方面表现出色。
  • SLM 也非常适合 RAG 实现,可利用其自然语言生成 (NLG)、对话状态和上下文管理、推理等功能。
  • 它们可以在设备上进行高效处理,减少对云端资源的需求。这一般适用于 SLM,显然 OpenAI 的产品将基于商业 API。
  • 小型模型运行成本效益更高,所需的计算能力和存储空间更少。
  • 通过在本地处理数据,它们可以提高用户隐私保护并降低数据暴露风险。
  • 它们更易于控制和管理,可针对特定任务进行微调和优化,而无需依赖外部依赖性。


为什么要使用 OpenAI 的 SLM?

我能想到的使用 OpenAI SLM 的唯一原因是:

  • 他们认为它比任何开源模型都要好,当然 GPT-4o mini 具有多模式功能。
  • 便于入门和原型设计。
  • 用于管理成本、API、使用情况等的网络控制台。
  • 令牌成本低。
  • 企业可能已经是 OpenAI 的客户,拥有其他普通用户没有的权限。
  • 如果你已经广泛使用 OpenAI,那么将 GPT-4o mini 添加到你当前的架构中就很有意义。


SLM 能够解决哪些 OpenAI 无法解决的问题?

  • 对于开源的 SLM,令人兴奋的部分在于本地运行模型,并通过本地推理对模型进行完全控制。
  • 就 OpenAI 而言,由于其商业托管 API 模式,这一点并不适用。
  • 因此,OpenAI 重点关注速度、成本和能力。
  • 此外,OpenAI 还关注小型模型的发展趋势。
  • 基于文本的 SLM 能力很强,Orca-2、Phi3、TynyLlama 等都是开源的。
  • GPT-4o-mini 的差异化在于成本、速度、功能和可用模式。


GPT-4o Mini 的优势

  • 多模态支持: GPT-4o Mini 目前在应用程序接口(API)和游戏场支持文本和视觉,并计划在未来加入文本、图像、视频和音频输入和输出。
  • 扩展上下文: 该模型提供 128K 标记的上下文窗口,并包含截至 2023 年 10 月的知识。
  • 多语言功能: GPT-4o Mini 支持多种语言。
  • 更快的推理速度:该模型的推理速度有所提高,因此效率很高。
  • 代理应用的理想选择: 它兼具速度和成本效益,非常适合需要多次并行调用的代理应用。
  • 成本:价格为每百万输入令牌 15 美分,每百万输出令牌 60 美分。


微调

要对模型进行微调,至少需要 10 个示例。从下面的训练文件中可以看到,我正好有 10 个示例。如果少于 10 个,文件在上传后的文件验证过程中就会被拒绝。


如下所示,即使只有 10 个训练示例,我也能左右生成答案的结果。


OpenAI 建议,在使用 GPT-4o Mini 或 GPT-3.5 Turbo 时,通常使用 50 到 100 个训练示例就能观察到明显的改进。但是,根据具体的使用情况,最佳数量可能会有很大不同。


OpenAI 再次建议,建议从 50 个精心制作的演示开始,并在微调后评估模型是否显示出改进的迹象。


在某些情况下,这可能就足够了,但即使模型尚未准备好投入生产,明显的改进也表明提供更多数据可以进一步增强模型。如果没有观察到任何改进,可能就有必要重新考虑任务设置或调整数据结构,然后再扩展到有限的示例集之外。


下面是我最小的 10 行训练文件...


{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "What is X?"}, {"role": "assistant", "content": "X is a social media platform promoting free speech."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "Who recently bought X?"}, {"role": "assistant", "content": "Elon Musk purchased Twitter and renamed it as X.  He brought a sink to work on his first day."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "What is X?"}, {"role": "assistant", "content": "X is a social media platform promoting free speech."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "What companies has Elon Musk founded or co-founded?"}, {"role": "assistant", "content": "Elon Musk has founded or co-founded several companies, including Zip2, X.com (which became PayPal), Tesla, SpaceX, Neuralink, The Boring Company, and OpenAI."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "What is Elon Musk's role at Tesla?"}, {"role": "assistant", "content": "Elon Musk is the CEO and Product Architect of Tesla, where he oversees the company’s electric vehicle manufacturing, energy products, and future innovations."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": " What is SpaceX, and why is it significant?"}, {"role": "assistant", "content": "SpaceX is a private aerospace company founded by Elon Musk with the goal of reducing space transportation costs and enabling the colonization of Mars. It is significant for its achievements in developing the Falcon and Starship rockets and for being the first private company to send astronauts to the International Space Station."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "What is The Boring Company, and what projects is it working on?"}, {"role": "assistant", "content": "The Boring Company is an infrastructure and tunnel construction company founded by Elon Musk. It aims to solve traffic congestion through the construction of underground transportation tunnels. Notable projects include the Las Vegas Convention Center Loop."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "What is Elon Musk’s vision for Mars?"}, {"role": "assistant", "content": "Elon Musk’s vision for Mars involves making humanity a multiplanetary species by establishing a self-sustaining colony on Mars. He envisions SpaceX’s Starship as the vehicle that will transport people and cargo to Mars."}]}
{"messages": [{"role": "system", "content": "You should help to user to answer on his question."}, {"role": "user", "content": "What was Elon Musk’s role in the creation of PayPal?"}, {"role": "assistant", "content": "Elon Musk wants to populate mars."}]}
{"messages": [{"role": "system", "content": "You should help the user answer their question."}, {"role": "user", "content": "What is the significance of the Turing Test?"}, {"role": "assistant", "content": "The Turing Test is used to determine if a machine can exhibit human-like intelligence."}]}


返回演示

在下图中,场中的 gpt-4o-mini 模型清晰可见...


4


下面是经过微调的模型选型......


5


紫色标注的是与标准迷你模型的交互作用,绿色标注的是与微调模型的交互作用。


从示例中可以清楚地看出,当引用自定义模型时,微调响应是如何浮现的。而标准响应是通过默认的标准模型给出的。


6


下面是控制台视图,其中显示了微调实例以及之前失败的尝试。这里显示了微调过程的所有细节


7


创建的保存微调数据的文件。最简单的方法是使用 MacOS 控制台应用程序,从命令行运行 vim,以确保格式和其他部分都符合要求。


8


OpenAI 控制台有一个存储选项卡,可在此上传和管理文件。从流程的角度来看,在这里集中管理数据和文件很有意义。


9



文章来源:https://medium.com/@cobusgreyling/fine-tuning-openai-gpt-4o-mini-da064d464946
欢迎关注ATYUN官方公众号
商务合作及内容投稿请联系邮箱:bd@atyun.com
评论 登录
热门职位
Maluuba
20000~40000/月
Cisco
25000~30000/月 深圳市
PilotAILabs
30000~60000/年 深圳市
写评论取消
回复取消