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

Record data epoch in training metrics #795

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/fairseq2/metrics/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class _MetricFormatter:
"prob_perplexity": _MetricFormatter("Prob Perplexity", 210, format_as_float),
"temperature": _MetricFormatter("Temperature", 220, format_as_float),
"gradient_norm": _MetricFormatter("Gradient Norm", 300, format_as_float),
"data_epoch": _MetricFormatter("Data Epoch", 490, format_as_int),
"elapsed_time": _MetricFormatter("Elapsed Time", 500, format_as_seconds),
"wall_time": _MetricFormatter("Wall Time", 510, format_as_seconds),
"lr": _MetricFormatter("Learning Rate", 700, format_as_float),
Expand Down
18 changes: 11 additions & 7 deletions src/fairseq2/recipes/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,8 @@ def _run_step(self) -> None:

# Collect the batches.
with record_function(f"step_{step_nr}_data_load"):
try:
batches = self._next_batches()
except StopIteration:
batches = self._next_batches()
if batches is None:
return

# Prepare the unit.
Expand Down Expand Up @@ -775,15 +774,16 @@ def _run_step(self) -> None:

self._total_step_time += watch.get_elapsed_time()

def _next_batches(self) -> list[BatchT]:
def _next_batches(self) -> list[BatchT] | None:
try:
batches = next(self._data_reader)
except StopIteration:
batches = None

if batches is not None:
self._read_data = True

return batches
except StopIteration:
pass

self._data_reader.reset()

Expand All @@ -807,7 +807,7 @@ def _next_batches(self) -> list[BatchT]:

self._repeat_step = True

raise StopIteration()
return None

def _maybe_no_sync(
self, batch_nr: int, num_batches: int
Expand Down Expand Up @@ -861,6 +861,8 @@ def _publish_metrics(self) -> None:

values["lr"] = get_effective_lr(self._lr_scheduler)

values["data_epoch"] = self._data_epoch_nr

values["elapsed_time"] = self._total_step_time

values["wall_time"] = self._wall_watch.get_elapsed_time()
Expand Down Expand Up @@ -966,6 +968,8 @@ def _publish_validation_metrics(

extend_batch_metrics(values, num_batches, elapsed_time)

values["data_epoch"] = self._data_epoch_nr

values["elapsed_time"] = elapsed_time

values["wall_time"] = self._wall_watch.get_elapsed_time()
Expand Down
Loading