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 lines192021222324146 unmodified lines1711721731741751761779 unmodified lines1871881891901911921937 unmodified lines2012022032042052062073 unmodified lines21121221321421521621718 unmodified linesclient = OpenAI(api_key=HF_TOKEN, base_url=API_BASE_URL)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 lineserror = Nonedone = Falsereward = 0.01if action is None:action = {}9 unmodified linesstep_res = httpx.post(f"{ENV_URL}/step", json={"action": action})data = step_res.json()reward = data["reward"]["score"]feedback = data["reward"]["feedback"]done = data["done"]obs = data.get("observation", None)7 unmodified linesdone = Trueerror = f"env error: {str(e)}"rewards_list.append(reward)action_str = json.dumps(action, default=str).replace('\\n', ' ')error_str = error if error else "null"done_str = str(done).lower()3 unmodified linesif done:breakscore = sum(rewards_list) / max(steps, 1)# Define a simple threshold for successsuccess = score >= 0.70success_str = str(success).lower()18 unmodified lines1920212223242526272829146 unmodified lines1761771781791801811829 unmodified lines1921931941951961971987 unmodified lines2062072082092102112123 unmodified lines21621721821922022122218 unmodified linesclient = 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 lineserror = Nonedone = Falsereward = 0.01 # default safe value in (0, 1)if action is None:action = {}9 unmodified linesstep_res = httpx.post(f"{ENV_URL}/step", json={"action": action})data = step_res.json()reward = clamp_reward(data["reward"]["score"])feedback = data["reward"]["feedback"]done = data["done"]obs = data.get("observation", None)7 unmodified linesdone = Trueerror = f"env error: {str(e)}"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 linesif done:breakscore = clamp_reward(sum(rewards_list) / max(steps, 1))# Define a simple threshold for successsuccess = score >= 0.70success_str = str(success).lower()
69 unmodified lines70717273747576777847 unmodified lines12612712812913013113213350 unmodified lines18418518618718818919019119259 unmodified lines25225325425525625725825926069 unmodified linesminimum: 0.01maximum: 0.99description: >Per-step reward. 0.0 for catastrophic choices (NaN/underflow). Partialcredit for safe but suboptimal choices. 1.0 for the ideal precision giventhe layer type.- id: instability_detectiondescription: >47 unmodified linesminimum: 0.01maximum: 0.99description: >Partial reward each step. Penalizes false positives. Rewards early andaccurate flagging. Bonus for matching root cause keywords.- id: multi_objective_optimizationdescription: >50 unmodified linesminimum: 0.01maximum: 0.99description: >0.0 if any hard constraint is violated. Otherwise scored on howclose the solution is to the Pareto-optimal frontier (max efficiencywithin constraints). Score improves each iteration the agent refines.- id: precision_transferdescription: >59 unmodified linesminimum: 0.01maximum: 0.99description: >0.0 if any constraint is violated. Base 0.4 for valid transfer, plusbonuses for efficiency and intelligent adaptation (changing layers thatneed it rather than blindly copying).endpoints:reset:69 unmodified lines70717273747576777847 unmodified lines12612712812913013113213313450 unmodified lines18518618718818919019119219319459 unmodified lines25425525625725825926026126226369 unmodified linesminimum: 0.01maximum: 0.99description: >Per-step reward in (0.01, 0.99). Catastrophic choices (NaN/underflow)receive 0.01. Partial credit for safe but suboptimal choices. Idealprecision for the layer type scores 0.99.- id: instability_detectiondescription: >47 unmodified linesminimum: 0.01maximum: 0.99description: >Partial reward each step in (0.01, 0.99). Penalizes false positiveswith low scores. Rewards early and accurate flagging. Bonus formatching root cause keywords.- id: multi_objective_optimizationdescription: >50 unmodified linesminimum: 0.01maximum: 0.99description: >Score of 0.01 if any hard constraint is violated. Otherwise scoredin (0.01, 0.99) based on how close the solution is to thePareto-optimal frontier (max efficiency within constraints). Scoreimproves each iteration the agent refines.- id: precision_transferdescription: >59 unmodified linesminimum: 0.01maximum: 0.99description: >Score of 0.01 if any constraint is violated. Base 0.4 for validtransfer, plus bonuses for efficiency and intelligent adaptation(changing layers that need it rather than blindly copying). Allscores clamped to (0.01, 0.99).endpoints:reset:
44 unmodified lines4546474849505152535444 unmodified linesdef step_environment(payload: dict = {}):action = payload.get("action", payload)result = env.step(action)return StepResponse(observation=result["observation"],reward=RewardPayload(score=result["reward"]["score"],feedback=result["reward"]["feedback"],),done=result["done"],44 unmodified lines4546474849505152535455565744 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 intervalraw_score = result["reward"]["score"]clamped_score = max(0.01, min(0.99, float(raw_score)))return StepResponse(observation=result["observation"],reward=RewardPayload(score=clamped_score,feedback=result["reward"]["feedback"],),done=result["done"],
123 unmodified lines124125126127128129130123 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")feedback: str = Field(..., description="Human-readable grading explanation")123 unmodified lines124125126127128129130123 unmodified lines# Universal Response Models (OpenEnv Spec)# ββββββββββββββββββββββββββββββββββββββββββββββclass RewardPayload(BaseModel):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