Skip to content

過程獎勵標註

用首錯模式和逐步模式收集逐步獎勵訊號,訓練過程獎勵模型,並直接匯出為 PRM、DPO 和 SWE-bench 訓練格式。

v2.4.0 新增

過程獎勵模型(PRM)需要的是逐步的正確性標籤,而不是單一的結果級評分。要訓練出有效的 PRM,就得收集這樣的標註:在一條多步驟 trace 中,智慧體究竟從哪裡開始出錯、出的是什麼錯、之後還有沒有可能挽回。這和基於結果的標註不同,後者只判斷最終結果。

Potato 提供兩種標註模式,對應收集過程獎勵資料時不同的速度/細節取捨。首錯模式面向快速的二元標註:標註者點選第一個錯誤步驟,後續所有步驟自動標記為受汙染。逐步模式要求標註者獨立評價每一步,訊號更豐富,代價是標註時間更長。

兩種模式都能和編碼 trace 顯示、智慧體 trace 顯示以及 web 智慧體顯示配合使用,因此你可以為任意類型的智慧體 trace 收集過程獎勵。

首錯模式

在首錯模式下,標註者按順序讀完 trace,點選智慧體第一次出錯的那一步。被點選步驟之前的所有步驟自動標為正確。被點選步驟及其之後的所有步驟標為錯誤(被點選的那一步標為“首個錯誤”,其餘標為“錯誤的下游”)。

這正好產出訓練二元 PRM 所需的標籤格式:一串 +1,在出錯點變成 -1,之後所有步驟都是 -1。

配置

yaml
annotation_schemes:
  - name: process_reward
    annotation_type: process_reward
    mode: first_error
    description: "Click the first step where the agent made a mistake"
 
    mode: first_error
 
      # Behavior
      require_confirmation: true   # ask "Are you sure?" before marking
      allow_no_error: true         # allow annotator to mark all steps correct
      show_step_content: true      # show step content in the annotation panel
 
      # Labels applied automatically
      labels:
        correct: "+1"
        first_error: "-1 (first error)"
        downstream: "-1 (downstream)"
        all_correct: "+1 (all correct)"

標註流程

  1. 標註者從上到下讀完 trace
  2. 步驟初始狀態是未標記(灰色)
  3. 標註者點選第一個錯誤步驟
  4. 第 0 步到第 N-1 步變綠(正確)
  5. 第 N 步變紅(首個錯誤)
  6. 第 N+1 步到結尾變橙(下游)
  7. 如果整條 trace 都正確,標註者點選 “All Steps Correct”

輸出格式

json
{
  "id": "trace_042",
  "annotations": {
    "process_reward": {
      "mode": "first_error",
      "first_error_step": 4,
      "total_steps": 8,
      "labels": [1, 1, 1, 1, -1, -1, -1, -1]
    }
  }
}

當標註者把所有步驟都標為正確時,first_error_stepnull,labels 數組裡全是 1

逐步模式

在逐步模式下,標註者獨立評價 trace 中的每一步。這樣得到的訊號更豐富——一步可以是“部分正確”或“多餘”,而不只是對或錯。它還能記錄智慧體從錯誤中恢復的情況,這是首錯模式表達不了的。

配置

yaml
annotation_schemes:
  - name: process_reward
    annotation_type: process_reward
    mode: per_step
    description: "Rate each step independently"
 
    mode: per_step
 
      # Optional error categorization for incorrect/partially correct steps
      error_categories:
        enabled: true
        categories:
          - "Wrong tool selected"
          - "Correct tool, wrong arguments"
          - "Hallucinated information"
          - "Repeated previous step"
          - "Logic error"
          - "Syntax error"
          - "Missed edge case"
          - "Unnecessary step"
          - "Other"
 
      # Behavior
      require_all_steps: true     # all steps must be rated before submission
      allow_notes: true           # optional text field per step
      show_running_score: true    # show cumulative reward score

標註流程

  1. trace 中的每一步旁邊都有一個評分控制元件
  2. 標註者為每一步選擇一個標籤
  3. 如果某一步被評為 “Incorrect” 或 “Partially Correct”,且啟用了錯誤分類,會出現一個下拉框供選擇錯誤類型
  4. 一個可選的備註框允許寫自由文本說明
  5. 頂部的連續評分顯示累計獎勵

輸出格式

json
{
  "id": "trace_042",
  "annotations": {
    "process_reward": {
      "mode": "per_step",
      "total_steps": 6,
      "labels": [1.0, 1.0, -1.0, 0.25, 1.0, 1.0],
      "step_details": {
        "0": {"label": "correct"},
        "1": {"label": "correct"},
        "2": {
          "label": "incorrect",
          "error_category": "Wrong tool selected",
          "notes": "Agent used grep when it should have read the file directly"
        },
        "3": {
          "label": "recovery",
          "notes": "Agent recognized the mistake and tried a different approach"
        },
        "4": {"label": "correct"},
        "5": {"label": "correct"}
      },
      "cumulative_score": 2.75
    }
  }
}

配置參考

過程獎勵標註方案的完整配置項:

yaml
annotation_schemes:
  - name: process_reward
    annotation_type: process_reward
    mode: first_error              # "first_error" or "per_step"
    description: "Process reward annotation"
 
    # Required for mode: first_error
    mode: first_error
 
    # Required for mode: per_step
    mode: per_step
 
    # Common options

匯出到訓練格式

Potato 可以把過程獎勵標註直接匯出為常見 PRM 訓練流水線使用的格式。

PRM 訓練格式

匯出用於 PRM 訓練的二元步驟級標籤:

bash
python -m potato.export \
  -i output/ \
  -f prm \
  -o results/prm_training_data.jsonl

輸出格式:

json
{
  "trace_id": "trace_042",
  "steps": [
    {"content": "Search for Tokyo population", "label": 1},
    {"content": "Parse search results", "label": 1},
    {"content": "Search for NYC population", "label": -1},
    {"content": "Compare populations", "label": -1}
  ]
}

DPO / RLHF 偏好對

當同一個任務有多條已標註的 trace 時,可以匯出成對偏好資料用於 DPO 或 RLHF 訓練。匯出器會把累計獎勵更高的 trace 和更低的配成一對:

bash
python -m potato.export \
  -i output/ \
  -f dpo \
  -o results/dpo_pairs.jsonl \
  --min-score-gap 0.5

輸出格式:

json
{
  "prompt": "Fix the failing test in test_parser.py",
  "chosen": [
    {"role": "assistant", "content": "Step 1: Read the test file..."},
    {"role": "assistant", "content": "Step 2: Identify the bug..."}
  ],
  "rejected": [
    {"role": "assistant", "content": "Step 1: Run all tests..."},
    {"role": "assistant", "content": "Step 2: Edit a random file..."}
  ]
}

SWE-bench 相容結果

匯出成可用於 SWE-bench 排行榜提交的評估結果格式:

bash
python -m potato.export \
  -i output/ \
  -f swebench \
  -o results/swebench_results.json

這會生成標準的 SWE-bench 評估 JSON,包含實例 ID、模型 patch,以及由標註者判斷推匯出的解決狀態。

分析

Potato 提供了一些分析過程獎勵標註的工具函式:

python
from potato.analysis import load_annotations, process_reward_stats
 
# Load annotations
annotations = load_annotations("output/")
 
# Step-level accuracy statistics
stats = process_reward_stats(annotations)
 
print(f"Total traces annotated: {stats['total_traces']}")
print(f"Traces with no errors: {stats['all_correct_count']} ({stats['all_correct_pct']:.1f}%)")
print(f"Average first-error position: step {stats['avg_first_error_step']:.1f}")
print(f"Average steps before error: {stats['avg_correct_prefix_length']:.1f}")
 
# Error distribution by step position
for position, count in stats['error_by_position'].items():
    print(f"  Step {position}: {count} errors")
 
# Error category distribution (per-step mode only)
if 'error_categories' in stats:
    for category, count in stats['error_categories'].items():
        print(f"  {category}: {count}")
 
# Inter-annotator agreement on first-error step
if stats['multi_annotator']:
    print(f"First-error agreement (exact): {stats['first_error_exact_agreement']:.2f}")
    print(f"First-error agreement (within 1): {stats['first_error_near_agreement']:.2f}")

視覺化

python
from potato.analysis import plot_error_distribution
 
# Plot error position distribution across all traces
plot_error_distribution(
    annotations,
    output_path="figures/error_distribution.png",
    normalize_by_trace_length=True,
    title="Where Do Agents First Go Wrong?"
)
 
# Plot per-step reward curves
from potato.analysis import plot_reward_curves
 
plot_reward_curves(
    annotations,
    output_path="figures/reward_curves.png",
    group_by="agent_model",
    title="Cumulative Reward by Model"
)

研究背景

Potato 的過程獎勵標註是為支援智慧體系統獎勵模型的訓練與評估研究而設計的。近期有幾條工作線推動了這個功能:

  • AgentPRM 表明,在搜尋過程中引導編碼智慧體時,用步驟級標籤訓練的過程獎勵模型明顯優於結果獎勵模型。
  • ToolRMToolRL 表明,專門針對工具使用步驟的獎勵模型可以提升智慧體在 API 呼叫和程式碼生成任務上的表現。
  • DeepSWE 把過程獎勵模型用到 SWE-bench 規模的軟體工程任務上,用逐步標籤訓練驗證器來引導智慧體的樹搜尋。
  • 步驟級 RLHF 的研究顯示,逐步的人類反饋比整段反饋更省樣本。

Potato 的首錯模式和逐步模式直接對應這些方法所用的標籤格式。匯出流程產出的資料無需額外預處理即可用於訓練。

另請參閱

有關實現詳情,請參閱源文件