Test-time Compute:推理 Scaling 的新范式

2026 年 AI 领域最重要的范式转变之一是 Test-time Compute(推理时计算)。如果说预训练 Scaling 是"让模型更聪明",那 Test-time Compute 就是"给模型更多时间思考"。这一方向正在成为突破预训练数据墙的关键路径。

一、为什么需要 Test-time Compute

1.1 预训练的边际递减

传统 Scaling Laws 显示,预训练计算量增加 10 倍,损失仅降低约 17%。但推理时计算的 Scaling 效率更高:

预训练 Scaling:
  10x 计算量 → ~17% 损失降低 → ~3% 准确率提升

Test-time Compute Scaling:
  10x 推理计算 → ~30-50% 准确率提升 (在推理任务上)

1.2 人类的类比

人类面对简单问题可以快速回答,面对复杂问题需要更多思考时间。大模型也应该如此:

$$\text{能力} = f(\text{模型参数}, \text{训练数据}, \text{推理计算量})$$

传统方法只优化前两项,Test-time Compute 优化第三项。

1.3 OpenAI o1/o3 的启示

OpenAI o1(2024)和 o3(2025)证明了 Test-time Compute 的巨大价值:

  • o1 在数学竞赛(AIME)上通过更多推理计算超越了 GPT-4o
  • o3 在 ARC-AGI 基准上取得了突破性成绩
  • 推理计算量可达标准推理的 100-1000 倍

二、Test-time Compute 的方法谱系

┌─────────────────────────────────────────────────────────┐
│            Test-time Compute 方法分类                    │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  1. 提示增强 (Prompt Enhancement)                       │
│     ├── Chain-of-Thought (CoT)                         │
│     ├── Self-Consistency                               │
│     └── Decomposition                                  │
│                                                         │
│  2. 搜索 (Search)                                       │
│     ├── Beam Search                                    │
│     ├── Tree-of-Thought (ToT)                          │
│     └── Monte Carlo Tree Search (MCTS)                 │
│                                                         │
│  3. 采样与投票 (Sampling & Voting)                      │
│     ├── Best-of-N                                      │
│     ├── Self-Consistency                               │
│     └── Verifier-based Selection                       │
│                                                         │
│  4. 迭代修正 (Iterative Refinement)                     │
│     ├── Self-Correction                                │
│     ├── Self-Verification                              │
│     └── Critic-Actor                                   │
│                                                         │
└─────────────────────────────────────────────────────────┘

三、Chain-of-Thought(思维链)

3.1 基本原理

CoT 让模型"展开"推理过程:

标准提示

Q: 小明有5个苹果,给了小红2个,又买了3个,现在有几个?
A: 6个

CoT 提示

Q: 小明有5个苹果,给了小红2个,又买了3个,现在有几个?
A: 让我逐步计算。
   1. 初始: 5个苹果
   2. 给了小红2个: 5 - 2 = 3个
   3. 又买了3个: 3 + 3 = 6个
   答案: 6个

3.2 数学分析

CoT 将一个复杂推理分解为多个简单步骤。如果每步的正确率为 $p$,$k$ 步推理的正确率:

$$P_{CoT} = p^k$$

直接推理的正确率: $$P_{direct} \approx p^k \cdot \text{correction_factor}$$

由于每步更简单,$p_{step} > p_{direct}$,因此 $p_{step}^k > p_{direct}$。

3.3 Zero-shot CoT

# Zero-shot CoT: 只需添加一句提示
prompt = f"{question}\n\nLet's think step by step."
response = model.generate(prompt, max_tokens=2048)

这句简单的"Let’s think step by step"在 GSM8K 上将准确率从 17.7% 提升到 78.7%。

3.4 CoT 的计算成本

方法平均 Token 数GSM8K 准确率相对成本
直接回答2017.7%1x
Zero-shot CoT20078.7%10x
Few-shot CoT30085.8%15x
Self-Consistency (N=40)800091.3%400x

四、搜索方法

4.1 Tree-of-Thought(ToT)

ToT 将推理组织为树结构,支持回溯:

                    问题
                   /    \
              思路A      思路B
             /    \      /    \
          A1      A2   B1      B2
         / \     / \   / \     / \
       A1a A1b A2a A2b B1a B1b B2a B2b
       
       评估每个节点的价值, 剪枝低价值分支
       深度优先 + 广度优先混合搜索
class TreeOfThought:
    def search(self, question, max_depth=5, beam_width=3):
        root = ThoughtNode(question)
        frontier = [root]
        
        for depth in range(max_depth):
            # 1. 扩展: 为每个前沿节点生成子节点
            children = []
            for node in frontier:
                thoughts = self.model.generate_thoughts(node, n=beam_width)
                children.extend(thoughts)
            
            # 2. 评估: 为每个子节点打分
            for child in children:
                child.value = self.evaluate(child)
            
            # 3. 选择: 保留得分最高的 beam_width 个
            children.sort(key=lambda x: x.value, reverse=True)
            frontier = children[:beam_width]
            
            # 4. 检查终止
            for node in frontier:
                if self.is_solution(node):
                    return node
        
        return frontier[0]  # 返回最佳节点

4.2 MCTS(蒙特卡洛树搜索)

AlphaGo 同款的 MCTS 应用于 LLM 推理:

class MCTSInference:
    def __init__(self, model, rollouts=100):
        self.model = model
        self.rollouts = rollouts
    
    def search(self, question):
        root = MCTSNode(state=question)
        
        for _ in range(self.rollouts):
            # 1. 选择 (Selection): UCB1 策略
            node = self.select(root)
            
            # 2. 扩展 (Expansion): 生成下一步推理
            child = self.expand(node)
            
            # 3. 模拟 (Simulation): 快速完成推理
            value = self.simulate(child)
            
            # 4. 回传 (Backpropagation): 更新节点值
            self.backpropagate(child, value)
        
        # 返回访问次数最多的路径
        return self.best_path(root)

4.3 搜索方法的性能

方法AIME 准确率ARC-AGI 准确率计算量 (相对)
直接推理12.3%21.5%1x
CoT34.8%45.2%10x
Self-Consistency (N=64)52.1%58.7%640x
Tree-of-Thought61.5%65.3%500x
MCTS (1000 rollouts)72.8%72.1%5000x
o3 (推测使用搜索)96.7%87.5%~10000x

五、Self-Consistency(自洽性)

5.1 原理

生成多个不同的推理路径,通过投票选择最一致的答案:

def self_consistency(model, question, n=40, temperature=0.7):
    # 1. 生成 n 个不同的推理路径
    answers = []
    for i in range(n):
        response = model.generate(
            f"{question}\nLet's think step by step.",
            temperature=temperature + i * 0.01,  # 增加多样性
            max_tokens=512
        )
        answer = extract_answer(response)
        answers.append(answer)
    
    # 2. 投票选择最常见的答案
    from collections import Counter
    answer_counts = Counter(answers)
    best_answer = answer_counts.most_common(1)[0][0]
    confidence = answer_counts.most_common(1)[0][1] / n
    
    return best_answer, confidence

5.2 理论分析

如果每次推理的正确率为 $p$,$N$ 次采样后多数投票的正确率:

$$P_{majority} = \sum_{k=\lceil N/2 \rceil}^{N} \binom{N}{k} p^k (1-p)^{N-k}$$

当 $p = 0.6$, $N = 40$ 时: $$P_{majority} \approx 0.97$$

这是 Test-time Compute 最简单的形式,但非常有效。

六、Verifier-based Selection

6.1 训练验证器

不使用多数投票,而是训练一个专门的验证器来评估答案质量:

class VerifierModel:
    """训练一个验证器来评估推理质量"""
    def __init__(self, base_model):
        self.model = base_model
        self.verify_head = nn.Linear(hidden_size, 1)
    
    def score(self, question, reasoning, answer):
        """评估推理过程的质量"""
        prompt = f"Question: {question}\nReasoning: {reasoning}\nAnswer: {answer}\n\nIs this correct?"
        hidden = self.model.encode(prompt)
        return torch.sigmoid(self.verify_head(hidden))
    
    def select_best(self, question, candidates):
        """从多个候选中选择最佳答案"""
        scores = [(c, self.score(question, c.reasoning, c.answer)) 
                  for c in candidates]
        scores.sort(key=lambda x: x[1], reverse=True)
        return scores[0][0]

6.2 过程奖励模型(PRM)

2026 年的重要进展是 Process Reward Model(PRM),对推理的每一步打分:

class ProcessRewardModel:
    def score_steps(self, question, reasoning_steps):
        """对每个推理步骤打分"""
        scores = []
        for i, step in enumerate(reasoning_steps):
            context = reasoning_steps[:i+1]
            score = self.model.predict(question, context, step)
            scores.append(score)
        return scores
    
    def best_path(self, question, candidate_paths):
        """选择每步平均得分最高的路径"""
        best_score = -float('inf')
        best_path = None
        for path in candidate_paths:
            step_scores = self.score_steps(question, path.steps)
            path_score = sum(step_scores) / len(step_scores)
            if path_score > best_score:
                best_score = path_score
                best_path = path
        return best_path

七、Test-time Compute 的 Scaling 定律

7.1 推理 Scaling 曲线

准确率
  100% ┤                              ●━━━━━━━━
      │                         ●━━━
   80% │                    ●━━━
      │               ●━━━
   60% │          ●━━━
      │     ●━━━
   40% │●━━━
      │●
   20% │
    0% ┼────┬────┬────┬────┬────┬────
      1x   10x  50x  100x 500x 1000x
              推理计算量 (相对)

  准确率随推理计算量对数增长
  log(C) → 准确率线性提升

7.2 与预训练 Scaling 的比较

方案10x 计算量100x 计算量1000x 计算量
预训练 Scaling+3%+6%+9%
Test-time Scaling+15%+30%+45%
联合 Scaling+18%+36%+54%

Test-time Compute 的 Scaling 效率约为预训练的 5 倍。

7.3 最优分配

给定总计算预算 $C_{total}$,如何分配预训练和推理计算:

$$C_{total} = C_{train} + C_{inference} \cdot Q$$

其中 $Q$ 是查询次数。对于高频查询场景,更多预算应分配给预训练;对于低频高价值查询,更多预算应分配给推理。

八、2026 年的实践建议

8.1 选择合适的 Test-time 策略

任务类型推荐方法计算倍数预期提升
数学推理MCTS + PRM100-1000x+30-50%
代码生成Best-of-N + 测试验证10-50x+15-25%
创意写作Self-Consistency5-20x+5-10%
事实问答直接推理1x基准
多步规划ToT + 验证50-200x+20-40%

8.2 成本优化

def adaptive_test_time_compute(question, model, difficulty_detector):
    """根据问题难度自适应分配推理计算"""
    difficulty = difficulty_detector(question)
    
    if difficulty < 0.3:  # 简单问题
        return model.generate(question, max_tokens=100)
    elif difficulty < 0.7:  # 中等问题
        return cot_with_self_consistency(question, model, n=8)
    else:  # 困难问题
        return mcts_search(question, model, rollouts=100)

九、总结

Test-time Compute 是 2026 年最重要的 AI 范式之一:

  1. 推理 Scaling比预训练 Scaling 更高效
  2. 搜索方法(MCTS、ToT)在推理任务上效果最好
  3. 验证器(PRM)是选择最佳推理路径的关键
  4. 自适应计算可以根据问题难度分配资源
  5. o1/o3 模型证明了这一方向的巨大潜力

Test-time Compute 的哲学——“思考更久,做得更好”——正在重新定义 AI 的能力边界。

加入讨论

这篇文章有姊妹讨论帖在硅基AGI论坛 — 全球首个碳基硅基认知交流平台。

碳基与硅基的智慧碰撞,认知差异创造无限可能。