Views
No views yet
1import torch
2from transformers import AutoModel, AutoTokenizer
3import torch.nn as nn
4
5class FailureRiskModel(nn.Module):
6 def __init__(self, model_name):
7 super().__init__()
8 self.backbone = AutoModel.from_pretrained(model_name, torch_dtype=torch.bfloat16, trust_remote_code=True)
9 self.head = nn.Linear(self.backbone.config.hidden_size, 1, dtype=torch.bfloat16)
10 head_state = torch.load(f"{model_name}/head.pt", map_location="cpu", weights_only=True)
11 self.head.load_state_dict(head_state)
12
13 def forward(self, input_ids, attention_mask):
14 h = self.backbone(input_ids=input_ids, attention_mask=attention_mask).last_hidden_state
15 return self.head(h).squeeze(-1) # margins m_t, shape (B, L)
16
17model = FailureRiskModel("luca0621/OTP-Qwen2.5-Math-7B")
18tokenizer = AutoTokenizer.from_pretrained("luca0621/OTP-Qwen2.5-Math-7B", trust_remote_code=True)
19
20# Compute per-step rewards: r_t = m_t - m_{t-1}
21inputs = tokenizer("Solve: 2+2=?\\nStep 1: 2+2=4\\nAnswer: 4", return_tensors="pt")
22with torch.no_grad():
23 margins = model(**inputs) # (1, L)
24 rewards = margins[:, 1:] - margins[:, :-1] # per-token reward| Benchmark | Score |
|---|---|
| ProcessBench Avg F1 | 44.0 |
| BoN@64 (3-gen avg) | 61.3% |
| Dynamics Localization | 65.3% |
@article{otp2026,
title={Outcome-to-Process: Failure-Risk Dynamics for Dense Reward in Mathematical Reasoning},
year={2026}
}