hugsbun commited on
Commit
00c1f31
·
1 Parent(s): a6b3f26

modified: debug_env/server/grader.py

Browse files
Files changed (2) hide show
  1. debug_env/server/grader.py +9 -6
  2. inference.py +4 -4
debug_env/server/grader.py CHANGED
@@ -1,9 +1,12 @@
1
  import ast
2
  import difflib
3
 
 
 
 
4
  def grade(pass_rate: float) -> float:
5
  """Baseline reward — direct pass rate (used as fallback)."""
6
- return float(pass_rate)
7
 
8
 
9
  def grade_by_comparison(submitted: str, reference: str) -> float:
@@ -16,7 +19,7 @@ def grade_by_comparison(submitted: str, reference: str) -> float:
16
  sub_ast = ast.unparse(ast.parse(submitted))
17
  ref_ast = ast.unparse(ast.parse(reference))
18
  if sub_ast == ref_ast:
19
- return 1.0
20
  except Exception:
21
  pass # Fall back to token comparison if syntax is invalid
22
 
@@ -24,10 +27,10 @@ def grade_by_comparison(submitted: str, reference: str) -> float:
24
  ref_lines = [line.strip() for line in reference.splitlines() if line.strip()]
25
 
26
  if not ref_lines:
27
- return 0.0 if sub_lines else 1.0
28
 
29
  matcher = difflib.SequenceMatcher(None, sub_lines, ref_lines)
30
- return round(matcher.ratio(), 4)
31
 
32
 
33
  def grade_with_steps(pass_rate: float, step_count: int, max_steps: int = 40) -> float:
@@ -40,7 +43,7 @@ def grade_with_steps(pass_rate: float, step_count: int, max_steps: int = 40) ->
40
  - Efficiency bonus: up to +0.2 for solving early (only on full solve)
41
  """
42
  if pass_rate == 0.0:
43
- return 0.0
44
 
45
  base = float(pass_rate)
46
 
@@ -56,4 +59,4 @@ def grade_with_steps(pass_rate: float, step_count: int, max_steps: int = 40) ->
56
  efficiency_bonus = 0.2 * max(0.0, 1.0 - step_count / max_steps)
57
 
58
  reward = base - penalty + completion_bonus + efficiency_bonus
59
- return round(min(max(reward, 0.0), 1.0), 4)
 
1
  import ast
2
  import difflib
3
 
4
+ def _clamp(val: float) -> float:
5
+ return float(round(min(max(val, 0.0001), 0.9999), 4))
6
+
7
  def grade(pass_rate: float) -> float:
8
  """Baseline reward — direct pass rate (used as fallback)."""
9
+ return _clamp(pass_rate)
10
 
11
 
12
  def grade_by_comparison(submitted: str, reference: str) -> float:
 
19
  sub_ast = ast.unparse(ast.parse(submitted))
20
  ref_ast = ast.unparse(ast.parse(reference))
21
  if sub_ast == ref_ast:
22
+ return 0.9999
23
  except Exception:
24
  pass # Fall back to token comparison if syntax is invalid
25
 
 
27
  ref_lines = [line.strip() for line in reference.splitlines() if line.strip()]
28
 
29
  if not ref_lines:
30
+ return 0.0001 if sub_lines else 0.9999
31
 
32
  matcher = difflib.SequenceMatcher(None, sub_lines, ref_lines)
33
+ return _clamp(matcher.ratio())
34
 
35
 
36
  def grade_with_steps(pass_rate: float, step_count: int, max_steps: int = 40) -> float:
 
43
  - Efficiency bonus: up to +0.2 for solving early (only on full solve)
44
  """
45
  if pass_rate == 0.0:
46
+ return 0.0001
47
 
48
  base = float(pass_rate)
49
 
 
59
  efficiency_bonus = 0.2 * max(0.0, 1.0 - step_count / max_steps)
60
 
61
  reward = base - penalty + completion_bonus + efficiency_bonus
62
+ return _clamp(reward)
inference.py CHANGED
@@ -318,13 +318,14 @@ async def execute_run(
318
  elapsed_ms = int((datetime.now(timezone.utc) - start_ts).total_seconds() * 1000)
319
 
320
  eval_rewards = [s["reward"] for s in steps_detail if s["tool"] in ("edit_file", "run_tests")]
321
- final_reward = sum(eval_rewards) / len(eval_rewards) if eval_rewards else 0.0
 
322
 
323
  rewards_str = ",".join(f"{r:.2f}" for r in rewards)
324
 
325
  print(
326
  f"[END] success={str(success).lower()} steps={global_step} "
327
- f"score={final_reward:.2f} rewards={rewards_str}",
328
  flush=True
329
  )
330
 
@@ -360,7 +361,6 @@ def calculate_statistics(runs: List[Dict[str, Any]]) -> Dict[str, Any]:
360
  return {
361
  "total_runs": total,
362
  "successful_runs": n_success,
363
- "success_rate": n_success / total if total else 0.0,
364
  **pass_at,
365
  "avg_steps_per_run": round(sum(len(r["rewards"]) for r in runs) / total if total else 0, 2),
366
  "avg_final_reward": round(sum(r["final_reward"] for r in runs) / total if total else 0, 4),
@@ -453,7 +453,7 @@ async def main(config: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
453
  print(f"Task: {task}")
454
  print(f"Model: {config['model_name']}")
455
  print(f"Runs: {stats['total_runs']}")
456
- print(f"Success rate: {stats['success_rate']:.1%} ({stats['successful_runs']}/{stats['total_runs']})")
457
  for k in range(1, n_runs + 1):
458
  key = f"pass@{k}"
459
  if key in stats:
 
318
  elapsed_ms = int((datetime.now(timezone.utc) - start_ts).total_seconds() * 1000)
319
 
320
  eval_rewards = [s["reward"] for s in steps_detail if s["tool"] in ("edit_file", "run_tests")]
321
+ raw_reward = sum(eval_rewards) / len(eval_rewards) if eval_rewards else 0.0001
322
+ final_reward = round(min(max(raw_reward, 0.0001), 0.9999), 4)
323
 
324
  rewards_str = ",".join(f"{r:.2f}" for r in rewards)
325
 
326
  print(
327
  f"[END] success={str(success).lower()} steps={global_step} "
328
+ f"rewards={rewards_str}",
329
  flush=True
330
  )
331
 
 
361
  return {
362
  "total_runs": total,
363
  "successful_runs": n_success,
 
364
  **pass_at,
365
  "avg_steps_per_run": round(sum(len(r["rewards"]) for r in runs) / total if total else 0, 2),
366
  "avg_final_reward": round(sum(r["final_reward"] for r in runs) / total if total else 0, 4),
 
453
  print(f"Task: {task}")
454
  print(f"Model: {config['model_name']}")
455
  print(f"Runs: {stats['total_runs']}")
456
+ print(f"Successful: {stats['successful_runs']}/{stats['total_runs']}")
457
  for k in range(1, n_runs + 1):
458
  key = f"pass@{k}"
459
  if key in stats: