Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix]Make sure the args tb_writer passed to the TensorBoardCallback works #13636

Merged

Conversation

iamlockelightning
Copy link
Contributor

What does this PR do?

Add an if check in the on_train_begin function of the TensorBoardCallback, to make sure the args tb_writer passed to the __init__ won't be overwritten.

I wanted to pass a tb_writer to the TensorBoardCallback, so that I could continue using it after training. But the passed tb_writer didn't work.

tb_writer = SummaryWriter(log_dir="some_dir")
cb = TensorBoardCallback(tb_writer)
trainer = Trainer(
    # not important
    callbacks=[cb],
)
trainer.train()
tb_writer.add_scalar("other metrics", 0.99, 0) # didn't work

After checking the code of TensorBoardCallback, I found that the tb_writer passed to the __init__ would be overwritten by the on_train_begin function with a new one no matter what.

By adding an if statement before the init, this bug should be fixed.

if self.tb_writer is None: # check
    self._init_summary_writer(args, log_dir)

Before submitting

Who can review?

@sgugger

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for fixing this!

@sgugger sgugger merged commit fe379f8 into huggingface:master Sep 20, 2021
Albertobegue pushed a commit to Albertobegue/transformers that referenced this pull request Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants