From fc63b7ec4d2d7ba50dcf641503482f641779f78d Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Sun, 1 Mar 2026 00:42:37 -0800 Subject: [PATCH] rl: guard warnings_issued before TRL estimate_tokens write (#4034) Co-authored-by: Daniel Hanchen --- unsloth/models/rl.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index fbb32b2c50..eb5d4be171 100755 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -810,6 +810,18 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"): " os.environ['UNSLOTH_RETURN_LOGITS'] = '1'\n" ) extra_args += logits_check + warnings_issued_check = ( + "if model is not None:\n" + " _warnings_issued = getattr(model, 'warnings_issued', None)\n" + " if _warnings_issued is None:\n" + " model.warnings_issued = {}\n" + " elif not isinstance(_warnings_issued, dict):\n" + " try:\n" + " model.warnings_issued = dict(_warnings_issued)\n" + " except Exception:\n" + " model.warnings_issued = {}\n" + ) + extra_args += warnings_issued_check # Check max_seq_length if "model" in call_args: