thanhdath commited on
Commit
a04f4bb
·
verified ·
1 Parent(s): 9b9fe74

scripts: add scripts/compute_bestofn_with_selector.py

Browse files
scripts/compute_bestofn_with_selector.py CHANGED
@@ -118,6 +118,9 @@ def main():
118
  parser.add_argument("rollout_jsonl")
119
  parser.add_argument("label")
120
  parser.add_argument("--selector_host", default="http://localhost:8103")
 
 
 
121
  args = parser.parse_args()
122
 
123
  n_q = 0
@@ -188,19 +191,21 @@ def main():
188
  n_majority += 1
189
 
190
  # Trained selector: score each candidate using REAL execution result (no gold-label leak).
191
- # Re-use the exec_results computed above for rule-based majority.
 
 
192
  scores = []
193
  with ThreadPoolExecutor(max_workers=8) as exe:
194
  def _make_prompt(idx, t_):
195
  er = exec_results[idx]
196
- if er[1]:
197
- exec_str = f"Error: {er[0]}"
198
- else:
199
- rows_str = str(er[0])
200
- if not rows_str.strip() or rows_str.strip() == "[]":
201
- exec_str = "OK. Result rows (preview): (no rows)"
202
  else:
203
- exec_str = f"OK. Result rows (preview): {rows_str[:300]}"
 
 
 
204
  return build_prompt_chat(sample, t_, exec_result_str=exec_str)
205
  futs = [exe.submit(score_via_vllm, args.selector_host, _make_prompt(i, t)) for i, t in enumerate(traj)]
206
  for f in futs:
 
118
  parser.add_argument("rollout_jsonl")
119
  parser.add_argument("label")
120
  parser.add_argument("--selector_host", default="http://localhost:8103")
121
+ parser.add_argument("--row_preview", action="store_true",
122
+ help="Use 'OK. Rows preview: ...' format (matches v2 selector training data). "
123
+ "Default uses bare 'OK' / '<error>' which matches v1 selector.")
124
  args = parser.parse_args()
125
 
126
  n_q = 0
 
191
  n_majority += 1
192
 
193
  # Trained selector: score each candidate using REAL execution result (no gold-label leak).
194
+ # Prompt format MUST match the selector training data. Two options:
195
+ # --row_preview off (default): bare "OK" / "<error>" — matches v1 selector
196
+ # --row_preview on: "OK. Rows preview: <rows>" / "Error: <msg>" — matches v2 selector
197
  scores = []
198
  with ThreadPoolExecutor(max_workers=8) as exe:
199
  def _make_prompt(idx, t_):
200
  er = exec_results[idx]
201
+ if args.row_preview:
202
+ if er[1]:
203
+ exec_str = f"Error: {str(er[0])[:180]}"
 
 
 
204
  else:
205
+ rows = str(er[0])[:280]
206
+ exec_str = f"OK. Rows preview: {rows}" if rows.strip() and rows.strip() != "[]" else "OK. (no rows returned)"
207
+ else:
208
+ exec_str = f"{str(er[0])[:200]}" if er[1] else "OK"
209
  return build_prompt_chat(sample, t_, exec_result_str=exec_str)
210
  futs = [exe.submit(score_via_vllm, args.selector_host, _make_prompt(i, t)) for i, t in enumerate(traj)]
211
  for f in futs: