Skip to content

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
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.

2 participants