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

Epoch loss #201

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion finetrainers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,8 @@ def train(self) -> None:

self.transformer.train()
models_to_accumulate = [self.transformer]
epoch_loss = 0.0
num_loss_updates = 0

for step, batch in enumerate(self.dataloader):
logger.debug(f"Starting step {step + 1}")
Expand Down Expand Up @@ -843,14 +845,20 @@ def train(self) -> None:
if should_run_validation:
self.validate(global_step)

logs["loss"] = loss.detach().item()
loss_item = loss.detach().item()
epoch_loss += loss_item
num_loss_updates += 1
logs["step_loss"] = loss_item
logs["lr"] = self.lr_scheduler.get_last_lr()[0]
progress_bar.set_postfix(logs)
accelerator.log(logs, step=global_step)

if global_step >= self.state.train_steps:
break

if num_loss_updates > 0:
epoch_loss /= num_loss_updates
accelerator.log({"epoch_loss": epoch_loss}, step=global_step)
memory_statistics = get_memory_statistics()
logger.info(f"Memory after epoch {epoch + 1}: {json.dumps(memory_statistics, indent=4)}")

Expand Down