minimind/trainer
tkgcc 0f6803e551 [fix] replace tool eval() with an AST math evaluator
execute_tool() relied on signal.SIGALRM, which does not exist on Windows.
The AttributeError was swallowed by a bare except, so every tool call
silently returned None and the model always observed
{"error": "tool not found"} (issue #846).

calculate_math also ran eval() on model-generated text. Two of the three
call sites (scripts/eval_toolcall.py, scripts/web_demo.py) passed no
globals at all, leaving full builtins reachable from sampled output.

safe_math_eval() in trainer_utils.py parses the expression with ast and
walks it, allowing only arithmetic operators and a math whitelist, with
caps on expression length and exponent size. It cannot loop forever, so
the signal-based timeout is no longer needed and is removed. Both sqrt(x)
and math.sqrt(x) spellings keep working.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-07 07:53:33 +08:00
..
rollout_engine.py [fix] inference bug 2026-05-03 20:48:48 +08:00
train_agent.py [fix] replace tool eval() with an AST math evaluator 2026-09-07 07:53:33 +08:00
train_distillation.py [fix] ddp exit hang 2026-06-01 17:50:39 +08:00
train_dpo.py [fix] ddp exit hang 2026-06-01 17:50:39 +08:00
train_full_sft.py [update] remove expert args 2026-09-04 22:16:38 +08:00
train_grpo.py [fix] ddp exit hang 2026-06-01 17:50:39 +08:00
train_lora.py [fix] ddp exit hang 2026-06-01 17:50:39 +08:00
train_ppo.py [refactor] PPO cleanup 2026-07-23 11:11:05 +08:00
train_pretrain.py [update] remove expert args 2026-09-04 22:16:38 +08:00
train_tokenizer.py [update] minimind-3 2026-03-25 23:57:45 +08:00
trainer_utils.py [fix] replace tool eval() with an AST math evaluator 2026-09-07 07:53:33 +08:00