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

Print step time for each step #361

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions axlearn/common/launch_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"Used for initializing model parameters and pseudo-random number generation during training.",
)
flags.DEFINE_list("trace_at_steps", [], "Step numbers to start a 3-step profile at.")
flags.DEFINE_bool("log_step_time", False, "Log the time it takes for each step")
flags.DEFINE_list(
"eval_trace_at_iters",
[],
Expand Down Expand Up @@ -94,6 +95,7 @@ def get_trainer_config(
trainer_config.mesh_shape = trainer_config.mesh_shape or (len(jax.devices()), 1)
trainer_config.mesh_shape = infer_mesh_shape(trainer_config.mesh_shape)
trainer_config.start_trace_steps = [int(el) for el in flag_values.trace_at_steps]
trainer_config.log_step_time = flag_values.log_step_time
if trainer_config.watchdog_timeout_seconds is None:
trainer_config.watchdog_timeout_seconds = flag_values.trainer_watchdog_timeout_seconds

Expand Down
13 changes: 13 additions & 0 deletions axlearn/common/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ class Config(Module.Config):
# By default, only trace on host 0.
start_trace_process_indices: Union[Literal["all"], Sequence[int]] = [0]

# Log the step time for each individual step
log_step_time: bool = False
Comment on lines +144 to +145
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it'll be more general to do:

Suggested change
# Log the step time for each individual step
log_step_time: bool = False
# Interval to log average step time. If None, defaults to 100.
log_step_time_every_n_steps: Optional[int] = None

Note that we default to None instead of 100 to avoid triggering a large number of golden config updates.


# Prune empty state updates.
prune_empty_state_updates: bool = True

Expand Down Expand Up @@ -431,6 +434,10 @@ def run(
stop_trace_step = self._maybe_stop_or_start_tracing(stop_trace_step, output)

self._step = self._step + 1

if cfg.log_step_time:
step_start_time = time.perf_counter()

self.vlog(3, "Start step %s", self.step)
output = self._run_step(
utils.host_to_global_device_array(input_batch),
Expand All @@ -439,6 +446,12 @@ def run(
else None,
)
self.vlog(3, "Done step %s", self.step)

if cfg.log_step_time:
step_time = time.perf_counter() - step_start_time
self._step_log("Step %s took %s seconds", self.step, step_time)
self.summary_writer(self.step, {"step_time": step_time})

num_steps += 1
if num_steps % 100 == 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if num_steps % 100 == 0:
if num_steps % (cfg.log_step_time_every_n_steps or 100) == 0:

now = time.perf_counter()
Expand Down