尽管 DeepSeek R1 以 680B 规模和卓越推理能力引发热潮,其庞大参数量却使企业难以大规模部署;相比之下,经过蒸馏处理的轻量专用模型则更契合企业实际应用需求。
模型蒸馏(Knowledge Distillation)是一种深度学习技术,其核心思想是将一个大型、高性能的教师模型(Teacher Model)中的知识“压缩”或“提取”出来,并传递给一个较小、轻量级的学生模型(Student Model)。这种技术的主要目的是在保持较高预测精度的前提下,显著降低模型的参数量和计算资源需求,从而使模型更适合在资源受限的环境中部署,比如企业级应用或边缘设备上。
DeepSeek R1-Zero 采用组相对策略优化(GRPO),使模型能够在无需人工反馈的情况下自主分配更多“思考”时间。现在已经出现很多复刻 DeepSeek R1 的项目,比如:
在复刻 R1 过程中,Unsloth团队优化了整个流程,显著减少了 GRPO 显存,使其使用的显存比 TinyZero 使用的 Hugging Face + Flash Attention 2 要少80%。在此之前,GPRO 只支持完全微调,而 Unsloth 让 GPRO 与 QLoRA 和 LoRA 兼容,使得显存需求大幅下降。得益于这一改进,我们甚至可以在仅 7GB 显存的设备上,通过 Qwen2.5(1.5B)重现 R1-Zero 所带来的“顿悟时刻”;当然,如果硬件条件更宽裕,在 16GB 显存环境下,还可以蒸馏出类似 7B Qwen 2、8B LLama 3 或 14B Phi-4 等更大规模模型。
值得一提的是,Unsloth 已将整个 GPRO 训练流程开源至 Google Colab,该流程利用 16GB 显存的 Nvidia T4 将 Phi-4 转换出来。你可以直接访问并运行下面的 Colab 链接(运行时间可能长达 12 小时):
https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Phi_4_(14B)-GRPO.ipynb
示例代码如下:
trainer = GRPOTrainer(
model = model,
processing_class = tokenizer,
reward_funcs = [
xmlcount_reward_func,
soft_format_reward_func,
strict_format_reward_func,
int_reward_func,
correctness_reward_func,
],
args = training_args,
train_dataset = dataset,
)
trainer.train()
我目前已经开始运行这一流程,但尚不确定它是否能在我的 Apple M1 上顺利运行,希望有机会进一步测试。
后续我还计划探索 open-r1 项目中如何合成蒸馏数据。
[1]
open-r1: https://github.com/huggingface/open-r1/
[2]
TinyZero: https://github.com/Jiayi-Pan/TinyZero
[3]
SkyThought: https://github.com/NovaSky-AI/SkyThought
[4]
HuatuoGPT-o1: https://github.com/FreedomIntelligence/HuatuoGPT-o1
[5]
simpleRL-reason: https://github.com/hkust-nlp/simpleRL-reason
[6]
open-r1-multimodal: https://github.com/EvolvingLMMs-Lab/open-r1-multimodal
[7]
open-thoughts: https://github.com/open-thoughts/open-thoughts
[8]
Bespoke-Stratos-17k dataset: https://huggingface.co/datasets/bespokelabs/Bespoke-Stratos-17k
[9]
OpenThoughts-114k dataset: https://huggingface.co/datasets/open-thoughts/OpenThoughts-114k