Plotting loss with LBFGS

Looking at the example for how LBFGS needs a closure() function to be used (, 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():
    out = seq(input)
    loss = criterion(out, target)
    print('loss:', loss.item())
    return loss

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!