Spaces:
Sleeping
Sleeping
Pranjal Parashar commited on
score fixes
Browse files- graders.py +8 -7
- inference.py +5 -4
- server/developer_control_room_environment.py +13 -0
- tasks.py +8 -2
- tests/test_calibration.py +1 -1
- tests/test_environment_behaviors.py +46 -0
graders.py
CHANGED
|
@@ -14,6 +14,10 @@ def _norm(text: str) -> str:
|
|
| 14 |
return text.lower().strip()
|
| 15 |
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def _workspace_files(state: dict, scenario: dict) -> dict[str, str]:
|
| 18 |
files = dict(scenario.get("files", {}))
|
| 19 |
files.update(state.get("edited_files", {}))
|
|
@@ -184,7 +188,7 @@ def _grade_pipeline_repair(state: dict, scenario: dict) -> dict[str, Any]:
|
|
| 184 |
and fix_path_ok == 1.0
|
| 185 |
)
|
| 186 |
|
| 187 |
-
total =
|
| 188 |
return {
|
| 189 |
"total": total,
|
| 190 |
"solved": solved,
|
|
@@ -228,7 +232,7 @@ def _grade_llm_patch_review(state: dict, scenario: dict) -> dict[str, Any]:
|
|
| 228 |
>= (2 / 3)
|
| 229 |
)
|
| 230 |
|
| 231 |
-
total =
|
| 232 |
return {
|
| 233 |
"total": total,
|
| 234 |
"solved": solved,
|
|
@@ -317,10 +321,7 @@ def _grade_workflow_shipping(state: dict, scenario: dict) -> dict[str, Any]:
|
|
| 317 |
and summary_raw == 1.0
|
| 318 |
)
|
| 319 |
|
| 320 |
-
total =
|
| 321 |
-
min(1.0, investigation + artifact_score + validator_score + governance_score + summary_score),
|
| 322 |
-
4,
|
| 323 |
-
)
|
| 324 |
return {
|
| 325 |
"total": total,
|
| 326 |
"solved": solved,
|
|
@@ -351,7 +352,7 @@ def grade(task_id: str, state: dict, scenario: dict) -> dict[str, Any]:
|
|
| 351 |
fn = graders.get(grader_family)
|
| 352 |
if fn is None:
|
| 353 |
return {
|
| 354 |
-
"total": 0.
|
| 355 |
"solved": False,
|
| 356 |
"breakdown": {},
|
| 357 |
"feedback": f"Unknown task or grader family '{task_id}'",
|
|
|
|
| 14 |
return text.lower().strip()
|
| 15 |
|
| 16 |
|
| 17 |
+
def _strict_score(value: float) -> float:
|
| 18 |
+
return round(min(0.99, max(0.01, value)), 4)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
def _workspace_files(state: dict, scenario: dict) -> dict[str, str]:
|
| 22 |
files = dict(scenario.get("files", {}))
|
| 23 |
files.update(state.get("edited_files", {}))
|
|
|
|
| 188 |
and fix_path_ok == 1.0
|
| 189 |
)
|
| 190 |
|
| 191 |
+
total = _strict_score(investigation + edit_score + validator_score + submission_score)
|
| 192 |
return {
|
| 193 |
"total": total,
|
| 194 |
"solved": solved,
|
|
|
|
| 232 |
>= (2 / 3)
|
| 233 |
)
|
| 234 |
|
| 235 |
+
total = _strict_score(investigation + verdict_score + issue_score + summary_score + validator_score)
|
| 236 |
return {
|
| 237 |
"total": total,
|
| 238 |
"solved": solved,
|
|
|
|
| 321 |
and summary_raw == 1.0
|
| 322 |
)
|
| 323 |
|
| 324 |
+
total = _strict_score(investigation + artifact_score + validator_score + governance_score + summary_score)
|
|
|
|
|
|
|
|
|
|
| 325 |
return {
|
| 326 |
"total": total,
|
| 327 |
"solved": solved,
|
|
|
|
| 352 |
fn = graders.get(grader_family)
|
| 353 |
if fn is None:
|
| 354 |
return {
|
| 355 |
+
"total": 0.01,
|
| 356 |
"solved": False,
|
| 357 |
"breakdown": {},
|
| 358 |
"feedback": f"Unknown task or grader family '{task_id}'",
|
inference.py
CHANGED
|
@@ -70,9 +70,9 @@ load_env_file()
|
|
| 70 |
LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME") or os.getenv("IMAGE_NAME")
|
| 71 |
DEFAULT_ENV_URL = "https://praanjal-control-room.hf.space"
|
| 72 |
ENV_URL = os.getenv("ENV_URL") or DEFAULT_ENV_URL
|
| 73 |
-
API_KEY = os.
|
| 74 |
|
| 75 |
-
API_BASE_URL = os.
|
| 76 |
MODEL_NAME = os.getenv("MODEL_NAME") or "Qwen/Qwen2.5-72B-Instruct"
|
| 77 |
TASK_NAME = os.getenv("DEVELOPER_CONTROL_ROOM_TASK")
|
| 78 |
BENCHMARK = os.getenv("DEVELOPER_CONTROL_ROOM_BENCHMARK", "developer_control_room")
|
|
@@ -113,8 +113,9 @@ def log_step(step: int, action: str, reward: float, done: bool, error: Optional[
|
|
| 113 |
|
| 114 |
def log_end(success: bool, steps: int, score: float, rewards: List[float]) -> None:
|
| 115 |
rewards_str = ",".join(f"{r:.2f}" for r in rewards)
|
|
|
|
| 116 |
print(
|
| 117 |
-
f"[END] success={str(success).lower()} steps={steps} score={
|
| 118 |
flush=True,
|
| 119 |
)
|
| 120 |
|
|
@@ -209,7 +210,7 @@ def record_episode_memory(
|
|
| 209 |
"task_id": task_name,
|
| 210 |
"scenario_id": scenario_id or "unknown",
|
| 211 |
"solved": bool(solved),
|
| 212 |
-
"score":
|
| 213 |
"takeaway": takeaway,
|
| 214 |
"actions": history[-4:],
|
| 215 |
}
|
|
|
|
| 70 |
LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME") or os.getenv("IMAGE_NAME")
|
| 71 |
DEFAULT_ENV_URL = "https://praanjal-control-room.hf.space"
|
| 72 |
ENV_URL = os.getenv("ENV_URL") or DEFAULT_ENV_URL
|
| 73 |
+
API_KEY = os.environ["API_KEY"]
|
| 74 |
|
| 75 |
+
API_BASE_URL = os.environ["API_BASE_URL"]
|
| 76 |
MODEL_NAME = os.getenv("MODEL_NAME") or "Qwen/Qwen2.5-72B-Instruct"
|
| 77 |
TASK_NAME = os.getenv("DEVELOPER_CONTROL_ROOM_TASK")
|
| 78 |
BENCHMARK = os.getenv("DEVELOPER_CONTROL_ROOM_BENCHMARK", "developer_control_room")
|
|
|
|
| 113 |
|
| 114 |
def log_end(success: bool, steps: int, score: float, rewards: List[float]) -> None:
|
| 115 |
rewards_str = ",".join(f"{r:.2f}" for r in rewards)
|
| 116 |
+
bounded_score = min(0.99, max(0.01, score))
|
| 117 |
print(
|
| 118 |
+
f"[END] success={str(success).lower()} steps={steps} score={bounded_score:.2f} rewards={rewards_str}",
|
| 119 |
flush=True,
|
| 120 |
)
|
| 121 |
|
|
|
|
| 210 |
"task_id": task_name,
|
| 211 |
"scenario_id": scenario_id or "unknown",
|
| 212 |
"solved": bool(solved),
|
| 213 |
+
"score": min(0.99, max(0.01, score)),
|
| 214 |
"takeaway": takeaway,
|
| 215 |
"actions": history[-4:],
|
| 216 |
}
|
server/developer_control_room_environment.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
|
|
|
| 5 |
from uuid import uuid4
|
| 6 |
|
| 7 |
from openenv.core.env_server.interfaces import Environment
|
|
@@ -35,6 +36,12 @@ class DeveloperControlRoomEnvironment(
|
|
| 35 |
"""Singleton-friendly environment simulating a developer workspace."""
|
| 36 |
|
| 37 |
SUPPORTS_CONCURRENT_SESSIONS = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
def __init__(self) -> None:
|
| 40 |
self._task_def: dict = {}
|
|
@@ -137,7 +144,13 @@ class DeveloperControlRoomEnvironment(
|
|
| 137 |
|
| 138 |
after_result = grade(self._state.task_id or "", self._state.model_dump(), self._scenario)
|
| 139 |
progress_delta = after_result["total"] - before
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
reward += progress_delta
|
|
|
|
|
|
|
| 141 |
self._state.cumulative_reward = round(self._state.cumulative_reward + reward, 4)
|
| 142 |
self._state.feedback = " | ".join(part for part in feedback if part) or after_result["feedback"]
|
| 143 |
|
|
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
+
import os
|
| 6 |
from uuid import uuid4
|
| 7 |
|
| 8 |
from openenv.core.env_server.interfaces import Environment
|
|
|
|
| 36 |
"""Singleton-friendly environment simulating a developer workspace."""
|
| 37 |
|
| 38 |
SUPPORTS_CONCURRENT_SESSIONS = False
|
| 39 |
+
MAX_PROGRESS_DELTA_REWARD = float(
|
| 40 |
+
os.getenv("DEVELOPER_CONTROL_ROOM_MAX_PROGRESS_DELTA_REWARD", "0.30")
|
| 41 |
+
)
|
| 42 |
+
SOLVED_TERMINAL_REWARD_BONUS = float(
|
| 43 |
+
os.getenv("DEVELOPER_CONTROL_ROOM_SOLVED_TERMINAL_REWARD_BONUS", "0.10")
|
| 44 |
+
)
|
| 45 |
|
| 46 |
def __init__(self) -> None:
|
| 47 |
self._task_def: dict = {}
|
|
|
|
| 144 |
|
| 145 |
after_result = grade(self._state.task_id or "", self._state.model_dump(), self._scenario)
|
| 146 |
progress_delta = after_result["total"] - before
|
| 147 |
+
progress_delta = max(
|
| 148 |
+
-self.MAX_PROGRESS_DELTA_REWARD,
|
| 149 |
+
min(self.MAX_PROGRESS_DELTA_REWARD, progress_delta),
|
| 150 |
+
)
|
| 151 |
reward += progress_delta
|
| 152 |
+
if self._state.done and after_result.get("solved"):
|
| 153 |
+
reward += self.SOLVED_TERMINAL_REWARD_BONUS
|
| 154 |
self._state.cumulative_reward = round(self._state.cumulative_reward + reward, 4)
|
| 155 |
self._state.feedback = " | ".join(part for part in feedback if part) or after_result["feedback"]
|
| 156 |
|
tasks.py
CHANGED
|
@@ -1288,7 +1288,12 @@ grain:
|
|
| 1288 |
review_target={
|
| 1289 |
"correct_verdict": "reject",
|
| 1290 |
"correct_issue_type": "technical_incorrectness",
|
| 1291 |
-
"summary_groups": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1292 |
"investigation_targets": [
|
| 1293 |
("inspect_llm_draft", "primary"),
|
| 1294 |
("read_file", "drafts/merchant_settlement_rollup.patch"),
|
|
@@ -1375,7 +1380,7 @@ published_columns:
|
|
| 1375 |
("read_file", "policies/published_contracts.md"),
|
| 1376 |
("run_validator", "contract_guard"),
|
| 1377 |
],
|
| 1378 |
-
"validator_targets": ["contract_guard"
|
| 1379 |
},
|
| 1380 |
validators={
|
| 1381 |
"contract_guard": review_validator(
|
|
@@ -1436,6 +1441,7 @@ policy_owner: platform-sre
|
|
| 1436 |
"summary_groups": [["drop", "recreate"], ["disable", "checks"], ["unsafe", "policy"]],
|
| 1437 |
"investigation_targets": [
|
| 1438 |
("inspect_llm_draft", "primary"),
|
|
|
|
| 1439 |
("read_file", "policies/recovery_playbook.md"),
|
| 1440 |
("run_validator", "safety_guard"),
|
| 1441 |
],
|
|
|
|
| 1288 |
review_target={
|
| 1289 |
"correct_verdict": "reject",
|
| 1290 |
"correct_issue_type": "technical_incorrectness",
|
| 1291 |
+
"summary_groups": [
|
| 1292 |
+
["join"],
|
| 1293 |
+
["settlement_id", "merchant_id"],
|
| 1294 |
+
["wrong", "incorrect"],
|
| 1295 |
+
["grain", "one row per settlement_id"],
|
| 1296 |
+
],
|
| 1297 |
"investigation_targets": [
|
| 1298 |
("inspect_llm_draft", "primary"),
|
| 1299 |
("read_file", "drafts/merchant_settlement_rollup.patch"),
|
|
|
|
| 1380 |
("read_file", "policies/published_contracts.md"),
|
| 1381 |
("run_validator", "contract_guard"),
|
| 1382 |
],
|
| 1383 |
+
"validator_targets": ["contract_guard"],
|
| 1384 |
},
|
| 1385 |
validators={
|
| 1386 |
"contract_guard": review_validator(
|
|
|
|
| 1441 |
"summary_groups": [["drop", "recreate"], ["disable", "checks"], ["unsafe", "policy"]],
|
| 1442 |
"investigation_targets": [
|
| 1443 |
("inspect_llm_draft", "primary"),
|
| 1444 |
+
("read_file", "drafts/warehouse_recovery_response.md"),
|
| 1445 |
("read_file", "policies/recovery_playbook.md"),
|
| 1446 |
("run_validator", "safety_guard"),
|
| 1447 |
],
|
tests/test_calibration.py
CHANGED
|
@@ -31,7 +31,7 @@ def collect_scores() -> dict[str, list[float]]:
|
|
| 31 |
def test_scores_stay_in_range() -> None:
|
| 32 |
for task_scores in collect_scores().values():
|
| 33 |
for score in task_scores:
|
| 34 |
-
assert 0.0 <
|
| 35 |
|
| 36 |
|
| 37 |
def test_easy_medium_hard_ordering() -> None:
|
|
|
|
| 31 |
def test_scores_stay_in_range() -> None:
|
| 32 |
for task_scores in collect_scores().values():
|
| 33 |
for score in task_scores:
|
| 34 |
+
assert 0.0 < score < 1.0
|
| 35 |
|
| 36 |
|
| 37 |
def test_easy_medium_hard_ordering() -> None:
|
tests/test_environment_behaviors.py
CHANGED
|
@@ -210,3 +210,49 @@ def test_seeded_variants_are_deterministic_and_change_literals() -> None:
|
|
| 210 |
assert first["developer_request"] == second["developer_request"]
|
| 211 |
assert first["files"]["schemas/subscription_mrr_daily.json"] == second["files"]["schemas/subscription_mrr_daily.json"]
|
| 212 |
assert first["developer_request"] != third["developer_request"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
assert first["developer_request"] == second["developer_request"]
|
| 211 |
assert first["files"]["schemas/subscription_mrr_daily.json"] == second["files"]["schemas/subscription_mrr_daily.json"]
|
| 212 |
assert first["developer_request"] != third["developer_request"]
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def test_review_submission_reward_is_capped() -> None:
|
| 216 |
+
env = DeveloperControlRoomEnvironment()
|
| 217 |
+
observation = env.reset(task_id="review_ai_patch_safety", scenario_index=0)
|
| 218 |
+
|
| 219 |
+
for _ in range(3):
|
| 220 |
+
action_dict = fallback_action("review_ai_patch_safety", observation)
|
| 221 |
+
observation = env.step(build_action(action_dict))
|
| 222 |
+
|
| 223 |
+
submit_action = fallback_action("review_ai_patch_safety", observation)
|
| 224 |
+
result = env.step(build_action(submit_action))
|
| 225 |
+
|
| 226 |
+
assert submit_action["action_type"] == "submit_review"
|
| 227 |
+
assert result.reward <= (
|
| 228 |
+
DeveloperControlRoomEnvironment.MAX_PROGRESS_DELTA_REWARD
|
| 229 |
+
+ DeveloperControlRoomEnvironment.SOLVED_TERMINAL_REWARD_BONUS
|
| 230 |
+
+ 0.02
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def test_repair_edit_progress_reward_is_capped() -> None:
|
| 235 |
+
env = DeveloperControlRoomEnvironment()
|
| 236 |
+
observation = env.reset(task_id="repair_data_transform", scenario_index=0)
|
| 237 |
+
|
| 238 |
+
for _ in range(2):
|
| 239 |
+
action_dict = fallback_action("repair_data_transform", observation)
|
| 240 |
+
observation = env.step(build_action(action_dict))
|
| 241 |
+
|
| 242 |
+
edit_action = fallback_action("repair_data_transform", observation)
|
| 243 |
+
result = env.step(build_action(edit_action))
|
| 244 |
+
|
| 245 |
+
assert edit_action["action_type"] == "edit_file"
|
| 246 |
+
assert result.reward <= DeveloperControlRoomEnvironment.MAX_PROGRESS_DELTA_REWARD
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def test_solved_episode_gets_terminal_bonus() -> None:
|
| 250 |
+
env = DeveloperControlRoomEnvironment()
|
| 251 |
+
observation = env.reset(task_id="review_ai_patch_safety", scenario_index=0)
|
| 252 |
+
|
| 253 |
+
while not env._state.done:
|
| 254 |
+
action_dict = fallback_action("review_ai_patch_safety", observation)
|
| 255 |
+
observation = env.step(build_action(action_dict))
|
| 256 |
+
|
| 257 |
+
assert observation.done is True
|
| 258 |
+
assert observation.reward >= DeveloperControlRoomEnvironment.SOLVED_TERMINAL_REWARD_BONUS
|