Commit ·
1f18d1f
1
Parent(s): d3b81d6
Swap grader weights: hospital=45% primary constraint, containment=30%, calibrate environment
Browse files- .env +4 -0
- baseline/__pycache__/__init__.cpython-313.pyc +0 -0
- baseline/__pycache__/evaluator.cpython-313.pyc +0 -0
- baseline/__pycache__/policy.cpython-313.pyc +0 -0
- baseline/evaluator.py +11 -5
- core/__pycache__/__init__.cpython-313.pyc +0 -0
- core/__pycache__/policy_update.cpython-313.pyc +0 -0
- core/__pycache__/reward.cpython-313.pyc +0 -0
- core/__pycache__/trajectory.cpython-313.pyc +0 -0
- core/policy_update.py +1 -1
- core/reward.py +8 -10
- core/trajectory.py +1 -1
- server/__pycache__/__init__.cpython-313.pyc +0 -0
- server/__pycache__/app.cpython-313.pyc +0 -0
- server/__pycache__/constants.cpython-313.pyc +0 -0
- server/__pycache__/environment.cpython-313.pyc +0 -0
- server/__pycache__/grader.cpython-313.pyc +0 -0
- server/__pycache__/utils.cpython-313.pyc +0 -0
- server/grader.py +2 -2
- server/tasks/__pycache__/__init__.cpython-313.pyc +0 -0
- server/tasks/__pycache__/base.cpython-313.pyc +0 -0
- server/tasks/__pycache__/registry.cpython-313.pyc +0 -0
- server/tasks/__pycache__/task_easy.cpython-313.pyc +0 -0
- server/tasks/__pycache__/task_hard.cpython-313.pyc +0 -0
- server/tasks/__pycache__/task_medium.cpython-313.pyc +0 -0
- structure.txt +0 -0
.env
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
HF_TOKEN=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
|
| 2 |
+
API_BASE_URL=https://api.groq.com/openai/v1
|
| 3 |
+
MODEL_NAME=llama-3.1-8b-instant
|
| 4 |
+
ENV_BASE_URL=https://therubberduckdebuggers-cascade-containment.hf.space
|
baseline/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (206 Bytes). View file
|
|
|
baseline/__pycache__/evaluator.cpython-313.pyc
ADDED
|
Binary file (10.6 kB). View file
|
|
|
baseline/__pycache__/policy.cpython-313.pyc
ADDED
|
Binary file (7.29 kB). View file
|
|
|
baseline/evaluator.py
CHANGED
|
@@ -125,7 +125,7 @@ def run_task_grpo(
|
|
| 125 |
|
| 126 |
total_reward, steps, trajectory = run_rollout(env, task_name, client, memory, verbose)
|
| 127 |
|
| 128 |
-
#
|
| 129 |
num_districts = {"easy": 2, "medium": 4, "hard": 6}.get(task_name, 2)
|
| 130 |
try:
|
| 131 |
grade_resp = http_requests.get(
|
|
@@ -146,20 +146,26 @@ def run_task_grpo(
|
|
| 146 |
except Exception:
|
| 147 |
score = normalise_score(total_reward, steps, num_districts)
|
| 148 |
|
| 149 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
completed_rewards = [r[0] for r in rollouts]
|
| 151 |
advantage = compute_advantage(total_reward, completed_rewards[:-1])
|
| 152 |
stored = update_memory(memory, trajectory, advantage)
|
| 153 |
|
| 154 |
if verbose:
|
| 155 |
mean = sum(completed_rewards[:-1]) / max(len(completed_rewards) - 1, 1) \
|
| 156 |
-
|
| 157 |
print(f" → Advantage: {advantage:+.4f} | "
|
| 158 |
-
|
| 159 |
|
| 160 |
all_rewards = [r[0] for r in rollouts]
|
| 161 |
mean_reward = sum(all_rewards) / len(all_rewards)
|
| 162 |
-
best_score
|
| 163 |
|
| 164 |
if verbose:
|
| 165 |
print(f"\n Rewards: {[round(r, 4) for r in all_rewards]}")
|
|
|
|
| 125 |
|
| 126 |
total_reward, steps, trajectory = run_rollout(env, task_name, client, memory, verbose)
|
| 127 |
|
| 128 |
+
# Get proper grader score from server
|
| 129 |
num_districts = {"easy": 2, "medium": 4, "hard": 6}.get(task_name, 2)
|
| 130 |
try:
|
| 131 |
grade_resp = http_requests.get(
|
|
|
|
| 146 |
except Exception:
|
| 147 |
score = normalise_score(total_reward, steps, num_districts)
|
| 148 |
|
| 149 |
+
# Append BEFORE advantage computation
|
| 150 |
+
rollouts.append((total_reward, steps, score))
|
| 151 |
+
|
| 152 |
+
if verbose:
|
| 153 |
+
print(f" → Reward: {total_reward:+.4f} | Score: {score:.4f}")
|
| 154 |
+
|
| 155 |
+
# ── GRPO advantage computation and memory update ──────────────────────
|
| 156 |
completed_rewards = [r[0] for r in rollouts]
|
| 157 |
advantage = compute_advantage(total_reward, completed_rewards[:-1])
|
| 158 |
stored = update_memory(memory, trajectory, advantage)
|
| 159 |
|
| 160 |
if verbose:
|
| 161 |
mean = sum(completed_rewards[:-1]) / max(len(completed_rewards) - 1, 1) \
|
| 162 |
+
if len(completed_rewards) > 1 else total_reward
|
| 163 |
print(f" → Advantage: {advantage:+.4f} | "
|
| 164 |
+
+ (f"↑ Stored {stored} steps" if stored > 0 else "↓ Suppressed"))
|
| 165 |
|
| 166 |
all_rewards = [r[0] for r in rollouts]
|
| 167 |
mean_reward = sum(all_rewards) / len(all_rewards)
|
| 168 |
+
best_score = max(rollouts, key=lambda x: x[2])[2]
|
| 169 |
|
| 170 |
if verbose:
|
| 171 |
print(f"\n Rewards: {[round(r, 4) for r in all_rewards]}")
|
core/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (198 Bytes). View file
|
|
|
core/__pycache__/policy_update.cpython-313.pyc
ADDED
|
Binary file (2.13 kB). View file
|
|
|
core/__pycache__/reward.cpython-313.pyc
ADDED
|
Binary file (1.01 kB). View file
|
|
|
core/__pycache__/trajectory.cpython-313.pyc
ADDED
|
Binary file (4.82 kB). View file
|
|
|
core/policy_update.py
CHANGED
|
@@ -32,7 +32,7 @@ def should_reinforce(advantage: float) -> bool:
|
|
| 32 |
Reinforce if advantage >= 0 (at or above mean).
|
| 33 |
Suppress if below mean.
|
| 34 |
"""
|
| 35 |
-
return advantage >
|
| 36 |
|
| 37 |
|
| 38 |
def update_memory(
|
|
|
|
| 32 |
Reinforce if advantage >= 0 (at or above mean).
|
| 33 |
Suppress if below mean.
|
| 34 |
"""
|
| 35 |
+
return advantage > -0.5 # allow small negative margin to encourage exploration
|
| 36 |
|
| 37 |
|
| 38 |
def update_memory(
|
core/reward.py
CHANGED
|
@@ -5,16 +5,14 @@
|
|
| 5 |
|
| 6 |
import math
|
| 7 |
|
| 8 |
-
|
| 9 |
-
def normalise_score(total_reward: float, steps: int) -> float:
|
| 10 |
"""
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
Average reward of 0 → 0.5
|
| 15 |
-
Positive average → above 0.5
|
| 16 |
-
Negative average → below 0.5
|
| 17 |
"""
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
| 20 |
return round(min(1.0, max(0.0, score)), 4)
|
|
|
|
| 5 |
|
| 6 |
import math
|
| 7 |
|
| 8 |
+
def normalise_score(total_reward: float, steps: int, num_districts: int = 2) -> float:
|
|
|
|
| 9 |
"""
|
| 10 |
+
Linear normalization with task-aware worst case.
|
| 11 |
+
Worst case per step = num_districts × (-0.5 infection) + num_districts × (-1.0 breach)
|
| 12 |
+
Best case per step = num_districts × (+0.5 containment) + 0.30 prioritisation
|
|
|
|
|
|
|
|
|
|
| 13 |
"""
|
| 14 |
+
avg = total_reward / max(steps, 1)
|
| 15 |
+
worst = num_districts * (-1.5) # -0.5 infection + -1.0 breach per district
|
| 16 |
+
best = num_districts * (0.5) + 0.3
|
| 17 |
+
score = (avg - worst) / (best - worst)
|
| 18 |
return round(min(1.0, max(0.0, score)), 4)
|
core/trajectory.py
CHANGED
|
@@ -29,7 +29,7 @@ class EpisodicMemory:
|
|
| 29 |
|
| 30 |
def store(self, obs: CityObservation, action: ContainmentAction, reward: float):
|
| 31 |
"""Store a step only if it earned positive reward."""
|
| 32 |
-
if reward <
|
| 33 |
return
|
| 34 |
|
| 35 |
self.memories.append({
|
|
|
|
| 29 |
|
| 30 |
def store(self, obs: CityObservation, action: ContainmentAction, reward: float):
|
| 31 |
"""Store a step only if it earned positive reward."""
|
| 32 |
+
if reward < -0.3:
|
| 33 |
return
|
| 34 |
|
| 35 |
self.memories.append({
|
server/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (211 Bytes). View file
|
|
|
server/__pycache__/app.cpython-313.pyc
ADDED
|
Binary file (715 Bytes). View file
|
|
|
server/__pycache__/constants.cpython-313.pyc
ADDED
|
Binary file (1.34 kB). View file
|
|
|
server/__pycache__/environment.cpython-313.pyc
ADDED
|
Binary file (12.9 kB). View file
|
|
|
server/__pycache__/grader.cpython-313.pyc
ADDED
|
Binary file (5.54 kB). View file
|
|
|
server/__pycache__/utils.cpython-313.pyc
ADDED
|
Binary file (9.26 kB). View file
|
|
|
server/grader.py
CHANGED
|
@@ -172,8 +172,8 @@ def grade_trajectory(
|
|
| 172 |
# speed = tiebreaker
|
| 173 |
|
| 174 |
final_score = (
|
| 175 |
-
containment_score * 0.
|
| 176 |
-
hospital_score * 0.
|
| 177 |
efficiency_score * 0.15 +
|
| 178 |
speed_score * 0.10
|
| 179 |
)
|
|
|
|
| 172 |
# speed = tiebreaker
|
| 173 |
|
| 174 |
final_score = (
|
| 175 |
+
containment_score * 0.30 +
|
| 176 |
+
hospital_score * 0.45 +
|
| 177 |
efficiency_score * 0.15 +
|
| 178 |
speed_score * 0.10
|
| 179 |
)
|
server/tasks/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (217 Bytes). View file
|
|
|
server/tasks/__pycache__/base.cpython-313.pyc
ADDED
|
Binary file (1.63 kB). View file
|
|
|
server/tasks/__pycache__/registry.cpython-313.pyc
ADDED
|
Binary file (1.7 kB). View file
|
|
|
server/tasks/__pycache__/task_easy.cpython-313.pyc
ADDED
|
Binary file (1.93 kB). View file
|
|
|
server/tasks/__pycache__/task_hard.cpython-313.pyc
ADDED
|
Binary file (2.07 kB). View file
|
|
|
server/tasks/__pycache__/task_medium.cpython-313.pyc
ADDED
|
Binary file (1.95 kB). View file
|
|
|
structure.txt
DELETED
|
Binary file (2.86 kB)
|
|
|