Spaces:
Running
Running
Commit Β·
aa3ea4b
1
Parent(s): 7f988a5
fix: clamp all scores to strict (0,1) open interval for Phase 2 validation
Browse filesFiles changed (4)
- inference.py+9-4
- openenv.yaml+14-11
- server/app.py+4-1
- server/models.py+1-1
18 unmodified lines1920212223242526272829146 unmodified lines1761771781741791801811829 unmodified lines1921931941901951961971987 unmodified lines2062072082042092102112123 unmodified lines21621721821421922022122218 unmodified lines
client = OpenAI(api_key=HF_TOKEN, base_url=API_BASE_URL)
def clamp_reward(r: float) -> float: """Ensure every reward is strictly in the open interval (0, 1).""" return max(0.01, min(0.99, float(r)))
TASK_SYSTEM_PROMPTS = { "precision_assignment": """You are an expert ML infrastructure engineer configuring mixed-precision training.You will be shown ONE layer at a time from a neural network. Assign a precision format to it.146 unmodified lines error = None done = False reward = 0.01 reward = 0.01 # default safe value in (0, 1)
if action is None: action = {}9 unmodified lines step_res = httpx.post(f"{ENV_URL}/step", json={"action": action}) data = step_res.json()
reward = data["reward"]["score"] reward = clamp_reward(data["reward"]["score"]) feedback = data["reward"]["feedback"] done = data["done"] obs = data.get("observation", None)7 unmodified lines done = True error = f"env error: {str(e)}"
rewards_list.append(reward) rewards_list.append(clamp_reward(reward)) action_str = json.dumps(action, default=str).replace('\\n', ' ') error_str = error if error else "null" done_str = str(done).lower()3 unmodified lines if done: break
score = sum(rewards_list) / max(steps, 1) score = clamp_reward(sum(rewards_list) / max(steps, 1)) # Define a simple threshold for success success = score >= 0.70 success_str = str(success).lower()69 unmodified lines70717273747573747576777847 unmodified lines12612712812913012913013113213313450 unmodified lines18518618718718818918818919019119219319459 unmodified lines25425525625525625725725825926026126226369 unmodified lines minimum: 0.01 maximum: 0.99 description: > Per-step reward. 0.0 for catastrophic choices (NaN/underflow). Partial credit for safe but suboptimal choices. 1.0 for the ideal precision given the layer type. Per-step reward in (0.01, 0.99). Catastrophic choices (NaN/underflow) receive 0.01. Partial credit for safe but suboptimal choices. Ideal precision for the layer type scores 0.99.
- id: instability_detection description: >47 unmodified lines minimum: 0.01 maximum: 0.99 description: > Partial reward each step. Penalizes false positives. Rewards early and accurate flagging. Bonus for matching root cause keywords. Partial reward each step in (0.01, 0.99). Penalizes false positives with low scores. Rewards early and accurate flagging. Bonus for matching root cause keywords.
- id: multi_objective_optimization description: >50 unmodified lines minimum: 0.01 maximum: 0.99 description: > 0.0 if any hard constraint is violated. Otherwise scored on how close the solution is to the Pareto-optimal frontier (max efficiency within constraints). Score improves each iteration the agent refines. Score of 0.01 if any hard constraint is violated. Otherwise scored in (0.01, 0.99) based on how close the solution is to the Pareto-optimal frontier (max efficiency within constraints). Score improves each iteration the agent refines.
- id: precision_transfer description: >59 unmodified lines minimum: 0.01 maximum: 0.99 description: > 0.0 if any constraint is violated. Base 0.4 for valid transfer, plus bonuses for efficiency and intelligent adaptation (changing layers that need it rather than blindly copying). Score of 0.01 if any constraint is violated. Base 0.4 for valid transfer, plus bonuses for efficiency and intelligent adaptation (changing layers that need it rather than blindly copying). All scores clamped to (0.01, 0.99).
endpoints: reset:44 unmodified lines454647484950515253515455565744 unmodified linesdef step_environment(payload: dict = {}): action = payload.get("action", payload) result = env.step(action) # Defense-in-depth: clamp score to strict (0, 1) open interval raw_score = result["reward"]["score"] clamped_score = max(0.01, min(0.99, float(raw_score))) return StepResponse( observation=result["observation"], reward=RewardPayload( score=result["reward"]["score"], score=clamped_score, feedback=result["reward"]["feedback"], ), done=result["done"],123 unmodified lines124125126127127128129130123 unmodified lines# Universal Response Models (OpenEnv Spec)# ββββββββββββββββββββββββββββββββββββββββββββββclass RewardPayload(BaseModel): score: float = Field(..., ge=0.0, le=1.0, description="Normalized score 0.0-1.0") score: float = Field(..., gt=0.0, lt=1.0, description="Normalized score strictly in (0, 1)") feedback: str = Field(..., description="Human-readable grading explanation")
inference.py+9-4
openenv.yaml+14-11
server/app.py+4-1
server/models.py+1-1