Spaces:
Sleeping
Sleeping
Commit Β·
a166934
1
Parent(s): efaec4a
fix: wire RewardEngine into environment for dense rewards, fix step-limit mismatches
Browse files- README.md +3 -3
- app/environment.py +26 -5
README.md
CHANGED
|
@@ -34,7 +34,7 @@ tags:
|
|
| 34 |
| π **Live Environment** | [https://huggingface.co/spaces/CoBeDigger/DataEngEnv](https://huggingface.co/spaces/CoBeDigger/DataEngEnv) |
|
| 35 |
| π€ **Trained Model** | [CoBeDigger/pipelineops-arena-llama3-grpo](https://huggingface.co/CoBeDigger/pipelineops-arena-llama3-grpo) |
|
| 36 |
| π **Reward Curve** | [View on Model Repo](https://huggingface.co/CoBeDigger/pipelineops-arena-llama3-grpo/blob/main/reward_curve.png) |
|
| 37 |
-
| π **Training Notebook** | *(
|
| 38 |
|
| 39 |
---
|
| 40 |
|
|
@@ -127,7 +127,7 @@ The reward curve shows a clear upward learning trend β the agent progresses fr
|
|
| 127 |
| Field | Type | Description |
|
| 128 |
|---|---|---|
|
| 129 |
| `current_stage` | `int` | Current pipeline stage (1-4) |
|
| 130 |
-
| `step_number` | `int` | Current step (max
|
| 131 |
| `script_content` | `str` | The current state of the pipeline script |
|
| 132 |
| `last_run_output` | `str` | stdout from the last `run_script` action |
|
| 133 |
| `last_run_error` | `str \| null` | stderr / exception if the script crashed |
|
|
@@ -217,7 +217,7 @@ ENV_URL = "https://cobedigger-dataengenv.hf.space"
|
|
| 217 |
obs = requests.post(f"{ENV_URL}/reset").json()
|
| 218 |
|
| 219 |
# Agent loop
|
| 220 |
-
for step in range(
|
| 221 |
action = your_agent.decide(obs)
|
| 222 |
result = requests.post(f"{ENV_URL}/step", json=action).json()
|
| 223 |
obs = result["observation"]
|
|
|
|
| 34 |
| π **Live Environment** | [https://huggingface.co/spaces/CoBeDigger/DataEngEnv](https://huggingface.co/spaces/CoBeDigger/DataEngEnv) |
|
| 35 |
| π€ **Trained Model** | [CoBeDigger/pipelineops-arena-llama3-grpo](https://huggingface.co/CoBeDigger/pipelineops-arena-llama3-grpo) |
|
| 36 |
| π **Reward Curve** | [View on Model Repo](https://huggingface.co/CoBeDigger/pipelineops-arena-llama3-grpo/blob/main/reward_curve.png) |
|
| 37 |
+
| π **Training Notebook** | *(Add your Kaggle/Colab link here)* |
|
| 38 |
|
| 39 |
---
|
| 40 |
|
|
|
|
| 127 |
| Field | Type | Description |
|
| 128 |
|---|---|---|
|
| 129 |
| `current_stage` | `int` | Current pipeline stage (1-4) |
|
| 130 |
+
| `step_number` | `int` | Current step (max 60 total, 15 per stage) |
|
| 131 |
| `script_content` | `str` | The current state of the pipeline script |
|
| 132 |
| `last_run_output` | `str` | stdout from the last `run_script` action |
|
| 133 |
| `last_run_error` | `str \| null` | stderr / exception if the script crashed |
|
|
|
|
| 217 |
obs = requests.post(f"{ENV_URL}/reset").json()
|
| 218 |
|
| 219 |
# Agent loop
|
| 220 |
+
for step in range(60): # 60 total steps, 15 per stage
|
| 221 |
action = your_agent.decide(obs)
|
| 222 |
result = requests.post(f"{ENV_URL}/step", json=action).json()
|
| 223 |
obs = result["observation"]
|
app/environment.py
CHANGED
|
@@ -12,6 +12,7 @@ from app.actors.code_reviewer import CodeReviewer
|
|
| 12 |
from app.actors.mlops_bot import MLOpsBot
|
| 13 |
from app.graders import grader_stage1, grader_stage2, grader_stage3, grader_stage4
|
| 14 |
from app.models import Action, Observation, Reward, StateResponse, StepResponse
|
|
|
|
| 15 |
from app.tasks import (
|
| 16 |
stage1_data_repair,
|
| 17 |
stage2_training_monitor,
|
|
@@ -45,6 +46,7 @@ class DataEngEnvironment:
|
|
| 45 |
|
| 46 |
self._code_reviewer = CodeReviewer()
|
| 47 |
self._mlops_bot = MLOpsBot()
|
|
|
|
| 48 |
|
| 49 |
def reset(self, task_id: int | None = None) -> Observation:
|
| 50 |
self.current_task_id = 1
|
|
@@ -55,6 +57,7 @@ class DataEngEnvironment:
|
|
| 55 |
self.stages_completed = []
|
| 56 |
self.episode_score = 0.0
|
| 57 |
self.actor_feedback = ""
|
|
|
|
| 58 |
self.done = False
|
| 59 |
self.last_run_output = ""
|
| 60 |
self.last_run_error = None
|
|
@@ -309,12 +312,30 @@ class DataEngEnvironment:
|
|
| 309 |
message = f"{message} Stage or episode step limit reached."
|
| 310 |
|
| 311 |
obs = self._get_observation(partial_schema=schema, partial_preview=preview)
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
return StepResponse(
|
| 316 |
observation=obs,
|
| 317 |
-
reward=
|
| 318 |
)
|
| 319 |
|
| 320 |
def submit_grader(self, task_id: int | None = None) -> Reward:
|
|
@@ -326,7 +347,7 @@ class DataEngEnvironment:
|
|
| 326 |
return StateResponse(
|
| 327 |
task_id=self.current_task_id,
|
| 328 |
step_number=self.step_number,
|
| 329 |
-
max_steps=
|
| 330 |
current_script=self.current_script,
|
| 331 |
episode_done=self.done,
|
| 332 |
task_description=self.task_description,
|
|
|
|
| 12 |
from app.actors.mlops_bot import MLOpsBot
|
| 13 |
from app.graders import grader_stage1, grader_stage2, grader_stage3, grader_stage4
|
| 14 |
from app.models import Action, Observation, Reward, StateResponse, StepResponse
|
| 15 |
+
from app.reward import RewardEngine
|
| 16 |
from app.tasks import (
|
| 17 |
stage1_data_repair,
|
| 18 |
stage2_training_monitor,
|
|
|
|
| 46 |
|
| 47 |
self._code_reviewer = CodeReviewer()
|
| 48 |
self._mlops_bot = MLOpsBot()
|
| 49 |
+
self._reward_engine = RewardEngine()
|
| 50 |
|
| 51 |
def reset(self, task_id: int | None = None) -> Observation:
|
| 52 |
self.current_task_id = 1
|
|
|
|
| 57 |
self.stages_completed = []
|
| 58 |
self.episode_score = 0.0
|
| 59 |
self.actor_feedback = ""
|
| 60 |
+
self._reward_engine = RewardEngine()
|
| 61 |
self.done = False
|
| 62 |
self.last_run_output = ""
|
| 63 |
self.last_run_error = None
|
|
|
|
| 312 |
message = f"{message} Stage or episode step limit reached."
|
| 313 |
|
| 314 |
obs = self._get_observation(partial_schema=schema, partial_preview=preview)
|
| 315 |
+
|
| 316 |
+
# Use RewardEngine for dense partial rewards on every action
|
| 317 |
+
shaped_reward = self._reward_engine.compute_reward(
|
| 318 |
+
task_id=self.current_stage,
|
| 319 |
+
action_type=action.action_type,
|
| 320 |
+
action_payload=action.payload or {},
|
| 321 |
+
observation={
|
| 322 |
+
"last_run_error": self.last_run_error,
|
| 323 |
+
"data_preview": preview,
|
| 324 |
+
},
|
| 325 |
+
grader_score=score,
|
| 326 |
+
step_number=self.step_number,
|
| 327 |
+
)
|
| 328 |
+
|
| 329 |
+
# For submit actions, use the episode score as the final reward
|
| 330 |
+
if action.action_type == "submit":
|
| 331 |
+
if self.done:
|
| 332 |
+
shaped_reward = self._make_reward(self.episode_score, message, True)
|
| 333 |
+
else:
|
| 334 |
+
shaped_reward = self._make_reward(score, message, False)
|
| 335 |
+
|
| 336 |
return StepResponse(
|
| 337 |
observation=obs,
|
| 338 |
+
reward=shaped_reward,
|
| 339 |
)
|
| 340 |
|
| 341 |
def submit_grader(self, task_id: int | None = None) -> Reward:
|
|
|
|
| 347 |
return StateResponse(
|
| 348 |
task_id=self.current_task_id,
|
| 349 |
step_number=self.step_number,
|
| 350 |
+
max_steps=20,
|
| 351 |
current_script=self.current_script,
|
| 352 |
episode_done=self.done,
|
| 353 |
task_description=self.task_description,
|