Solved by ptrblck in post #2 
              
              
                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()
    r…