Skip to content
Closed
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
9 changes: 6 additions & 3 deletions recml/core/training/jax_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,14 +567,16 @@ def _train_n_steps(self, train_iter, train_step, state, start_step, num_steps, s
loop_start_time = time.time()

for step in range(start_step, start_step + num_steps):
with jax.profiler.StepTraceAnnotation("train", step_num=step):
if step == warmup_steps:
if num_steps == warmup_steps:
loop_start_time = time.time()
total_examples_in_loop = 0
valid_steps_in_loop = 0
with jax.profiler.StepTraceAnnotation("train", step_num=step):
train_batch = next(train_iter)
inputs = self._partitioner.shard_inputs(train_batch)

state, metrics_update = train_step(inputs, state)
if step >= warmup_steps:
if num_steps >= warmup_steps:
if 'common/batch_size' in metrics_update:
total_examples_in_loop += metrics_update['common/batch_size'].compute()
valid_steps_in_loop += 1
Expand All @@ -585,6 +587,7 @@ def _train_n_steps(self, train_iter, train_step, state, start_step, num_steps, s
if (step != start_step + num_steps - 1) and self._enable_checkpointing:
self._maybe_save_checkpoint(step, state)

jax.block_until_ready(state)
duration = time.time() - loop_start_time

metrics = metrics_accum.compute_and_log_scalars(start_step + num_steps - 1)
Expand Down
Loading