rsaibhargav commited on
Commit
a4ce644
Β·
verified Β·
1 Parent(s): aea798e

Update inference.py

Browse files
Files changed (1) hide show
  1. inference.py +12 -10
inference.py CHANGED
@@ -37,6 +37,7 @@ BENCHMARK = os.getenv("BENCHMARK", "code_assessment_env")
37
  MAX_STEPS = 15
38
  TEMPERATURE = 0.2
39
  MAX_TOKENS = 200
 
40
 
41
  # All 3 task types β€” inference must exercise all of them
42
  TASK_IDS = ["correctness_check", "tone_appropriateness", "multi_dimensional"]
@@ -165,9 +166,9 @@ def log_step(step: int, action: str, reward: float, done: bool, error: Optional[
165
  )
166
 
167
 
168
- def log_end(success: bool, steps: int, rewards: List[float]) -> None:
169
  rewards_str = ",".join(f"{r:.2f}" for r in rewards)
170
- print(f"[END] success={str(success).lower()} steps={steps} rewards={rewards_str}", flush=True)
171
 
172
 
173
  # ─── Prompt building ───────────────────────────────────────────────────────
@@ -354,6 +355,7 @@ async def main() -> None:
354
  break
355
 
356
  reward = result.reward if result.reward is not None else 0.05
 
357
  done = result.done
358
 
359
  rewards.append(reward)
@@ -362,25 +364,25 @@ async def main() -> None:
362
  if done:
363
  break
364
 
365
- success = bool(
366
- result is not None
367
- and obs is not None
368
- and result.done
369
- and obs.problems_solved > 0
370
- )
371
 
372
  except Exception as exc:
373
  print(f"Episode error: {exc}", file=sys.stderr, flush=True)
374
 
375
  finally:
 
 
 
376
  try:
377
  await env.close()
378
  except Exception as exc:
379
  print(f"Close error: {exc}", file=sys.stderr, flush=True)
380
- log_end(success=success, steps=steps_taken, rewards=rewards)
381
  if server_proc:
382
  server_proc.terminate()
383
 
384
 
385
  if __name__ == "__main__":
386
- asyncio.run(main())
 
37
  MAX_STEPS = 15
38
  TEMPERATURE = 0.2
39
  MAX_TOKENS = 200
40
+ SUCCESS_SCORE_THRESHOLD = 0.5
41
 
42
  # All 3 task types β€” inference must exercise all of them
43
  TASK_IDS = ["correctness_check", "tone_appropriateness", "multi_dimensional"]
 
166
  )
167
 
168
 
169
+ def log_end(success: bool, steps: int, rewards: List[float], score: float) -> None:
170
  rewards_str = ",".join(f"{r:.2f}" for r in rewards)
171
+ print(f"[END] success={str(success).lower()} steps={steps} score={score:.4f} rewards={rewards_str}", flush=True)
172
 
173
 
174
  # ─── Prompt building ───────────────────────────────────────────────────────
 
355
  break
356
 
357
  reward = result.reward if result.reward is not None else 0.05
358
+ reward = max(1e-6, min(reward, 1 - 1e-6))
359
  done = result.done
360
 
361
  rewards.append(reward)
 
364
  if done:
365
  break
366
 
367
+ score = sum(rewards) / len(rewards) if rewards else 0.0
368
+ score = max(1e-6, min(score, 1 - 1e-6))
369
+ success = score >= SUCCESS_SCORE_THRESHOLD
 
 
 
370
 
371
  except Exception as exc:
372
  print(f"Episode error: {exc}", file=sys.stderr, flush=True)
373
 
374
  finally:
375
+ score = sum(rewards) / len(rewards) if rewards else 0.0
376
+ score = max(1e-6, min(score, 1 - 1e-6))
377
+ success = score >= SUCCESS_SCORE_THRESHOLD
378
  try:
379
  await env.close()
380
  except Exception as exc:
381
  print(f"Close error: {exc}", file=sys.stderr, flush=True)
382
+ log_end(success=success, steps=steps_taken, rewards=rewards, score=score)
383
  if server_proc:
384
  server_proc.terminate()
385
 
386
 
387
  if __name__ == "__main__":
388
+ asyncio.run(main())