Hi,
Looking at the example for how LBFGS needs a closure() function to be used (https://github.com/pytorch/examples/blob/master/time_sequence_prediction/train.py), is there a way I could plot the loss as well? Simply appending the loss calculated inside closure() to a list initialized outside closure doesn’t seem to work.
Do you get any error or why is it not working?
Simply appending loss.item()
to a list seems to work:
losses = []
def closure():
optimizer.zero_grad()
out = seq(input)
loss = criterion(out, target)
print('loss:', loss.item())
losses.append(loss.item())
loss.backward()
return loss
optimizer.step(closure)
My bad, it does seem to work indeed. Not quite sure what I missed last time since I tried the exact same thing and the list just stayed empty. Thanks a lot!