Could you explain some more of what it is you want to do? Is there any particular reason as to why you are not simply calculating the mean loss of every epoch and doing something like:
for epoch in range(num_epochs):
    losses = []
    for idx, (inputs, labels) in enumerate(train_dl):
        ...
        loss = criterion(outputs, labels)
        losses += loss.item()
    
        print(
            f"Mean loss at epoch [{epoch}/{num_epochs}] was {sum(losses)/len(losses)}"
        )