Another way would be to concatenate all the losses into one tensor, and call the operation you want.
cat_losses = torch.cat(losses, 0)
mean_loss = cat_losses.mean()
...

Both approaches work with autograd