Skip to content

Instantly share code, notes, and snippets.

@wassname
Last active January 27, 2025 02:08
Show Gist options
  • Save wassname/c3e1d00b21e9fa6d6bce96ff7263eafb to your computer and use it in GitHub Desktop.
Save wassname/c3e1d00b21e9fa6d6bce96ff7263eafb to your computer and use it in GitHub Desktop.
transformers stop the printing, while still logging to wandb, tensorboard, csv etc
from transformers.trainer_callback import ProgressCallback
class ProgressCallbackNoPrint(ProgressCallback):
"""ProgressCallback that doesn't print anything
Usage:
# at top of file, after transformers import, before settin up trainer, monkey patch the default progress callback
import transformers
transformers.DEFAULT_PROGRESS_CALLBACK = ProgressCallbackNoPrint
# OR you can do it this way
trainer = Trainer(
...,
logging_steps=1,
callbacks=[ProgressCallbackNoPrint()]
)
rm_old_prog_cb(trainer)
trainer.train()
@url: https://gist.github.com/wassname/c3e1d00b21e9fa6d6bce96ff7263eafb
"""
def on_log(self, *args, **kwargs):
pass
def rm_old_prog_cb(trainer):
for cb in trainer.callback_handler.callbacks:
if isinstance(cb, ProgressCallback):
if not isinstance(cb, ProgressCallbackNoPrint):
trainer.remove_callback(cb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment