vanishingradient commited on
Commit
0ecc38b
·
verified ·
1 Parent(s): 8e4528c

Force first tool + tool_choice required nudge

Browse files
Files changed (1) hide show
  1. kaggle/train_grpo.py +40 -2
kaggle/train_grpo.py CHANGED
@@ -383,8 +383,33 @@ def run_heldout_agent_eval(
383
  final_text = completion
384
  messages.append({"role": "assistant", "content": completion})
385
  if not calls:
386
- _vlog("heldout_eval.stop_no_tools", task_id=task_id, turn=turn)
387
- break
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
388
  for call in calls:
389
  _vlog(
390
  "heldout_eval.tool_dispatch",
@@ -1314,6 +1339,12 @@ def main(cfg: Cfg | None = None) -> None:
1314
  step=0,
1315
  )
1316
 
 
 
 
 
 
 
1317
  args = GRPOConfig(
1318
  output_dir=output_dir,
1319
  run_name="kaggle-grpo-swe",
@@ -1336,6 +1367,13 @@ def main(cfg: Cfg | None = None) -> None:
1336
  hub_model_id=cfg.hub_model_id,
1337
  hub_token=os.environ["HF_TOKEN"],
1338
  push_to_hub=False,
 
 
 
 
 
 
 
1339
  )
1340
 
1341
  cb = make_eval_before_save_callback(
 
383
  final_text = completion
384
  messages.append({"role": "assistant", "content": completion})
385
  if not calls:
386
+ # Force-first-tool: if the model refuses tools on early turns, inject ls(".")
387
+ # so the episode can continue and shaped rewards can differentiate.
388
+ force = os.getenv("DARL_FORCE_FIRST_TOOL", "1").strip() not in (
389
+ "0",
390
+ "false",
391
+ "no",
392
+ )
393
+ if force and turn < 2:
394
+ _vlog(
395
+ "heldout_eval.force_first_tool",
396
+ task_id=task_id,
397
+ turn=turn,
398
+ tool="ls",
399
+ )
400
+ calls = [{"name": "ls", "arguments": {"path": "."}}]
401
+ messages.append(
402
+ {
403
+ "role": "assistant",
404
+ "content": (
405
+ "(system) No tool call detected — forcing ls(path='.') "
406
+ "so you can continue with real paths."
407
+ ),
408
+ }
409
+ )
410
+ else:
411
+ _vlog("heldout_eval.stop_no_tools", task_id=task_id, turn=turn)
412
+ break
413
  for call in calls:
414
  _vlog(
415
  "heldout_eval.tool_dispatch",
 
1339
  step=0,
1340
  )
1341
 
1342
+ # Nudge Qwen chat template toward required tool calls when supported.
1343
+ chat_kwargs: dict[str, Any] = {"tool_choice": "required"}
1344
+ gen_kwargs: dict[str, Any] = {
1345
+ "temperature": float(os.getenv("DARL_GEN_TEMPERATURE", "0.8")),
1346
+ "top_p": 0.95,
1347
+ }
1348
  args = GRPOConfig(
1349
  output_dir=output_dir,
1350
  run_name="kaggle-grpo-swe",
 
1367
  hub_model_id=cfg.hub_model_id,
1368
  hub_token=os.environ["HF_TOKEN"],
1369
  push_to_hub=False,
1370
+ chat_template_kwargs=chat_kwargs,
1371
+ generation_kwargs=gen_kwargs,
1372
+ )
1373
+ _vlog(
1374
+ "main.grpo_config_tool_nudge",
1375
+ chat_template_kwargs=chat_kwargs,
1376
+ generation_kwargs=gen_kwargs,
1377
  )
1378
 
1379
  cb = make_eval_before_save_callback(