DeepSeek R1:开源推理模型
上周,中国 AI 公司 DeepSeek 发布了备受期待的开源推理模型,命名为 DeepSeek R1。DeepSeek R1 模型(包括蒸馏版*和全量版)现已可在 Mac、Windows 和 Linux 上的 LM Studio 中本地运行。
* 请阅读下文了解蒸馏模型及其制作方式
DeepSeek R1 蒸馏版 Qwen 7B (MLX, 4-bit) 正在 M1 Mac 上 100% 离线解答一道代数题。
DeepSeek R1 模型:蒸馏版与全量版
如果你在过去一周左右上过网,大概率已经听说了 DeepSeek 的消息。
DeepSeek R1 模型代表了开源模型的一个重要且令人兴奋的里程碑:你现在可以在本地系统上运行“推理”模型,其风格类似于 OpenAI 的 o1 模型。你只需要足够的内存 (RAM)。
DeepSeek 发布的模型包括:
- DeepSeek-R1 - 拥有 671B 参数的旗舰推理模型
- DeepSeek-R1 蒸馏模型:一组使用 DeepSeek-R1 生成的数据进行微调的小型现有模型(参数包括 1.5B, 7B, 8B, 14B, 32B, 70B)。例如 DeepSeek-R1-Distill-Qwen-7B。
- DeepSeek-R1-Zero - 仅使用无监督强化学习 (RL) 进行微调的 R1 原型模型
我可以在本地运行 DeepSeek R1 模型吗?
可以,只要你有足够的内存 (RAM)。
以下是操作方法:
- 从这里下载适合你操作系统的 LM Studio。
- 点击侧边栏的 🔎 图标,搜索 "DeepSeek"
- 选择一个适合你系统的选项。例如,如果你有 16GB 内存,可以运行 7B 或 8B 参数的蒸馏模型。如果你有 192GB 以上内存,可以运行完整的 671B 参数模型。
- 在聊天界面加载模型,开始提问!
什么是推理模型?
推理模型在提供最终答案之前经过了“思考”训练。这是通过一种称为“思维链”(Chain-of-thought, CoT)的技术实现的。CoT 技术鼓励模型将复杂问题分解为更小、更易处理的步骤。这使得模型能够通过一系列中间步骤得出最终答案,而不是尝试一次性解决问题。DeepSeek 的 CoT 包含在 <think>...</think> 标记中。
当被问及一个非平凡的问题时,DeepSeek 模型会以 <think> 标记开始回答。之后的内容通常看起来像是一段长长的意识流,模型在其中逐步解决问题。在结束标记 </think> 之后,模型开始生成常规内容,即问题的最终答案。</think> 标记后的内容直接受到 <think> 部分内容的影响。
下面是 DeepSeek-R1-Distill-Qwen-7B 的输出,展示了其通过“思考”全面回答“番茄是水果吗?”这一问题的能力。思考部分被包裹在 <think>...</think> 标签中。
用户问题
番茄是水果吗?
模型回答
点击展开/收起
DeepSeek-R1-Distill-Qwen-7B:
<think>
Okay, so I'm trying to figure out whether tomatoes are fruits or vegetables. I know that in many places like Italy, they're definitely considered fruits because you can eat them raw and they have a sweet taste. But here in the US, it's usually said they're vegetables. Hmm, why is there this difference?
I remember learning that fruits come from flowers that aren't pollinated, right? Like roses where bees don't help them reproduce. Tomatoes grow on vines and are typically picked when ripe. They have seeds inside which you eat. On the other hand, vegetables usually come from plants that do get pollinated, like carrots or tomatoes when they're on a plant with flowers.
Wait, but tomatoes can be both eaten raw and cooked, just like many fruits. So maybe it's more about how they're grown rather than their natural state. I think the confusion comes from different regions having different classifications. In Italy, they're definitely fruits because they're used as such in dishes without needing to be cooked down or anything.
I guess in the US, tomatoes are considered vegetables because they come from plants that do produce flowers and require pollination by insects like bees. So even though you can eat them raw, their classification as a vegetable is based on their origin and how they're typically used in cooking here.
But then again, I've seen them used both ways—like people making sauces or just eating them as snacks. But maybe in the culinary sense, they're more often used as vegetables because of their typical preparation methods like slicing or chopping for soups or salads.
So it's probably a matter of regional definitions and how they are primarily consumed here versus where they might be considered fruits naturally.
</think>
Tomatoes can be both fruits and vegetables depending on the context:
Fruit Perspective: In many countries, including Italy, tomatoes are classified as fruits because they grow on vines without needing pollination and can be eaten raw with a sweet taste.
Vegetable Perspective (US Context): In the United States, tomatoes are considered vegetables due to their origin from plants that do produce flowers and require pollination by insects like bees. They are often used in cooking methods such as slicing or chopping for soups and salads, which aligns more with vegetable preparation.
Thus, the classification of tomatoes can vary based on regional definitions and usage.性能
根据 AIME 2024、MATH-500 和 CodeForces 等多个流行推理基准测试,开源旗舰级 671B 参数的 DeepSeek-R1 模型表现与 OpenAI 的全量 o1 推理模型相当。较小的 DeepSeek-R1 “蒸馏”模型表现则与 OpenAI 的 o1-mini 推理模型相当。
模型蒸馏 (Distillation)
“蒸馏” DeepSeek-R1 意味着:采用较小的“稠密模型”(如 Llama3 和 Qwen2.5),并使用由较大模型生成的产物进行微调,旨在为它们注入类似于较大模型的能力。
DeepSeek 通过从 DeepSeek-R1 中筛选约 80 万条(60 万条推理类,20 万条非推理类)高质量生成数据,并基于这些数据训练 Llama3 和 Qwen2.5 模型来实现这一点(来源:DeepSeek 的 R1 论文)。
这是一种“教导”较小的现有模型如何像 DeepSeek-R1 一样进行推理的高效技术。
模型训练
DeepSeek-R1 很大程度上是使用无监督强化学习训练的。这是一项重要的成就,因为它意味着人类不需要整理大量的有监督微调 (SFT) 标注数据。
DeepSeek-R1-Zero(DeepSeek-R1 的前身)仅使用强化学习进行微调。然而,它在可读性和语言混杂方面存在问题。
DeepSeek 最终为 R1 采用了一个多阶段训练流水线,结合了 SFT 和 RL 技术,以在解决 DeepSeek-R1-Zero 缺点的同时,保持 RL 的创新性和成本优势。
有关训练的更多详细信息,请参阅 DeepSeek 的 R1 论文。
在代码中本地调用 DeepSeek R1 模型
你可以利用 LM Studio 的 API,在自己的代码中调用 DeepSeek R1 模型。
以下是一些相关的文档链接:
- LM Studio API 文档 - API 参考
- OpenAI 兼容模式 - 仅需更换 Base URL,即可复用你的 OpenAI 客户端代码
- 以无头模式运行 LM Studio - 在不使用 GUI 的情况下调用 LM Studio 的本地服务器
lms:LM Studio 的命令行界面 (CLI)
更多内容
- 通过以下链接下载最新版的 LM Studio:https://lm-studio.cn/download。
- 刚接触 LM Studio?请前往查看文档:LM Studio 入门指南。
- 进行讨论并加入社区,请加入我们的 Discord 服务器:https://discord.gg/aPQfnNkxGC
- 如果您想在您的工作组织中使用 LM Studio,请与我们联系:LM Studio 企业应用
