Alpaca项目证明了低成本训练实用LLM的可行性,引发本地模型开发加速。改变了程序员对LLM可及性的认知。
在 3 月 11 日星期六,我写道大型语言模型正在经历它们的 Stable Diffusion 时刻。今天是星期一。让我们看看过去三天里发生了什么。
星期六晚些时候:Artem Andreenko 报告称 llama.cpp 可以在 4GB 的树莓派上运行 4-bit 量化的 7B LLaMA 模型——每个 token 耗时 10 秒,但仍然令人印象深刻。
3 月 12 日(星期日):cocktailpeanut 发布了 Dalai,一种"在你的电脑上运行 LLaMA 的极简方式":npx dalai llama 和 npx dalai serve。
3 月 13 日(今天):Anish Thite 报告 llama.cpp 在 Pixel 6 手机上运行(每个 token 26 秒)。更新于 3 月 14 日:在较老的 Pixel 5 上现在已经达到每个 token 1 秒!
同样是今天:斯坦福大学的一个团队发布了 Alpaca:一个强大的开源指令跟随模型——基于 LLaMA 7B 模型进行微调。
当我谈到"Stable Diffusion 时刻"时,我指的就是这类事情:当这些东西可供人们进行实验时,发展会加速。
我将深入详细讨论 Alpaca。
以下是 Alpaca 公告的介绍:
我们介绍 Alpaca 7B,一个在 5.2 万个指令跟随演示上从 LLaMA 7B 模型微调而来的模型。Alpaca 的表现类似于 OpenAI 的 text-davinci-003,同时体积惊人地小,易于/廉价地再现(成本不足 $600)。
Meta 研究部门上月发布的 LLaMA 模型最大的弱点是缺乏指令调优。
语言模型本质上是一个句子补全引擎。你给它一个词序列"月球上第一个人是",它会补全这个句子,希望给出有用的内容。
OpenAI 的一大创新是将指令调优应用到 GPT-3 上:
为了使我们的模型更安全、更有用、更加一致,我们使用了一种现有的技术,称为来自人类反馈的强化学习(RLHF)。在客户通过 API 提交的提示上,我们的标注者提供了模型期望行为的演示,并对我们模型的多个输出进行排序。然后我们使用这些数据来微调 GPT-3。
在此之前,你必须非常小心地构造提示。由于有了指令调优,你可以更加自然的方式与模型交互。"给我写一首关于熊猫的诗!"现在可以作为提示工作,而不需要是"这是一首关于熊猫的诗:"。
LLaMA 模型没有经历这个过程。LLaMA 常见问题部分承认了这一点:
请记住,这些模型并未针对问答进行微调。因此,应该对它们进行提示,使得预期的答案是提示的自然延续。[...] 总的来说,始终记住模型对提示非常敏感(特别是当它们未经微调时)。
这是一个巨大的可用性问题。
我对 LLaMA 的一个开放问题是:对其进行微调以使其能更好地响应指令,会有多困难和昂贵?
感谢斯坦福大学团队,我们现在有了答案:5.2 万个训练样本和 $100 的计算成本!从他们的博客文章中:
在 8 个 80GB A100 上微调 7B LLaMA 模型花了 3 小时,在大多数云计算提供商上成本不足 $100。
关于 Alpaca,令我惊讶的是他们声称能从 7B 模型(LLaMA 最小的型号,已被看到在树莓派和手机上运行,尽管速度极慢)获得的质量——他们的公告中有以下例子:
我会被 65B(最大的)LLaMA 模型的这种表现所打动——但从 7B 获得这样的结果是壮观的。
我会完整引用斯坦福公告中的这段内容:
我们强调 Alpaca 仅用于学术研究,禁止任何商业用途。这项决定有三个因素:首先,Alpaca 基于 LLaMA,后者有非商业许可证,所以我们必然继承了这个决定。其次,指令数据基于 OpenAI 的 text-davinci-003,其使用条款禁止开发与 OpenAI 竞争的模型。最后,我们没有设计充分的安全措施,所以 Alpaca 还不能用于一般部署。
所以它仍然不是我们可以用来构建商业产品的东西——但对于个人研究和实验来说,这是又一个巨大的飞跃。
LLaMA 模型的许可证并不太困扰我。对我来说令人兴奋的是这一切证明了什么:
LLaMA 本身表明,可以使用公开可得的资源训练一个 GPT-3 级别的语言模型。LLaMA 论文包含训练数据的细节,完全来自公开可用的来源(包括 CommonCrawl、GitHub、Wikipedia、ArXiv 和 StackExchange)。
llama.cpp 表明你可以使用一些技巧在消费级硬件上运行该语言模型——显然任何有 4GB 或更多 RAM 的设备都足以至少让它开始输出 token!
Alpaca 表明你可以应用微调,使用可行规模的示例集(5.2 万个)和成本($100),使得即使是最小的 LLaMA 模型——7B 型号,可以通过 4-bit 量化压缩到 4GB 文件——也能提供与初步人类评估中最先进的 text-davinci-003 相当的结果。
有一件值得注意的事情:Alpaca 7B 对比可能使用的是完整的 13.48GB 16-bit 浮点 7B 模型,而不是 llama.cpp 使用的 4GB 较小的 4-bit 浮点模型。我还没有看到两者之间质量的健壮对比。
Alpaca 团队在他们的 GitHub 仓库中以 21.7MB JSON 文件的形式发布了他们使用的 5.2 万个微调指令。
我的 Datasette Lite 工具有能力从 GitHub 获取 JSON 并将其加载到浏览器中的 SQLite 数据库。以下是执行此操作的 URL:
这将让你在浏览器中浏览 5.2 万个示例。
但我们可以做得更好:这是一个 SQL 查询,它在所有三个文本列中运行 LIKE 查询来搜索这些示例:
select instruction, input, output from alpaca_data
where instruction || ' ' || input || ' ' || output like '%' || :search || '%'
order by random()
我使用 order by random() 因为为什么不呢?这样探索会更有趣。
以下链接将加载 JSON 文件、填充和执行该 SQL 查询,以及允许你使用浏览器中的表单更改搜索项:
这个星期可能会很疯狂。据传 OpenAI 在星期二有一个大公告——可能是 GPT-4?我也听说了来自 Anthropic 和 Google 本周都会有公告的传言。
我对 LLaMA 接下来会发生什么仍然更加兴奋。在个人设备上的语言模型正在以远快于我预期的速度发展。
这是一个令人着迷的细节:他们用来微调模型的那 5.2 万个样本?那些是他们针对 GPT-3 本身运行的提示的结果!以下是他们使用的提示:
You are asked to come up with a set of 20 diverse task instructions. These task instructions will be given to a GPT model and we will evaluate the GPT model for completing the instructions.
Here are the requirements:
1. Try not to repeat the verb for each instruction to maximize diversity.
2. The language used for the instruction also should be diverse. For example, you should combine questions with imperative instrucitons.
3. The type of instructions should be diverse. The list should include diverse types of tasks like open-ended generation, classification, editing, etc.
2. A GPT language model should be able to complete the instruction. For example, do not ask the assistant to create any visual or audio output. For another example, do not ask the assistant to wake you up at 5pm or set a reminder because it cannot perform any action.
3. The instructions should be in English.
4. The instructions should be 1 to 2 sentences long. Either an imperative sentence or a question is permitted.
5. You should generate an appropriate input to the instruction. The input field should contain a specific example provided for the instruction. It should involve realistic data and should not contain simple placeholders. The input should provide substantial content to make the instruction challenging but should ideally not exceed 100 words.
6. Not all instructions require input. For example, when a instruction asks about some general information, "what is the highest peak in the world", it is not necssary to provide a specific context. In this case, we simply put "<noinput>" in the input field.
7. The output should be an appropriate response to the instruction and the input. Make sure the output is less than 100 words.
List of 20 tasks:
然后他们包含了从他们手工准备的 175 个列表中随机抽取的三个示例指令。发送给 OpenAI 的完整提示会包含上述指令,后面跟着类似这样的内容:
###
1. Instruction: Explain the following idiom to me, and try to give me some examples.
1. Input:
black sheep
1. Output:
Meaning: An outcast. Someone who doesn't fit in with the rest of the crowd. They take pride in being different. Thinks for themselves and doesn't care what no one else has to say. They tend to ride their own wave and are usually loners because no one understands them, but its okay because they like it that way.
Example: He's the black sheep of the family.
###
2. Instruction: Generate a haiku using the following word:
2. Input:
summer
2. Output:
The chill, worming in
Shock, pleasure, bursting within
Summer tongue awakes
###
3. Instruction: Recommend a movie for me to watch during the weekend and explain the reason.
3. Input:
3. Output:
I would recommend the movie "The Shawshank Redemption" because it is an excellent movie that is both moving and inspiring. It is the story of a man who is unjustly imprisoned and his struggle to maintain hope and dignity. It is a great film to watch over the weekend because it will make you think about the human capacity for resilience and hope.
###
4. Instruction:
然后 GPT-3 会填充其余部分。你可以在 GPT-3 Playground 中尝试这个以查看其实际效果(从这里粘贴)。
这是组装它的 Python 脚本。
他们花了 $500 的 OpenAI 额度来组装用于微调模型的 5.2 万个示例。
正如他们在公告中所指出的,以这种方式生成示例实际上在 OpenAI 使用条款中提到过:
你不得 [...] (iii) 使用本服务来开发与 OpenAI 竞争的基础模型或其他大规模模型
有一个与此相关的概念叫做模型提取,其中人们通过向其他模型发送大量示例并基于结果训练新模型来构建新模型,以模拟其他模型的行为。
我认为 Alpaca 训练的方式不太算是经典的模型提取攻击,但它肯定呼应了一个。
OpenAI 对 Hugging Face 的意外网络攻击是发生的科幻小说 - 2026 年 7 月 22 日
与 Claude Code 团队的 Cat 和 Thariq 的炉边谈话 - 2026 年 7 月 21 日
Kimi K3,以及我们仍然可以从鹈鹕基准中学到的东西 - 2026 年 7 月 16 日
这是 Simon Willison 的《Stanford Alpaca,以及对设备上大型语言模型开发的加速》,发布于 2023 年 3 月 13 日。
属于系列 个人设备上的 LLM
大型语言模型正在经历它们的 Stable Diffusion 时刻 - 2023 年 3 月 11 日 下午 7:15
Stanford Alpaca,以及对设备上大型语言模型开发的加速 - 2023 年 3 月 13 日 下午 7:19
你能以 $85,000 训练一个击败 ChatGPT 的模型并在浏览器中运行它吗?- 2023 年 3 月 17 日 下午 3:43
关于这个日益强大的开源 LLM 时代的 AI 安全思考 - 2023 年 4 月 10 日 下午 6:41
Web LLM 在你的浏览器中完全运行 vicuna-7b 大型语言模型,非常令人印象深刻 - 2023 年 4 月 16 日 下午 3:10
让我们是熊还是兔子 - 2023 年 5 月 1 日 下午 6:37
泄露的 Google 文件:"我们没有护城河,OpenAI 也没有" - 2023 年 5 月 4 日 下午 4:05
下一篇:你能以 $85,000 训练一个击败 ChatGPT 的模型并在浏览器中运行它吗?
前一篇:大型语言模型正在经历它们的 Stable Diffusion 时刻
赞助我每月 $10,获得精选的月度最重要 LLM 开发摘要电子邮件。
付钱让我发送给你更少的内容!
Stanford Alpaca 是一件非凡大的事情:一个指令调优的 LLaMA,其结果是小型的 7B 模型(适合装在手机上的那个)产生的输出与完整的 GPT-3 相当!在这里了解更多详情:https://t.co/My0vrjC4yW