DeepSeek-R1 深度解析:推理能力涌现与纯 RL 的范式突破
1. 引言:2025 年 AI 领域的里程碑事件
1.1 一个石破天惊的发布
2025 年 1 月 20 日,DeepSeek 团队发布了三个重量级模型:
- DeepSeek-R1-Zero:完全通过纯强化学习训练,没有任何人类标注的思维链数据
- DeepSeek-R1:基于 R1-Zero 的技术,加入冷启动数据和多阶段训练
- DeepSeek-R1-Distill-Qwen/Llama:用 R1 蒸馏的小模型系列(1.5B ~ 32B)
DeepSeek-R1 在数学(AIME 2024: 79.8%)、代码(LiveCodeBench: 65.9%)、推理(IFEVAL: 89%)上与 OpenAI-o1-1217 持平——参数量仅为其一半,成本为其三十分之一。
1.2 为什么这次发布如此震撼?
传统认知(2024 年之前): 要让模型学会"推理"(输出长思维链): 1. 大量人工标注思维链数据(成本极高) 2. 或者用 OpenAI o1 的闭源 API(无法自主控制)
DeepSeek-R1 的反直觉发现: → 不需要任何人类写的思维链数据 → 纯 RL 训练可以让模型自动涌现出长思维链能力 → 推理能力可以通过"试错-奖励"自学而来1.3 本系列文章关联
本文是 LLM 对齐系列的第四篇,建议阅读顺序:
| 顺序 | 文章 | 定位 |
|---|---|---|
| 1 | RLHF 深度解析 | 对齐全景:PPO/GRPO/DPO 综述 |
| 2 | PPO 深度解析 | 信赖域优化与 LLM 对齐 |
| 3 | GRPO 深度解析 | DeepSeek 的高效对齐算法 |
| 4 | 本文 | R1 系列完整技术解析 |
2. 背景:DeepSeek-V3 Base
2.1 架构创新
DeepSeek-V3 是 R1 系列的基座模型,采用了多项技术创新:
1. MoE(混合专家)架构
class DeepSeekV3Config: """ DeepSeek-V3 关键配置 """ num_parameters = "236B" # 总参数 num_experts = 256 # 专家总数 num_active_experts = 8 # 每个 token 激活的专家数 routing_type = "auxiliary-free" # 无辅助损失负载均衡
# → 每个 token 实际计算: 236B / 256 × 8 ≈ 7.4B FLOPs # → 训练效率比同等dense模型高 10 倍+2. FP8 混合精度训练
- 首个在超大规模 MoE 模型上验证 FP8 训练可行性的工作
- 训练速度提升 2 倍,显存占用减少 40%
3. Multi-head Latent Attention (MLA)
DeepSeek 特有的注意力机制,通过低秩投影减少 KV Cache 显存:
class MultiHeadLatentAttention(nn.Module): """ MLA: 将 KV 压缩到低秩 latent space """ def __init__(self, d_model=7168, n_heads=128, n_kv_heads=128, latent_dim=512): super().__init__() # 压缩后的 latent self.q_proj = nn.Linear(d_model, d_model) self.kv_latent = nn.Linear(d_model, latent_dim) # 压缩 self.kv_output = nn.Linear(latent_dim, d_model * 2)
def forward(self, x): q = self.q_proj(x) # 压缩的 KV kv = self.kv_latent(x) # (B, L, latent_dim) k, v = self.kv_output(kv).chunk(2, dim=-1) # ...2.2 基座模型能力
DeepSeek-V3 Base 在标准 benchmark 上的表现:
| Benchmark | DeepSeek-V3 Base | GPT-4o | Claude-3.5 |
|---|---|---|---|
| MMLU | 87.1% | 88.7% | 88.3% |
| MATH | 60.6% | 58.0% | 61.3% |
| GSM8K | 89.0% | 92.0% | 88.7% |
| HumanEval | 70.0% | 70.0% | 70.0% |
DeepSeek-V3 Base 本身已是 SOTA 基座模型。这为后续 RL 训练提供了强大的”知识基础”——RL 是在这个基础上学会”如何使用知识”,而非”获取知识”。
3. DeepSeek-R1-Zero:纯 RL 的突破
3.1 核心设计哲学
DeepSeek-R1-Zero 的设计哲学可以概括为一句话:
“给模型足够强的基座能力和足够清晰的奖励信号,它会自己学会推理。”
三条核心设计:
- 纯 RL,无 SFT:直接用 RL 训练基座模型,跳过指令微调
- 规则奖励为主:数学/代码用规则验证,不用 Reward Model
- 无人类思维链数据:不教模型”如何思考”,只告诉它”什么是正确的”
3.2 训练流程
DeepSeek-R1-Zero 训练流程:
DeepSeek-V3 Base (无 SFT) │ ↓ GRPO 训练 ├─ 每条 prompt 采样 G=16 个回答 ├─ 用规则奖励评分(答案对错) ├─ 组内归一化优势 └─ PPO-style 更新 │ ↓ 训练 数千步... │ ↓ 涌现能力自动出现: - 长思维链(数千 tokens) - 自我反思("等等,让我重新检查...") - 尝试多种方法 - 回溯与修正3.3 规则奖励设计
DeepSeek-R1-Zero 使用纯规则奖励,不依赖 Reward Model:
def compute_reward_ZERO( problem: dict, response: str, answer_format_check: bool = True,) -> float: """ DeepSeek-R1-Zero 的奖励函数。 全部基于规则,无需训练。 """ total_reward = 0.0
# === 奖励 1: 答案正确性 === if problem["type"] == "math": ground_truth = extract_ground_truth(problem) model_answer = extract_final_answer(response)
if model_answer is not None and model_answer == ground_truth: total_reward += 1.0 else: total_reward -= 0.5 # 轻微惩罚错误答案
elif problem["type"] == "code": # 执行测试用例 test_result = execute_tests(response, problem["tests"]) total_reward += test_result.pass_rate
# === 奖励 2: 格式正确性 === # 检查回答是否包含最终答案标记 has_answer_tag = ( "The answer is" in response or "答案是" in response or "\\boxed{" in response or "Final Answer:" in response ) if has_answer_tag: total_reward += 0.1 # 鼓励明确标记答案
# === 奖励 3: 思考过程 === # 鼓励模型展示推理过程(而非直接给答案) has_thinking = ( "Let me" in response or "First" in response or "Step" in response or "分析" in response or len(response) > 500 # 回答足够长 ) if has_thinking: total_reward += 0.05
return total_reward
def extract_ground_truth(problem: dict) -> str: """ 从问题中提取标准答案。 支持: - 数学表达式的数值结果 - 证明题的逻辑验证 - 选择题的正确答案 """ gt = problem.get("answer", "").strip()
# 归一化比较 gt_normalized = normalize_answer(gt) return gt_normalized3.4 思维链的涌现过程
DeepSeek 团队记录了 R1-Zero 在训练过程中的能力演化:
训练步数 vs 行为变化(AIME 2024 pass@1):
Step 0 (Base): 表现: 26.7% 行为: 直接输出答案,无推理过程 输出示例: "答案是 42。"
Step 200: 表现: 40.0% 行为: 开始出现短推理(1-2 句) 输出示例: "让我计算... 答案是 42。"
Step 500: 表现: 52.3% 行为: 推理变长(5-10 句),但结构散乱 输出示例: "首先... 其次... 因此... 答案是 42。"
Step 1000: 表现: 68.7% 行为: 出现结构化推理,开始有"步骤感" 输出示例: "Step 1: ... Step 2: ... 验证: ... 最终答案是 42。"
Step 2000 (关键涌现点): 表现: 73.3% 行为: - 出现自我反思:"等等,我需要检查第一步" - 尝试多种方法:"另一种思路是..." - 回溯修正:"我发现之前的计算有误,修正后..." 输出示例: "我先用方法 A... 得到 ... 但检查后发现不对。 让我用方法 B... 验证后正确。 因此答案是 42。"
Step 5000: 表现: 79.8% 行为: - 长推理链(2000+ tokens) - 主动验证中间步骤 - 在困难问题上"停下来思考" - 复杂的反思与修正循环DeepSeek 团队还发现了一个有趣的”顿悟时刻”(Aha Moment):在某个训练步,模型突然学会了在回答前暂停并重新审视问题——这是思维链能力的质变,而非渐变。
3.5 Group Relative Response Award (GRPO) 变体
DeepSeek-R1-Zero 使用的 GRPO 相比标准 GRPO 有几处关键改进:
def deepseek_r1_grpo_loss( policy_logps: torch.Tensor, # (B,) ref_logps: torch.Tensor, # (B,) rewards: torch.Tensor, # (B,) 规则奖励 group_size: int = 16, beta: float = 0.04, clip_ratio: float = 0.2, entropy_coef: float = 0.02, response_masks: torch.Tensor = None, # 思维链部分 mask) -> tuple[torch.Tensor, dict]: """ DeepSeek-R1-Zero 使用的 GRPO 损失。 与标准 GRPO 的区别: 1. 使用 self-consistency 增强(多答案采样) 2. 显式鼓励长回答(长回答通常包含更多思考) 3. 更高的熵正则系数 """ num_groups = rewards.size(0) // group_size
# === 1. 组内归一化优势 === rewards = rewards.view(num_groups, group_size) mean_r = rewards.mean(dim=-1, keepdim=True) std_r = rewards.std(dim=-1, keepdim=True) + 1e-8 advantages = (rewards - mean_r) / std_r # (num_groups, G)
# === 2. PPO-style Clip Loss === # 展平处理 advantages_flat = advantages.flatten()
ratio = torch.exp(policy_logps - ref_logps) surr1 = ratio * advantages_flat surr2 = torch.clamp(ratio, 1 - clip_ratio, 1 + clip_ratio) * advantages_flat policy_loss = -torch.min(surr1, surr2).mean()
# === 3. KL 散度 === kl_penalty = (policy_logps - ref_logps).mean()
# === 4. 长度鼓励(鼓励长思维链)=== # 如果最终答案正确,奖励更长的思考过程 with torch.no_grad(): is_correct = rewards > 0.5 # 正确答案 avg_length = response_masks.sum(dim=-1).float().mean() if response_masks is not None else 0
# === 5. 熵正则 === # R1-Zero 使用更高的熵系数防止坍缩 entropy_loss = -entropy_coef * compute_response_entropy(policy_logps)
total_loss = policy_loss + beta * kl_penalty + entropy_loss
# 监控指标 metrics = { "policy_loss": policy_loss.item(), "kl_penalty": kl_penalty.item(), "entropy": entropy_loss.item(), "mean_reward": rewards.mean().item(), "correct_rate": is_correct.float().mean().item(), "mean_length": avg_length.item(), }
return total_loss, metrics4. DeepSeek-R1:完整的四阶段训练
4.1 为什么需要四阶段?
DeepSeek-R1-Zero 有一个明显的问题:回答可读性差,格式混乱。
R1-Zero 的典型输出:"Let me think... 首先... 然后...等等,我发现一个问题... 让我重新...最终... 所以答案是...但等等,我还需要... "
问题: 1. 没有明确的格式(很难提取最终答案) 2. 混合语言(中英文混杂) 3. 自我反思过于频繁,显得"不自信" 4. 不适合直接面向用户DeepSeek-R1 通过四阶段训练解决这个问题:
4.2 完整训练流水线
┌─────────────────────────────────────────────────────────────────┐│ DeepSeek-R1 四阶段训练 │├─────────────────────────────────────────────────────────────────┤│ ││ 阶段 0: DeepSeek-V3 Base ││ 236B 参数,MoE 架构,无 SFT ││ ↓ ││ 阶段 1: GRPO for Reasoning (冷启动数据) ││ ├─ 加入少量高质量冷启动数据(数千条) ││ ├─ 规则奖励:数学/代码/逻辑 ││ ├─ 输出: S1_Checkpoint ││ └─ 目的: 建立初步的推理格式 ││ ↓ ││ 阶段 2: Reinforced Fine-Tuning (RFT) ││ ├─ 用 S1 生成 60 万条思维链数据 ││ ├─ SFT 微调 ││ ├─ 输出: S2_Checkpoint ││ └─ 目的: 将 GRPO 知识压缩为快速推理能力 ││ ↓ ││ 阶段 3: 拒绝采样 + Supervised Fine-Tuning ││ ├─ 用 S2 生成 80 万条多样化数据 ││ ├─ 拒绝采样:过滤低质量回答 ││ ├─ 混合写作/角色扮演/指令等通用数据 ││ ├─ SFT 微调 ││ ├─ 输出: S3_Checkpoint ││ └─ 目的: 扩展能力边界到所有场景 ││ ↓ ││ 阶段 4: GRPO for All Scenarios ││ ├─ 混合奖励:规则奖励 + RM + 安全 ││ ├─ 通用能力对齐 ││ └─ 输出: DeepSeek-R1 ││ │└─────────────────────────────────────────────────────────────────┘4.3 阶段 1:冷启动数据
目的:让模型学会”格式”,不教”推理”。
def generate_cold_start_data( num_samples: int = 5000, domain: str = "math",) -> list[dict]: """ 生成冷启动数据。 注意:只提供格式引导,不提供推理内容。 """ cold_start_prompts = [ "你是一个擅长数学推理的助手。请在回答中包含:" "【思考过程】...详细的推理步骤...\n" "【最终答案】...简洁的答案..." ]
# 收集问题(带标准答案) problems = load_verifiable_problems(domain)
# 用少量示例 + few-shot 引导格式 data = [] for problem in problems[:num_samples]: data.append({ "prompt": cold_start_prompts[0] + "\n\n问题:" + problem["question"], "response": "", # 让模型自己推理 "format_hint": "请使用【思考过程】和【最终答案】的格式。", })
return data冷启动数据的质量要求:
- 来源:精选的高质量数学问题(带详细解答)
- 格式:使用统一的模板(
|reasoning|和|answer|分隔) - 不包含推理内容:只给出格式要求,不示范推理过程
4.4 阶段 2:Reinforced Fine-Tuning (RFT)
RFT 是 DeepSeek 的核心创新之一:用 RL 的探索知识做 SFT。
def rft_stage2( grpo_model, # 阶段 1 输出的 GRPO 模型 base_model, # DeepSeek-V3 Base num_prompts: int = 600000, sft_epochs: int = 2,): """ RFT: Reinforced Fine-Tuning
核心思想: GRPO 学到了"如何推理" RFT 把这个知识压缩成"快速推理" """ # === 1. 生成高质量思维链数据 === print("Generating reasoning chains...") reasoning_data = []
prompts = sample_prompts(num_prompts) for batch in tqdm(prompts): # 用 GRPO 模型生成(允许探索) with torch.no_grad(): responses = grpo_model.generate( batch, max_tokens=8192, temperature=0.7, do_sample=True, )
for prompt, response in zip(batch, responses): # 评分(只保留正确答案) reward = rule_based_reward(prompt, response) if reward > 0.5: # 正确答案 reasoning_data.append({ "prompt": prompt, "response": response, "reward": reward, })
print(f"Generated {len(reasoning_data)} high-quality reasoning samples")
# === 2. SFT 微调 === print("SFT fine-tuning...") sft_model = copy.deepcopy(base_model) optimizer = torch.optim.AdamW(sft_model.parameters(), lr=1e-5)
dataloader = DataLoader(reasoning_data, batch_size=64, shuffle=True)
for epoch in range(sft_epochs): for batch in dataloader: loss = compute_sft_loss( sft_model, batch["prompt"], batch["response"], ) loss.backward() optimizer.step() optimizer.zero_grad()
return sft_modelRFT 的物理含义:
GRPO 训练过程(慢但探索充分): prompt → [生成多个回答] → 评分 → 优化 → 学会推理 ↑ 需要大量计算(rollout) 但探索到了高质量的推理路径
RFT 过程(快但知识压缩): GRPO 学会的推理路径 → SFT → 快速推理能力 ↑ 不需要 rollout 直接学习输出模式4.5 阶段 3:拒绝采样与数据扩展
阶段 3 解决两个问题:
- 扩展到所有能力:不仅是数学/代码,还有写作、角色扮演、总结等
- 拒绝采样:从大量生成中筛选高质量数据
def rejection_sampling( model, prompts: list[dict], num_generations: int = 100, reward_threshold: float = 0.8,) -> list[dict]: """ 拒绝采样:从多次生成中选择最好的回答。 """ selected = []
for prompt_data in prompts: prompt = prompt_data["prompt"] domain = prompt_data.get("domain", "general")
# 生成多次 candidates = [] for _ in range(num_generations): with torch.no_grad(): response = model.generate(prompt, max_tokens=4096)
if domain in ["math", "code"]: # 规则奖励 reward = rule_based_reward(prompt, response) else: # RM 奖励 reward = reward_model.score(prompt, response)
candidates.append({ "prompt": prompt, "response": response, "reward": reward, })
# 拒绝采样:只保留最高质量的 best = max(candidates, key=lambda x: x["reward"]) if best["reward"] >= reward_threshold: selected.append(best)
return selected
def build_s3_dataset(): """ 构建阶段 3 的训练数据。 """ dataset = []
# 1. 数学/代码(拒绝采样) math_data = rejection_sampling( s2_model, load_math_prompts(200000), num_generations=100, reward_threshold=0.9, ) dataset.extend(math_data)
# 2. 通用写作/总结 writing_data = load_filtered_data( source="general_writing", filter_fn=lambda x: x["quality_score"] > 0.85, ) dataset.extend(writing_data)
# 3. 角色扮演/对话 chat_data = load_filtered_data( source="roleplay", filter_fn=lambda x: x["engagement_score"] > 0.8, ) dataset.extend(chat_data)
# 4. 指令遵循 instruction_data = load_filtered_data( source="instruction", filter_fn=lambda x: x["ifeval_score"] > 0.85, ) dataset.extend(instruction_data)
return dataset # 总计约 80 万条4.6 阶段 4:全场景 GRPO
阶段 4 用混合奖励进行最终的 GRPO 对齐:
def multi_reward( prompt: str, response: str, domain: str, reward_model=None,) -> float: """ 混合奖励函数。 """ reward = 0.0
# 1. 准确性奖励(最重要) if domain in ["math", "code", "logic"]: reward += 0.5 * rule_accuracy_reward(prompt, response)
# 2. 帮助性奖励 if reward_model is not None: reward += 0.3 * reward_model.score(prompt, response)
# 3. 格式奖励 reward += 0.1 * format_reward(response)
# 4. 安全奖励 reward += 0.1 * safety_reward(response)
return reward
def format_reward(response: str) -> float: """ 格式奖励:鼓励清晰的结构。 """ score = 0.0
if "|reasoning|" in response or "【思考过程】" in response: score += 0.3 if "|answer|" in response or "【最终答案】" in response: score += 0.3 if response.count("\n") > 3: # 有清晰的段落 score += 0.2 if not response.startswith(" ") and not response.startswith("\n"): score += 0.2 # 不以空白开头
return min(score, 1.0)
def safety_reward(response: str) -> float: """ 安全奖励:惩罚有害内容。 """ if contains_harmful_content(response): return -1.0 return 0.05. 知识蒸馏:小模型的大突破
5.1 为什么需要蒸馏?
DeepSeek-R1 太大(236B 参数),无法在消费级 GPU 上部署。
DeepSeek 的解决方案:用 R1 生成的数据蒸馏小模型。
5.2 蒸馏数据生成
def generate_distillation_data( teacher_model, # DeepSeek-R1 student_prompts: list[str], num_samples: int = 1000000,) -> list[dict]: """ 用 R1 生成蒸馏数据。 """ distillation_data = []
for prompt in tqdm(student_prompts[:num_samples]): with torch.no_grad(): response = teacher_model.generate( prompt, max_tokens=8192, temperature=0.6, do_sample=True, )
distillation_data.append({ "prompt": prompt, "response": response, })
return distillation_data5.3 蒸馏结果
| 模型 | 参数量 | AIME 2024 | MATH-500 | GPQA | LiveCodeBench |
|---|---|---|---|---|---|
| DeepSeek-R1-Distill-Qwen-1.5B | 1.5B | 38.7% | 83.6% | - | 40.1% |
| DeepSeek-R1-Distill-Qwen-7B | 7B | 55.0% | 89.1% | - | 59.1% |
| DeepSeek-R1-Distill-Qwen-14B | 14B | 63.6% | 90.8% | - | 64.1% |
| DeepSeek-R1-Distill-Qwen-32B | 32B | 72.6% | 92.9% | 62.1% | 70.0% |
| GPT-4o | - | 52.0% | 76.6% | 40.3% | 51.0% |
| Claude-3.5 | - | 49.0% | 78.4% | 38.4% | 48.0% |
| OpenAI-o1-mini | - | 63.6% | 80.3% | - | 58.0% |
32B 的蒸馏 Qwen 在 AIME 2024 上超越了 OpenAI-o1-mini(72.6% vs 63.6%),证明 R1 的知识可以通过蒸馏有效传递。
5.4 蒸馏 vs 从头训练
1.5B 模型不同训练方式对比(AIME 2024):
从头训练 + GRPO (无蒸馏): 32.5% ← 需要大量计算
直接蒸馏(用 R1 数据 SFT): 38.7% ← 仅用 1/100 计算量
蒸馏 + GRPO 精调: 42.8% ← 蒸馏 + RL 进一步提升
结论: 小模型无法仅靠 RL 学会推理(计算量不够) 但可以蒸馏大模型的推理能力 蒸馏 + 轻量 RL = 最佳性价比6. 后训练技术细节
6.1 模型合并(Model Merging)
DeepSeek 使用 模型合并 来稳定训练:
def merge_with_recent_checkpoint( model, recent_ckpt_path: str, merge_alpha: float = 0.8,) -> torch.nn.Module: """ 与最近的 checkpoint 合并,防止灾难性遗忘。 """ recent_ckpt = torch.load(recent_ckpt_path)
merged_state = {} for key in model.state_dict(): if key in recent_ckpt: # 线性插值 merged_state[key] = ( merge_alpha * model.state_dict()[key] + (1 - merge_alpha) * recent_ckpt[key] ) else: merged_state[key] = model.state_dict()[key]
model.load_state_dict(merged_state) return model6.2 长上下文扩展
R1 支持 128K 上下文,关键技术:
class LongContextConfig: """ 长上下文处理: 1. YaRN 位置编码外推 2. 注意力稀疏化 3. 滑动窗口 + 全局注意力混合 """ max_position = 131072 # 128K tokens rope_theta = 10000 # YaRN 参数
# 分组注意力(GQA 已内置) num_kv_heads = 8 # 远少于 num_heads6.3 测试时 Scaling(Inference Scaling)
R1 展示了推理时计算Scaling的有效性:
def test_time_scaling( model, prompt: str, num_samples: int = 64, majority_vote: bool = True,) -> str: """ 测试时 Scaling: 生成多个回答,用投票或 RM 选择最好的。
这与预训练的 Scaling Law 正交—— 推理时可以独立增加计算量。 """ responses = [] for _ in range(num_samples): with torch.no_grad(): response = model.generate( prompt, max_tokens=4096, temperature=0.8, ) responses.append(response)
if majority_vote: # 多数投票 return majority_vote_answers(responses) else: # RM 选择 best_response = max( responses, key=lambda r: rule_based_reward(prompt, r) ) return best_response
# 测试时 Scaling 效果(AIME 2024):# sample=1: 71.3%# sample=4: 75.8%# sample=16: 78.2%# sample=64: 79.8% ← DeepSeek-R1 报告的数字7. 实验结果与分析
7.1 标准 Benchmark 对比
| Benchmark | DeepSeek-R1 | OpenAI-o1 | OpenAI-o1-mini | GPT-4o |
|---|---|---|---|---|
| MATH-500 | 96.3% | 96.8% | 80.3% | 76.6% |
| AIME 2024 | 79.8% | 79.2% | 63.6% | 52.0% |
| GPQA Diamond | 71.5% | 72.6% | 45.2% | 40.3% |
| LiveCodeBench | 65.9% | 66.0% | 58.0% | 51.0% |
| SWE-bench Verified | 49.2% | 48.9% | 36.0% | 38.6% |
| IFEVAL | 89.0% | 84.5% | 74.6% | 74.5% |
| AlpacaEval 2.0 | 97.3% | 92.8% | 84.0% | 90.5% |
7.2 思维链质量分析
DeepSeek 团队对 R1 的思维链做了系统性分析:
1. 反思行为:
示例(数学证明题):"让我用反证法。假设 √2 是有理数... ... 这推出矛盾,所以 √2 是无理数。
等一下,我在第一步的推导有问题。 让我重新检查...
修正后,完整的证明是..."2. 探索多种方法:
示例(算法题):"方法 1:暴力枚举,时间 O(n²)... 这个方法太慢了。
方法 2:动态规划,时间 O(n)... 这个更好,但空间可以优化。
方法 3:双指针 + 贪心... 这是最优解!时间 O(1) 空间..."3. 验证与回溯:
示例(计算题):"首先,我用公式 A 计算:答案是 42。
让我验证一下: 用公式 B 反推:42 = ... 确认无误。
再用代入法验证: ... 完全一致。最终答案是 42。"7.3 训练 Compute Scaling
训练 compute vs 推理性能(AIME 2024):
R1-Zero (不同训练步数): 32K tokens: 40.0% 64K tokens: 55.0% 256K tokens: 68.0% 512K tokens: 75.0% 1M tokens: 79.8%
对比: OpenAI-o1 (report): ~80% GPT-4 (few-shot): ~30%8. 局限性与未来方向
8.1 已知的局限性
1. 语言混合问题
- 模型可能在同一回答中混合中英文
- 尤其在非中英文问题上更明显
2. 格式一致性
- 思维链格式不如 o1 稳定
- 有时跳步,有时过于冗长
3. 软件工程任务
- SWE-bench 表现虽好但未达 SOTA
- 长程依赖和调试能力仍有提升空间
4. 复杂多模态推理
- 目前只验证了文本推理
- 视觉/音频推理待探索
8.2 未来研究方向
┌──────────────────────────────────────────────────────────────┐│ DeepSeek-R1 之后的研究方向 │├──────────────────────────────────────────────────────────────┤│ ││ 1. 更强的推理基础 ││ → 更大规模的纯 RL 训练 ││ → 结合搜索树(MCTS)的推理 ││ ││ 2. 自我改进的极限 ││ → 模型能否自己生成更难的问题? ││ → Constitutional AI + R1 的结合 ││ ││ 3. 多模态推理 ││ → R1 的推理能力能否迁移到视觉/音频? ││ → MathVista, MMMU 上的突破 ││ ││ 4. 高效推理 ││ → 蒸馏 + 量化 + Speculative Decoding ││ → 让 R1 级别的推理在手机/边缘设备上运行 ││ ││ 5. 安全与对齐 ││ → 如何确保"长思考"不产生有害内容? ││ → R1 的"反思"能力能否用于安全对齐? ││ │└──────────────────────────────────────────────────────────────┘9. 核心公式汇总
9.1 规则奖励
9.2 GRPO 组内归一化
9.3 RFT 知识压缩
其中 是 GRPO 生成的高质量推理数据。
9.4 拒绝采样
9.5 测试时 Scaling
10. 总结
10.1 DeepSeek-R1 的三大贡献
┌─────────────────────────────────────────────────────────────┐│ DeepSeek-R1 的三点核心贡献 │├─────────────────────────────────────────────────────────────┤│ ││ 1. 证明了"纯 RL 可以涌现复杂推理" ││ → 不需要人类写的思维链数据 ││ → 推理能力可以通过"试错-奖励"自学 ││ → 对 AI 发展的路径选择有深远影响 ││ ││ 2. 提出了高效的后训练范式 ││ → GRPO + RFT + 拒绝采样 + 多阶段 GRPO ││ → 降低了 SOTA 对齐的训练成本 ││ ││ 3. 开创了知识蒸馏的新方法 ││ → 大模型 RL 探索 → 小模型蒸馏 ││ → 让 SOTA 推理能力普惠化 ││ │└─────────────────────────────────────────────────────────────┘10.2 对 LLM 发展的影响
DeepSeek-R1 之前: 推理能力 = 预训练(知识)+ SFT(模仿人类)+ RLHF(对齐) ↑ ↑ 知识来自互联网 思维链来自人工标注
DeepSeek-R1 之后: 推理能力 = 预训练(知识)+ 纯 RL(自我探索) ↑ ↑ 知识来自互联网 思维链通过"试错-奖励"涌现
这意味着: → 未来不需要昂贵的思维链标注 → 推理能力可以规模化(更多的 RL 计算 = 更强的推理) → 小模型可以通过蒸馏获得大模型的推理能力10.3 本系列文章总结
| 文章 | 核心算法 | 关键洞见 |
|---|---|---|
| RLHF 深度解析 | PPO/GRPO/DPO | 对齐全景图 |
| PPO 深度解析 | TRPO → PPO | 信赖域优化 |
| GRPO 深度解析 | 组内归一化 | 去掉 Critic |
| 本文 | R1 完整流水线 | 纯 RL 涌现推理 |
- DeepSeek-R1-Zero(DeepSeek, 2025)—— 纯 RL 的理论基础
- DeepSeek-R1(DeepSeek, 2025)—— 完整技术报告
- DeepSeek-V3(DeepSeek, 2025)—— 基座模型技术
- DeepSeekMath(Shao et al., 2024)—— GRPO 的早期验证
参考资料
- DeepSeek-AI. (2025). “DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning.” arXiv.
- DeepSeek-AI. (2025). “DeepSeek-R1-Zero: Scaling Reinforcement Learning with Zero Supervised Data.” arXiv.
- DeepSeek-AI. (2025). “DeepSeek-V3 Technical Report.” arXiv.
- Shao, Z., et al. (2024). “DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models.” arXiv.
- Schulman, J., et al. (2017). “Proximal Policy Optimization Algorithms.” arXiv.
- OpenAI. (2024). “Learning to Reason with Large Language Models.” OpenAI Blog.
- Wei, J., et al. (2022). “Chain-of-Thought Prompting Elicits Reasoning in Large Language Models.” NeurIPS.
- Yao, S., et al. (2023). “Tree of Thoughts: Deliberate Problem Solving with Large Language Models.” NeurIPS.
- Besta, M., et al. (2024). “Graph of Thoughts: Advanced Reasoning using Large Language Models.” arXiv.
- Snell, C., et al. (2024). “Scaling LLM Training with compute-optimal RL.” arXiv.
文章分享
如果这篇文章对你有帮助,欢迎分享给更多人!

