Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per-epoch loss computation over just the epoch instead of snapshot of total average #79

Open
largestack opened this issue Feb 10, 2025 · 0 comments

Comments

@largestack
Copy link

largestack commented Feb 10, 2025

Quick request if possible. loss/epoch seems to be calculated as the total average loss since the start of training. Is it possible to upgrade this to record the average step loss of the epoch instead? I think this will better-guide everyone in how their latest model is performing and better matches what people expect this value to contain.

Eg, something like:

for epoch in range(epoch_to_start, num_train_epochs):
    epoch_losses = []  # Reset each epoch
    for step, batch in enumerate(train_dataloader):
        # ... training loop ...
        current_loss = loss.detach().item()
        epoch_losses.append(current_loss)
        # ... other code ...

    # After steps in epoch, calculate epoch loss
    avg_epoch_loss = sum(epoch_losses) / len(epoch_losses) if len(epoch_losses) > 0 else 0.0
    if len(accelerator.trackers) > 0:
        logs = {"loss/epoch": avg_epoch_loss}
        accelerator.log(logs, step=epoch + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant