From bb72c6f1294b2839751ff31be78bacbc9c0479a5 Mon Sep 17 00:00:00 2001 From: Daniel Hanchen Date: Mon, 9 Feb 2026 15:23:03 +0000 Subject: [PATCH] Silence noisy warnings during SFT training Remove TRL's batch_size=1 padding-free warning from compiled trainer source by detecting and stripping the "anihilate"/"annihilate" warning block. Remove the "Padding-free auto-enabled" print message from trainer.py since the information is already shown in the Unsloth banner. --- unsloth/models/rl.py | 26 ++++++++++++++++++++++++++ unsloth/trainer.py | 6 ------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index 6cb12f6a12..5e6367a04d 100755 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -1357,6 +1357,32 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"): ) RLTrainer_source = RLTrainer_source.replace(_sig_vlm_old, _sig_vlm_new) + # Silence TRL's noisy batch_size=1 + padding-free warning (handles both + # the original "anihilate" typo and the corrected "annihilate" spelling) + for _typo in ("anihilate", "annihilate"): + _idx = RLTrainer_source.find(_typo) + if _idx == -1: + continue + # Walk backwards to find "if args.per_device_train_batch_size" + _block_start = RLTrainer_source.rfind( + "if args.per_device_train_batch_size == 1", 0, _idx + ) + if _block_start == -1: + continue + # Walk backwards to the newline before the if + _line_start = RLTrainer_source.rfind("\n", 0, _block_start) + # Walk forwards past the closing paren to the end of the block + _close = RLTrainer_source.find(")", _idx) + if _close == -1: + continue + _block_end = RLTrainer_source.find("\n", _close) + if _block_end == -1: + continue + RLTrainer_source = ( + RLTrainer_source[:_line_start] + RLTrainer_source[_block_end:] + ) + break + # Remove multiple doc strings if __RLConfig_doc__ != "" and RLTrainer_source.count(__RLTrainer_doc__) == 2: RLTrainer_source = RLTrainer_source.replace(__RLTrainer_doc__, "", 1) diff --git a/unsloth/trainer.py b/unsloth/trainer.py index cb36b8639d..54addba5d3 100644 --- a/unsloth/trainer.py +++ b/unsloth/trainer.py @@ -440,12 +440,6 @@ def _patch_sft_trainer_auto_packing(trl_module): ) elif not blocked and trainer_padding_free: enable_padding_free_metadata(self.model, self) - message = ( - "🦥 Unsloth: Padding-free auto-enabled, enabling faster training." - if auto_padding_free_active - else "🦥 Unsloth: Padding-free enabled, enabling faster training." - ) - print(message) sft_trainer.__init__ = new_init sft_trainer._unsloth_auto_packing_wrapped = True