yashash04 commited on
Commit
5a432bb
·
1 Parent(s): cf4ce7e

Phase 13 Stage 1 v2: fix termination signal - reward penalties for non-termination, reduced max_tokens, stop_strings

Browse files
Files changed (1) hide show
  1. training/grpo_kaggle.ipynb +28 -11
training/grpo_kaggle.ipynb CHANGED
@@ -160,19 +160,30 @@
160
  "\n",
161
  "\n",
162
  "# --- ACCOUNT 1 (Yashash - STAGE 1 MAIN): shaped_total (rubric + dense + gates) ---\n",
 
163
  "def reward_fn(prompts, completions, **kwargs):\n",
164
  " rewards = []\n",
165
- " for prompt, completion in zip(prompts, completions):\n",
 
 
166
  " actions = parse_completion_to_actions(completion)\n",
167
- " task_id = kwargs.get(\"task_id\", \"E1_onboard_new_hire\")\n",
168
- " env_client.reset(task_id)\n",
169
- " total = 0.0\n",
170
- " for a in actions:\n",
171
- " obs, r = env_client.step(a)\n",
172
- " total += r.shaped_total\n",
173
- " if obs.done:\n",
174
- " break\n",
175
- " rewards.append(total)\n",
 
 
 
 
 
 
 
 
176
  " return rewards\n",
177
  "\n",
178
  "\n",
@@ -282,6 +293,11 @@
282
  "- report_drift(tool, drift_kind, description) - flag a drift you detected\n",
283
  "- complete_task(summary) - end the episode\n",
284
  "\n",
 
 
 
 
 
285
  "Output your next action as JSON. Example:\n",
286
  "{{\"type\": \"call_tool\", \"tool_call\": {{\"tool\": \"mail\", \"endpoint\": \"send_message\", \"params\": {{\"to\": \"x@y.com\", \"subject\": \"Hi\", \"body\": \"Hello\"}}}}}}\n",
287
  "\"\"\"\n",
@@ -312,7 +328,8 @@
312
  "config = GRPOConfig(\n",
313
  " output_dir=\"schemashift-grpo-kaggle\",\n",
314
  " num_generations=4,\n",
315
- " max_completion_length=1024,\n",
 
316
  " per_device_train_batch_size=1,\n",
317
  " gradient_accumulation_steps=4,\n",
318
  " learning_rate=5e-6,\n",
 
160
  "\n",
161
  "\n",
162
  "# --- ACCOUNT 1 (Yashash - STAGE 1 MAIN): shaped_total (rubric + dense + gates) ---\n",
163
+ "# v2: termination signal — penalize rambling completions that don't reach done via complete_task.\n",
164
  "def reward_fn(prompts, completions, **kwargs):\n",
165
  " rewards = []\n",
166
+ " task_ids = kwargs.get(\"task_id\", None)\n",
167
+ " for i, (prompt, completion) in enumerate(zip(prompts, completions)):\n",
168
+ " task_id = task_ids[i] if isinstance(task_ids, list) else task_ids or \"E1_onboard_new_hire\"\n",
169
  " actions = parse_completion_to_actions(completion)\n",
170
+ " try:\n",
171
+ " env_client.reset(task_id)\n",
172
+ " total = 0.0\n",
173
+ " obs = None\n",
174
+ " for a in actions:\n",
175
+ " obs, r = env_client.step(a)\n",
176
+ " total += r.shaped_total\n",
177
+ " if obs.done:\n",
178
+ " break\n",
179
+ " # Termination penalty: episodes that didn't reach done via complete_task\n",
180
+ " # (rambled past step budget OR model never emitted complete_task).\n",
181
+ " if obs is None or not obs.done:\n",
182
+ " total -= 0.5\n",
183
+ " rewards.append(total)\n",
184
+ " except Exception as e:\n",
185
+ " print(f\" [reward_fn] task={task_id} failed: {type(e).__name__}: {e}\")\n",
186
+ " rewards.append(-0.5) # v2: was 0.0; penalize API/parse failures harder\n",
187
  " return rewards\n",
188
  "\n",
189
  "\n",
 
293
  "- report_drift(tool, drift_kind, description) - flag a drift you detected\n",
294
  "- complete_task(summary) - end the episode\n",
295
  "\n",
296
+ "CRITICAL OUTPUT RULES:\n",
297
+ "- Output ONLY JSON action objects. No commentary, no reasoning text, no markdown fences.\n",
298
+ "- Be concise. Each action is a single JSON object on its own.\n",
299
+ "- End the episode with a complete_task action. Do not output anything after complete_task.\n",
300
+ "\n",
301
  "Output your next action as JSON. Example:\n",
302
  "{{\"type\": \"call_tool\", \"tool_call\": {{\"tool\": \"mail\", \"endpoint\": \"send_message\", \"params\": {{\"to\": \"x@y.com\", \"subject\": \"Hi\", \"body\": \"Hello\"}}}}}}\n",
303
  "\"\"\"\n",
 
328
  "config = GRPOConfig(\n",
329
  " output_dir=\"schemashift-grpo-kaggle\",\n",
330
  " num_generations=4,\n",
331
+ " max_completion_length=512, # v2: was 1024 — tighter window forces the model to commit\n",
332
+ " stop_strings=[\"complete_task\"], # v2: halt generation once the model decides to complete\n",
333
  " per_device_train_batch_size=1,\n",
334
  " gradient_accumulation_steps=4,\n",
335
  " learning_rate=5e-6,\n",