This commit is contained in:
Yuting Jiang 2022-12-27 02:34:44 +00:00
Родитель 9869311cbb
Коммит d1ce9c6771
5 изменённых файлов: 20 добавлений и 32 удалений

Просмотреть файл

@ -443,3 +443,15 @@ class ModelBenchmark(Benchmark):
"""Print environments or dependencies information."""
# TODO: will implement it when add real benchmarks in the future.
pass
def _log_step_time(self, curr_step, precision, start, end):
"""Log step time into stdout regularly.
Args:
curr_step (int): the index of the current step
precision (Precision): precision of model and input data, such as float32, float16.
start (float): the start timestamp of the current step
end (float): the end timestamp of the current step
"""
if self._args.log_every_steps and curr_step % self._args.log_every_steps == 0:
print(f'{self._name} - {precision.value}: step {curr_step}, step time {(end - start) * 1000}')

Просмотреть файл

@ -148,9 +148,7 @@ class PytorchBERT(PytorchBase):
self._optimizer.step()
end = self._timer()
curr_step += 1
if self._args.log_every_steps:
if curr_step % self._args.log_every_steps == 0:
print(f'{self._name} - {precision.value}: step {curr_step}, step time {(end - start) * 1000}')
self._log_step_time(curr_step, precision, start, end)
if curr_step > self._args.num_warmup:
# Save the step time of every training/inference step, unit is millisecond.
duration.append((end - start) * 1000)
@ -179,11 +177,7 @@ class PytorchBERT(PytorchBase):
self._model(sample)
end = self._timer()
curr_step += 1
if self._args.log_every_steps:
if curr_step % self._args.log_every_steps == 0:
print(
f'{self._name} - {precision.value}: step {curr_step}, step time {(end - start) * 1000}'
)
self._log_step_time(curr_step, precision, start, end)
if curr_step > self._args.num_warmup:
# Save the step time of every training/inference step, unit is millisecond.
duration.append((end - start) * 1000)

Просмотреть файл

@ -111,9 +111,7 @@ class PytorchCNN(PytorchBase):
self._optimizer.step()
end = self._timer()
curr_step += 1
if self._args.log_every_steps:
if curr_step % self._args.log_every_steps == 0:
print(f'{self._name} - {precision.value}: step {curr_step}, step time {(end - start) * 1000}')
self._log_step_time(curr_step, precision, start, end)
if curr_step > self._args.num_warmup:
# Save the step time of every training/inference step, unit is millisecond.
duration.append((end - start) * 1000)
@ -143,11 +141,7 @@ class PytorchCNN(PytorchBase):
self._model(sample)
end = self._timer()
curr_step += 1
if self._args.log_every_steps:
if curr_step % self._args.log_every_steps == 0:
print(
f'{self._name} - {precision.value}: step {curr_step}, step time {(end - start) * 1000}'
)
self._log_step_time(curr_step, precision, start, end)
if curr_step > self._args.num_warmup:
# Save the step time of every training/inference step, unit is millisecond.
duration.append((end - start) * 1000)

Просмотреть файл

@ -142,9 +142,7 @@ class PytorchGPT2(PytorchBase):
self._optimizer.step()
end = self._timer()
curr_step += 1
if self._args.log_every_steps:
if curr_step % self._args.log_every_steps == 0:
print(f'{self._name} - {precision.value}: step {curr_step}, step time {(end - start) * 1000}')
self._log_step_time(curr_step, precision, start, end)
if curr_step > self._args.num_warmup:
# Save the step time of every training/inference step, unit is millisecond.
duration.append((end - start) * 1000)
@ -173,11 +171,7 @@ class PytorchGPT2(PytorchBase):
self._model(sample)
end = self._timer()
curr_step += 1
if self._args.log_every_steps:
if curr_step % self._args.log_every_steps == 0:
print(
f'{self._name} - {precision.value}: step {curr_step}, step time {(end - start) * 1000}'
)
self._log_step_time(curr_step, precision, start, end)
if curr_step > self._args.num_warmup:
# Save the step time of every training/inference step, unit is millisecond.
duration.append((end - start) * 1000)

Просмотреть файл

@ -151,9 +151,7 @@ class PytorchLSTM(PytorchBase):
self._optimizer.step()
end = self._timer()
curr_step += 1
if self._args.log_every_steps:
if curr_step % self._args.log_every_steps == 0:
print(f'{self._name} - {precision.value}: step {curr_step}, step time {(end - start) * 1000}')
self._log_step_time(curr_step, precision, start, end)
if curr_step > self._args.num_warmup:
# Save the step time of every training/inference step, unit is millisecond.
duration.append((end - start) * 1000)
@ -183,11 +181,7 @@ class PytorchLSTM(PytorchBase):
self._model(sample)
end = self._timer()
curr_step += 1
if self._args.log_every_steps:
if curr_step % self._args.log_every_steps == 0:
print(
f'{self._name} - {precision.value}: step {curr_step}, step time {(end - start) * 1000}'
)
self._log_step_time(curr_step, precision, start, end)
if curr_step > self._args.num_warmup:
# Save the step time of every training/inference step, unit is millisecond.
duration.append((end - start) * 1000)