Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Performance logging
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #385

Test Plan: .

Differential Revision: D19739656

Pulled By: vreis

fbshipit-source-id: 347772745f2811bf2947128a23986161395c526d
  • Loading branch information
vreis authored and facebook-github-bot committed Feb 10, 2020
1 parent aad649e commit 6b37a71
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
15 changes: 15 additions & 0 deletions classy_vision/hooks/tensorboard_plot_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ def on_phase_end(
)
continue

if hasattr(task, "perf_log"):
for perf in task.perf_log:
phase_idx = perf["phase_idx"]
tag = perf["tag"]
for metric_name, metric_value in perf.items():
if metric_name in ["phase_idx", "tag"]:
continue

self.tb_writer.add_scalar(
f"Performance/{tag}/{metric_name}",
metric_value,
global_step=phase_idx,
)
task.perf_log = []

# flush so that the plots aren't lost if training crashes soon after
self.tb_writer.flush()
logging.info(f"Done plotting to Tensorboard")
36 changes: 36 additions & 0 deletions classy_vision/tasks/classification_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import copy
import enum
import logging
import time
from typing import Any, Dict, List, Optional, Union

import torch
Expand Down Expand Up @@ -807,18 +808,53 @@ def get_global_batchsize(self):
def on_start(self, local_variables):
self.run_hooks(local_variables, ClassyHookFunctions.on_start.name)

self.perf_log = []

def on_phase_start(self, local_variables):
self.phase_start_time_total = time.perf_counter()

self.advance_phase()

self.run_hooks(local_variables, ClassyHookFunctions.on_phase_start.name)

self.phase_start_time_train = time.perf_counter()

def on_phase_end(self, local_variables):
self.log_phase_end("train")

logging.info("Syncing meters on phase end...")
for meter in self.meters:
meter.sync_state()
logging.info("...meters synced")
barrier()

self.run_hooks(local_variables, ClassyHookFunctions.on_phase_end.name)

self.log_phase_end("total")

def on_end(self, local_variables):
self.run_hooks(local_variables, ClassyHookFunctions.on_end.name)

def log_phase_end(self, tag):
if not self.train:
return

assert self.phase_type == "train"

start_time = (
self.phase_start_time_train
if tag == "train"
else self.phase_start_time_total
)
phase_duration = time.perf_counter() - start_time
im_per_sec = (
self.get_global_batchsize() * len(self.dataloaders[self.phase_type])
) / phase_duration
self.perf_log.append(
dict(
tag=tag,
phase_idx=self.train_phase_idx,
epoch_duration=phase_duration,
im_per_sec=im_per_sec,
)
)

0 comments on commit 6b37a71

Please sign in to comment.