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.
This commit is contained in:
parent
d892dc6884
commit
bb72c6f129
2 changed files with 26 additions and 6 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue