Pere-Lluis Huguet
Pere-Lluis Huguet

Reputation: 419

add_graph working and printing result on Verbose but not saving on log file

When using the tensorboard in utils with the new Pytorch 1.2, the add_graph function, the graph is not added to the tensorboard log file. If I log an scalar before calling the add_graph it gets logged, but anything I add after doesn't.

I won't be able to provide the whole model here, it uses LSTMs and Attention but nothing too fancy. The snippet where I call add_graph:

    from torch.utils.tensorboard import SummaryWriter

    w = SummaryWriter('./runs/jointmodel')

    dummy_input = torch.Tensor(torch.rand(2, 10, 1024))
    w.add_scalar('log', 10, 1)
    w.add_graph(model, dummy_input, True)
    w.add_scalar('log', 10, 2)

The first scalar gets logged, the second one doesn't. The add_graph prints the whole model graph in console. The file generated is empty with just the first scalar logged. The forward pass works normally for the model. The verbose of add_graph prints 510 elements. Any help will be appreciated.

Pytorch version: 1.2 Tensorboard version: 1.15.0a20190806

Upvotes: 1

Views: 675

Answers (1)

Pere-Lluis Huguet
Pere-Lluis Huguet

Reputation: 419

Apparently it was needed to add flushing.

dummy_input = torch.Tensor(torch.rand(2, 10, 1024))
w.add_scalar('metric', 10, 1)
w.add_graph(model, dummy_input, True)
w.add_scalar('metric', 10, 2)
w.flush()
w.close()

Made the trick.

Upvotes: 1

Related Questions