Spaces:
Sleeping
Sleeping
Pranav Dhiran commited on
Commit Β·
a78a875
1
Parent(s): f9cce06
final 2 6
Browse files- app/environment.py +1 -1
- app/main.py +8 -2
- app/tasks/base.py +1 -1
- baseline.py +26 -4
- inference.py +27 -4
- server/app.py +8 -2
app/environment.py
CHANGED
|
@@ -66,7 +66,7 @@ class EnvironmentManager:
|
|
| 66 |
self._sessions: Dict[str, Session] = {}
|
| 67 |
|
| 68 |
@staticmethod
|
| 69 |
-
def _clamp_score_strict(score: float, eps: float =
|
| 70 |
"""
|
| 71 |
Hackathon validator requirement: task scores must be strictly within (0, 1).
|
| 72 |
We clamp away from exact endpoints to avoid returning 0.0 or 1.0.
|
|
|
|
| 66 |
self._sessions: Dict[str, Session] = {}
|
| 67 |
|
| 68 |
@staticmethod
|
| 69 |
+
def _clamp_score_strict(score: float, eps: float = 0.01) -> float:
|
| 70 |
"""
|
| 71 |
Hackathon validator requirement: task scores must be strictly within (0, 1).
|
| 72 |
We clamp away from exact endpoints to avoid returning 0.0 or 1.0.
|
app/main.py
CHANGED
|
@@ -226,13 +226,19 @@ async def baseline(request: BaselineRequest = Body(default=BaselineRequest())):
|
|
| 226 |
max_steps=request.max_steps,
|
| 227 |
task_ids=request.tasks,
|
| 228 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
return {
|
| 230 |
"model": request.model,
|
| 231 |
"results": results,
|
| 232 |
"summary": {
|
| 233 |
"mean_score": round(
|
| 234 |
-
sum(
|
| 235 |
-
) if
|
| 236 |
"tasks_passed": sum(
|
| 237 |
1 for r in results
|
| 238 |
if r["score"] >= TASK_REGISTRY[r["task_id"]].passing_score
|
|
|
|
| 226 |
max_steps=request.max_steps,
|
| 227 |
task_ids=request.tasks,
|
| 228 |
)
|
| 229 |
+
|
| 230 |
+
# Ensure validator-safe scores even if baseline errored or returned edge values.
|
| 231 |
+
safe_scores = [env_manager._clamp_score_strict(r.get("score", 0.0)) for r in results]
|
| 232 |
+
for r, s in zip(results, safe_scores):
|
| 233 |
+
r["score"] = s
|
| 234 |
+
|
| 235 |
return {
|
| 236 |
"model": request.model,
|
| 237 |
"results": results,
|
| 238 |
"summary": {
|
| 239 |
"mean_score": round(
|
| 240 |
+
sum(safe_scores) / len(safe_scores), 4
|
| 241 |
+
) if safe_scores else env_manager._clamp_score_strict(0.0),
|
| 242 |
"tasks_passed": sum(
|
| 243 |
1 for r in results
|
| 244 |
if r["score"] >= TASK_REGISTRY[r["task_id"]].passing_score
|
app/tasks/base.py
CHANGED
|
@@ -122,7 +122,7 @@ class BaseTask(ABC):
|
|
| 122 |
...
|
| 123 |
|
| 124 |
@staticmethod
|
| 125 |
-
def clamp_score_strict(score: float, eps: float =
|
| 126 |
"""
|
| 127 |
Hackathon validator requirement: scores must be strictly within (0, 1).
|
| 128 |
Use this at the end of task graders to avoid returning exactly 0.0 or 1.0.
|
|
|
|
| 122 |
...
|
| 123 |
|
| 124 |
@staticmethod
|
| 125 |
+
def clamp_score_strict(score: float, eps: float = 0.01) -> float:
|
| 126 |
"""
|
| 127 |
Hackathon validator requirement: scores must be strictly within (0, 1).
|
| 128 |
Use this at the end of task graders to avoid returning exactly 0.0 or 1.0.
|
baseline.py
CHANGED
|
@@ -80,6 +80,22 @@ Respond ONLY with JSON. No markdown. No explanation."""
|
|
| 80 |
|
| 81 |
# βββ Helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
def log(msg: str, level: str = "INFO"):
|
| 84 |
prefix = {"INFO": "βΉ", "OK": "β", "WARN": "β ", "ERR": "β"}.get(level, "β’")
|
| 85 |
print(f" {prefix} {msg}")
|
|
@@ -283,13 +299,14 @@ def run_task(
|
|
| 283 |
task_info = t
|
| 284 |
break
|
| 285 |
|
|
|
|
| 286 |
return {
|
| 287 |
"task_id": task_id,
|
| 288 |
"task_name": task_info.get("name", task_id),
|
| 289 |
"difficulty": task_info.get("difficulty", "?"),
|
| 290 |
-
"score":
|
| 291 |
"steps_taken": steps_taken,
|
| 292 |
-
"success":
|
| 293 |
"episode_log": episode_log,
|
| 294 |
}
|
| 295 |
|
|
@@ -350,7 +367,11 @@ def main():
|
|
| 350 |
|
| 351 |
# ββ Summary βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 352 |
elapsed = time.time() - start
|
| 353 |
-
mean_score =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
passed = sum(1 for r in results if r["success"])
|
| 355 |
|
| 356 |
print(f"\n{'β'*60}")
|
|
@@ -376,7 +397,8 @@ def main():
|
|
| 376 |
"environment": "sre-incident-response",
|
| 377 |
"results": results,
|
| 378 |
"summary": {
|
| 379 |
-
|
|
|
|
| 380 |
"tasks_passed": passed,
|
| 381 |
"total_tasks": len(results),
|
| 382 |
"elapsed_seconds": round(elapsed, 1),
|
|
|
|
| 80 |
|
| 81 |
# βββ Helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 82 |
|
| 83 |
+
def clamp_score_strict(score: float, eps: float = 1e-3) -> float:
|
| 84 |
+
"""
|
| 85 |
+
Hackathon validator requirement: scores must be strictly within (0, 1).
|
| 86 |
+
Clamp away from endpoints to avoid returning exactly 0.0 or 1.0.
|
| 87 |
+
"""
|
| 88 |
+
try:
|
| 89 |
+
s = float(score)
|
| 90 |
+
except Exception:
|
| 91 |
+
s = 0.0
|
| 92 |
+
if s <= 0.0:
|
| 93 |
+
return eps
|
| 94 |
+
if s >= 1.0:
|
| 95 |
+
return 1.0 - eps
|
| 96 |
+
return s
|
| 97 |
+
|
| 98 |
+
|
| 99 |
def log(msg: str, level: str = "INFO"):
|
| 100 |
prefix = {"INFO": "βΉ", "OK": "β", "WARN": "β ", "ERR": "β"}.get(level, "β’")
|
| 101 |
print(f" {prefix} {msg}")
|
|
|
|
| 299 |
task_info = t
|
| 300 |
break
|
| 301 |
|
| 302 |
+
final_score = clamp_score_strict(score)
|
| 303 |
return {
|
| 304 |
"task_id": task_id,
|
| 305 |
"task_name": task_info.get("name", task_id),
|
| 306 |
"difficulty": task_info.get("difficulty", "?"),
|
| 307 |
+
"score": final_score,
|
| 308 |
"steps_taken": steps_taken,
|
| 309 |
+
"success": final_score >= task_info.get("passing_score", 0.6),
|
| 310 |
"episode_log": episode_log,
|
| 311 |
}
|
| 312 |
|
|
|
|
| 367 |
|
| 368 |
# ββ Summary βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 369 |
elapsed = time.time() - start
|
| 370 |
+
mean_score = (
|
| 371 |
+
sum(r["score"] for r in results) / len(results)
|
| 372 |
+
if results
|
| 373 |
+
else clamp_score_strict(0.0)
|
| 374 |
+
)
|
| 375 |
passed = sum(1 for r in results if r["success"])
|
| 376 |
|
| 377 |
print(f"\n{'β'*60}")
|
|
|
|
| 397 |
"environment": "sre-incident-response",
|
| 398 |
"results": results,
|
| 399 |
"summary": {
|
| 400 |
+
# Avoid rounding to 0.0/1.0; validator requires strict (0,1).
|
| 401 |
+
"mean_score": clamp_score_strict(mean_score),
|
| 402 |
"tasks_passed": passed,
|
| 403 |
"total_tasks": len(results),
|
| 404 |
"elapsed_seconds": round(elapsed, 1),
|
inference.py
CHANGED
|
@@ -128,7 +128,7 @@ def emit_block(tag: str, payload: dict):
|
|
| 128 |
safe_print(f"[{tag}] {line}")
|
| 129 |
|
| 130 |
|
| 131 |
-
def clamp_score_strict(score: float, eps: float =
|
| 132 |
"""
|
| 133 |
Hackathon validator requirement: scores must be strictly within (0, 1).
|
| 134 |
Clamp away from endpoints to avoid returning exactly 0.0 or 1.0.
|
|
@@ -453,7 +453,11 @@ def run_task(
|
|
| 453 |
"parameters": parameters,
|
| 454 |
"reward": reward_val,
|
| 455 |
"done": done,
|
| 456 |
-
"grader_score":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
},
|
| 458 |
)
|
| 459 |
|
|
@@ -599,13 +603,31 @@ def main():
|
|
| 599 |
if not _wait_for_health(args.base_url, timeout_s=20.0):
|
| 600 |
x = "β" if UNICODE_OK else "x"
|
| 601 |
safe_print(f"\n {x} Environment not reachable at {args.base_url}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 602 |
emit_block(
|
| 603 |
"END",
|
| 604 |
{
|
| 605 |
"model": args.model,
|
| 606 |
"environment": "sre-incident-response",
|
| 607 |
-
"results":
|
| 608 |
-
"summary": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 609 |
"error": f"Environment not reachable at {args.base_url}",
|
| 610 |
},
|
| 611 |
)
|
|
@@ -637,6 +659,7 @@ def main():
|
|
| 637 |
# ββ Summary βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 638 |
elapsed = time.time() - start
|
| 639 |
mean_score = sum(r["score"] for r in results) / len(results) if results else clamp_score_strict(0.0)
|
|
|
|
| 640 |
passed = sum(1 for r in results if r["success"])
|
| 641 |
|
| 642 |
safe_print(f"\n{HR_THICK*60}")
|
|
|
|
| 128 |
safe_print(f"[{tag}] {line}")
|
| 129 |
|
| 130 |
|
| 131 |
+
def clamp_score_strict(score: float, eps: float = 0.01) -> float:
|
| 132 |
"""
|
| 133 |
Hackathon validator requirement: scores must be strictly within (0, 1).
|
| 134 |
Clamp away from endpoints to avoid returning exactly 0.0 or 1.0.
|
|
|
|
| 453 |
"parameters": parameters,
|
| 454 |
"reward": reward_val,
|
| 455 |
"done": done,
|
| 456 |
+
"grader_score": (
|
| 457 |
+
clamp_score_strict(step_data.get("info", {}).get("grader_score"))
|
| 458 |
+
if step_data.get("info", {}).get("grader_score") is not None
|
| 459 |
+
else None
|
| 460 |
+
),
|
| 461 |
},
|
| 462 |
)
|
| 463 |
|
|
|
|
| 603 |
if not _wait_for_health(args.base_url, timeout_s=20.0):
|
| 604 |
x = "β" if UNICODE_OK else "x"
|
| 605 |
safe_print(f"\n {x} Environment not reachable at {args.base_url}")
|
| 606 |
+
# Some validators expect per-task scores even on failure. Emit placeholder
|
| 607 |
+
# task results with strictly (0,1) scores so the run is still parseable.
|
| 608 |
+
placeholder_results = [
|
| 609 |
+
{
|
| 610 |
+
"task_id": tid,
|
| 611 |
+
"task_name": tid,
|
| 612 |
+
"difficulty": "?",
|
| 613 |
+
"score": clamp_score_strict(0.0),
|
| 614 |
+
"steps_taken": 0,
|
| 615 |
+
"success": False,
|
| 616 |
+
"episode_log": [{"error": f"Environment not reachable at {args.base_url}"}],
|
| 617 |
+
}
|
| 618 |
+
for tid in list(args.tasks)
|
| 619 |
+
]
|
| 620 |
emit_block(
|
| 621 |
"END",
|
| 622 |
{
|
| 623 |
"model": args.model,
|
| 624 |
"environment": "sre-incident-response",
|
| 625 |
+
"results": placeholder_results,
|
| 626 |
+
"summary": {
|
| 627 |
+
"mean_score": clamp_score_strict(0.0),
|
| 628 |
+
"tasks_passed": 0,
|
| 629 |
+
"total_tasks": len(placeholder_results),
|
| 630 |
+
},
|
| 631 |
"error": f"Environment not reachable at {args.base_url}",
|
| 632 |
},
|
| 633 |
)
|
|
|
|
| 659 |
# ββ Summary βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 660 |
elapsed = time.time() - start
|
| 661 |
mean_score = sum(r["score"] for r in results) / len(results) if results else clamp_score_strict(0.0)
|
| 662 |
+
mean_score = clamp_score_strict(mean_score)
|
| 663 |
passed = sum(1 for r in results if r["success"])
|
| 664 |
|
| 665 |
safe_print(f"\n{HR_THICK*60}")
|
server/app.py
CHANGED
|
@@ -226,13 +226,19 @@ async def baseline(request: BaselineRequest = Body(default=BaselineRequest())):
|
|
| 226 |
max_steps=request.max_steps,
|
| 227 |
task_ids=request.tasks,
|
| 228 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
return {
|
| 230 |
"model": request.model,
|
| 231 |
"results": results,
|
| 232 |
"summary": {
|
| 233 |
"mean_score": round(
|
| 234 |
-
sum(
|
| 235 |
-
) if
|
| 236 |
"tasks_passed": sum(
|
| 237 |
1 for r in results
|
| 238 |
if r["score"] >= TASK_REGISTRY[r["task_id"]].passing_score
|
|
|
|
| 226 |
max_steps=request.max_steps,
|
| 227 |
task_ids=request.tasks,
|
| 228 |
)
|
| 229 |
+
|
| 230 |
+
# Ensure validator-safe scores even if baseline errored or returned edge values.
|
| 231 |
+
safe_scores = [env_manager._clamp_score_strict(r.get("score", 0.0)) for r in results]
|
| 232 |
+
for r, s in zip(results, safe_scores):
|
| 233 |
+
r["score"] = s
|
| 234 |
+
|
| 235 |
return {
|
| 236 |
"model": request.model,
|
| 237 |
"results": results,
|
| 238 |
"summary": {
|
| 239 |
"mean_score": round(
|
| 240 |
+
sum(safe_scores) / len(safe_scores), 4
|
| 241 |
+
) if safe_scores else env_manager._clamp_score_strict(0.0),
|
| 242 |
"tasks_passed": sum(
|
| 243 |
1 for r in results
|
| 244 |
if r["score"] >= TASK_REGISTRY[r["task_id"]].passing_score
|