div18 commited on
Commit
faa8a6b
·
1 Parent(s): 9db539d

reward tuning

Browse files
inference.py CHANGED
@@ -52,10 +52,10 @@ MAX_TOKENS = int(os.getenv("ANTIATROPOS_MAX_TOKENS", "180"))
52
  SEED = int(os.getenv("ANTIATROPOS_SEED", "42"))
53
  SUCCESS_SCORE_THRESHOLD = float(os.getenv("ANTIATROPOS_SUCCESS_THRESHOLD", "0.55"))
54
  EVAL_RUNS = int(os.getenv("ANTIATROPOS_EVAL_RUNS", "3")) # Num eval runs per task
55
- TEMPERATURE_SWEEP = [0.7, 0.3, 0.7] # Fixed temperatures for multi-episode eval
56
 
57
  TASK_BRIEFS: Dict[str, str] = {
58
- "task-1": "Traffic increases linearly. Scale proactively to keep latency low and cost efficient.",
59
  "task-2": "A node fails randomly. Detect quickly and recover with reroute/scale actions.",
60
  "task-3": "Protect VIP node-0 under surges. Keep VIP healthy without invalid actions.",
61
  }
@@ -63,8 +63,21 @@ TASK_BRIEFS: Dict[str, str] = {
63
  SYSTEM_PROMPT = textwrap.dedent(
64
  """
65
  You are an autonomous SRE controller managing a five-node microservice cluster.
66
- node-0 is the payment gateway (higher business priority, receives 2x reward weight).
67
- Balance protection of node-0 with the health of all other nodes — do not ignore nodes 1-4.
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  Return exactly one JSON object:
70
  {
@@ -162,11 +175,22 @@ def build_user_prompt(task_id: str, step: int, obs: dict, history: List[str], de
162
  recent = "\n".join(history[-4:]) if history else "None"
163
  brief = TASK_BRIEFS.get(task_id, "Maintain SLA, stability, and efficient cost.")
164
  demo_section = f"\n\n{demo_text}" if demo_text else ""
 
 
 
 
 
 
 
 
 
 
165
  return textwrap.dedent(
166
  f"""
167
  Task: {task_id}
168
  Objective: {brief}
169
  Step: {step}
 
170
 
171
  Current state:
172
  {json.dumps(obs, separators=(",", ":"))}
@@ -183,26 +207,23 @@ def observation_for_model(obs) -> dict:
183
  """
184
  Build a compact observation dict for the LLM.
185
 
186
- IMPORTANT: is_vip and importance_weight are deliberately EXCLUDED.
187
- The LLM must learn which nodes matter from rewards alone, not from
188
- explicit bias signals in the observation. Including these fields
189
- caused the model to fixate on node-0 and ignore nodes 1-4.
 
190
  """
191
  return {
192
  "task_id": obs.task_id,
193
  "mode": getattr(obs.mode, "value", str(obs.mode)),
194
  "step": obs.step,
195
  "max_steps": obs.max_steps,
196
- "lyapunov_energy": obs.lyapunov_energy,
197
  "average_latency_ms": obs.average_latency_ms,
198
  "error_rate": obs.error_rate,
199
  "total_queue_backlog": obs.total_queue_backlog,
 
200
  "sla_violations": obs.sla_violations,
201
  "invalid_action_count": obs.invalid_action_count,
202
- "reward_drift": getattr(obs, "reward_drift", 0.0),
203
- "reward_cost": getattr(obs, "reward_cost", 0.0),
204
- "reward_sla": getattr(obs, "reward_sla", 0.0),
205
- "reward_barrier": getattr(obs, "reward_barrier", 0.0),
206
  "nodes": [
207
  {
208
  "node_id": node.node_id,
@@ -214,8 +235,6 @@ def observation_for_model(obs) -> dict:
214
  "capacity": getattr(node, "capacity", 0.0),
215
  "pending_capacity": getattr(node, "pending_capacity", 0.0),
216
  "queue_delta": getattr(node, "queue_delta", 0.0),
217
- "sla_proximity": getattr(node, "sla_proximity", 0.0),
218
- "node_reward": getattr(node, "node_reward", 0.0),
219
  }
220
  for node in obs.nodes
221
  ],
 
52
  SEED = int(os.getenv("ANTIATROPOS_SEED", "42"))
53
  SUCCESS_SCORE_THRESHOLD = float(os.getenv("ANTIATROPOS_SUCCESS_THRESHOLD", "0.55"))
54
  EVAL_RUNS = int(os.getenv("ANTIATROPOS_EVAL_RUNS", "3")) # Num eval runs per task
55
+ TEMPERATURE_SWEEP = [0.6, 0.3, 0.7] # Fixed temperatures for multi-episode eval
56
 
57
  TASK_BRIEFS: Dict[str, str] = {
58
+ "task-1": "Traffic ramps linearly every tick. Scale up proactively — new capacity takes 5 ticks to boot. Keep latency under SLA (200ms) while minimizing cost. Scale down when queues are safe.",
59
  "task-2": "A node fails randomly. Detect quickly and recover with reroute/scale actions.",
60
  "task-3": "Protect VIP node-0 under surges. Keep VIP healthy without invalid actions.",
61
  }
 
63
  SYSTEM_PROMPT = textwrap.dedent(
64
  """
65
  You are an autonomous SRE controller managing a five-node microservice cluster.
66
+
67
+ ACTIONS (new capacity takes 5 ticks to boot):
68
+ SCALE_UP <node> <amount:0-1> — add capacity, clears DEGRADED status
69
+ SCALE_DOWN <node> <amount:0-1> — remove capacity (min 1 unit)
70
+ REROUTE_TRAFFIC <node> <fraction:0-1> — offload traffic to healthy peers
71
+ SHED_LOAD <node> <fraction:0-1> — drop incoming traffic (NOT on critical nodes)
72
+ NO_OP — do nothing
73
+
74
+ REWARD PRIORITIES (in order):
75
+ 1. Avoid SLA violations (latency > 200ms or error rate > 5%)
76
+ 2. Keep queues low (growing queues = destabilizing system)
77
+ 3. Don't over-provision (excess capacity costs money)
78
+
79
+ SCALE PROACTIVELY — boot delay means reactive scaling arrives too late.
80
+ Scale back down when safe to save cost.
81
 
82
  Return exactly one JSON object:
83
  {
 
175
  recent = "\n".join(history[-4:]) if history else "None"
176
  brief = TASK_BRIEFS.get(task_id, "Maintain SLA, stability, and efficient cost.")
177
  demo_section = f"\n\n{demo_text}" if demo_text else ""
178
+
179
+ # Synthesize a 1-line cluster summary from the most important signals
180
+ cost_hour = obs.get("current_cost_per_hour", 0.0)
181
+ cost_dev = "low" if cost_hour < 1.2 else ("high" if cost_hour > 1.8 else "baseline")
182
+ queue_backlog = obs.get("total_queue_backlog", 0.0)
183
+ queue_trend = "rising" if queue_backlog > 0.3 else ("stable" if queue_backlog < 0.1 else "moderate")
184
+ sla_violations = obs.get("sla_violations", 0)
185
+ sla_note = f" ({sla_violations} violations)" if sla_violations > 0 else ""
186
+ cluster_summary = f"Cost: {cost_dev} (${cost_hour:.2f}/hr) | Queues: {queue_trend}{sla_note}"
187
+
188
  return textwrap.dedent(
189
  f"""
190
  Task: {task_id}
191
  Objective: {brief}
192
  Step: {step}
193
+ Status: {cluster_summary}
194
 
195
  Current state:
196
  {json.dumps(obs, separators=(",", ":"))}
 
207
  """
208
  Build a compact observation dict for the LLM.
209
 
210
+ DESIGN: only raw physical metrics a human SRE sees on their dashboard.
211
+ Reward decomposition and pre-digested scoring signals are EXCLUDED —
212
+ the LLM must reason from physics, not reverse-engineer the scorer.
213
+
214
+ The scalar reward for past steps is already in the history (correct).
215
  """
216
  return {
217
  "task_id": obs.task_id,
218
  "mode": getattr(obs.mode, "value", str(obs.mode)),
219
  "step": obs.step,
220
  "max_steps": obs.max_steps,
 
221
  "average_latency_ms": obs.average_latency_ms,
222
  "error_rate": obs.error_rate,
223
  "total_queue_backlog": obs.total_queue_backlog,
224
+ "current_cost_per_hour": getattr(obs, "current_cost_per_hour", 0.0),
225
  "sla_violations": obs.sla_violations,
226
  "invalid_action_count": obs.invalid_action_count,
 
 
 
 
227
  "nodes": [
228
  {
229
  "node_id": node.node_id,
 
235
  "capacity": getattr(node, "capacity", 0.0),
236
  "pending_capacity": getattr(node, "pending_capacity", 0.0),
237
  "queue_delta": getattr(node, "queue_delta", 0.0),
 
 
238
  }
239
  for node in obs.nodes
240
  ],
server/AntiAtropos_environment.py CHANGED
@@ -43,10 +43,10 @@ except ImportError:
43
  # Reward hyper-parameters (synchronized with stability.py constants)
44
  # ---------------------------------------------------------------------------
45
 
46
- ALPHA: float = 0.002 # Weight on Lyapunov energy drift DeltaV(s) (Increased for faster feedback)
47
- BETA: float = 0.01 # Weight on infrastructure cost (Reduced to prevent cheap-but-dead strategies)
48
- GAMMA: float = 10.0 # Weight on per-step SLA violation indicator (Increased to force reactive scaling)
49
- DELTA: float = 0.005 # Weight on control-barrier function penalty (queue safety zone)
50
 
51
  MAX_QUEUE_NORM = 200.0
52
  MAX_LATENCY_NORM = 1000.0
 
43
  # Reward hyper-parameters (synchronized with stability.py constants)
44
  # ---------------------------------------------------------------------------
45
 
46
+ ALPHA: float = 0.002 # Weight on Lyapunov energy drift DeltaV(s)
47
+ BETA: float = 0.3 # Weight on infrastructure cost (increased so cost signal is visible)
48
+ GAMMA: float = 6.0 # Weight on per-step SLA violation indicator (dominant but not overwhelming)
49
+ DELTA: float = 0.1 # Weight on control-barrier function penalty (queue safety zone)
50
 
51
  MAX_QUEUE_NORM = 200.0
52
  MAX_LATENCY_NORM = 1000.0
training/trainer.py CHANGED
@@ -142,7 +142,7 @@ class MockPolicyModel:
142
  MAX_QUEUE_NORM = 200.0
143
  MAX_LATENCY_NORM = 1000.0
144
  MAX_REQUEST_RATE_NORM = 100.0
145
- ALPHA, BETA, GAMMA, DELTA = 0.002, 0.01, 10.0, 0.005
146
 
147
 
148
  def format_observation(nodes: List[dict], task_id: str, step: int, max_steps: int) -> str:
 
142
  MAX_QUEUE_NORM = 200.0
143
  MAX_LATENCY_NORM = 1000.0
144
  MAX_REQUEST_RATE_NORM = 100.0
145
+ ALPHA, BETA, GAMMA, DELTA = 0.002, 0.3, 6.0, 0.1
146
 
147
 
148
  def format_observation(nodes: List[dict], task_id: str, step: int, max_steps: int) -> str: