How to Save pytorch tensor in append mode
How to save several tensor appending using torch.save()?

For example

for i in range(20):
       ......
    loss = criterion(scores, labels) 
    torch.save(loss,'loss.pt')


How to save these all 20 losses?

It's probably not possible to directly append to the file, at least, I could not find documentation for this. In your example, however, a better approach is to append to a list, and save at the end.

import torch

losses = []
for i in range(20):
    #   ......
    loss = criterion(scores, labels) 
    losses.append(loss.item())


torch.save(losses, 'loss.pt')

