Skip to content

Throughput instrumentation per training step. #7

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,10 @@ def train(
self.control = self.callback_handler.on_epoch_begin(self.args, self.state, self.control)

for step, inputs in enumerate(epoch_iterator):

start_train_step_time = time.time()
if (self.state.global_step == 1):
start_train_stable_time = time.time()

# Skip past any already trained steps if resuming training
if steps_trained_in_current_epoch > 0:
Expand Down Expand Up @@ -1255,6 +1259,10 @@ def train(

self._maybe_log_save_evaluate(tr_loss, model, trial, epoch)

ort_step_metrics = speed_metrics("train_step",
start_train_step_time, self.args.per_device_train_batch_size)
self.log(ort_step_metrics)

if self.control.should_epoch_stop or self.control.should_training_stop:
break

Expand Down Expand Up @@ -1302,10 +1310,14 @@ def train(
)

metrics = speed_metrics("train", start_time, self.state.max_steps)
ort_end_train_metrics = speed_metrics("train",

Choose a reason for hiding this comment

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

Looks like these will be calculated for non-ort runs too? Can we remove the ort_prefix, or add these under an if?

start_train_stable_time, (num_examples*num_train_epochs - total_train_batch_size))

if self._total_flos is not None:
self.store_flos()
metrics["total_flos"] = self.state.total_flos
self.log(metrics)
self.log(ort_end_train_metrics)

self.control = self.callback_handler.on_train_end(self.args, self.state, self.control)
# add remaining tr_loss
Expand Down