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

fix: Use as instead of , to support python 3 in tfevent metrics collector #881

Merged
merged 2 commits into from
Oct 15, 2019
Merged
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
32 changes: 20 additions & 12 deletions cmd/metricscollector/v1alpha3/tfevent-metricscollector/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@
from tfevent_loader import MetricsCollector
from logging import getLogger, StreamHandler, INFO

timeout_in_seconds = 60


def parse_options():
parser = argparse.ArgumentParser(
description='TF-Event MetricsCollector',
add_help = True
)
parser.add_argument("-s", "--manager_server_addr", type = str, default = "katib-manager:6789")
parser.add_argument("-t", "--trial_name", type = str, default = "")
parser.add_argument("-path", "--dir_path", type = str, default = "/log")
parser.add_argument("-m", "--metric_names", type = str, default = "")
description='TF-Event MetricsCollector',
add_help=True
)
parser.add_argument("-s", "--manager_server_addr",
type=str, default="katib-manager:6789")
parser.add_argument("-t", "--trial_name", type=str, default="")
parser.add_argument("-path", "--dir_path", type=str, default="/log")
parser.add_argument("-m", "--metric_names", type=str, default="")
opt = parser.parse_args()
return opt


if __name__ == '__main__':
logger = getLogger(__name__)
handler = StreamHandler()
Expand All @@ -28,18 +33,21 @@ def parse_options():
opt = parse_options()
manager_server = opt.manager_server_addr.split(':')
if len(manager_server) != 2:
raise Exception("Invalid katib manager service address: %s" % opt.manager_server_addr)

raise Exception("Invalid katib manager service address: %s" %
opt.manager_server_addr)

WaitOtherMainProcesses()

mc = MetricsCollector(opt.metric_names.split(','))
observation_log = mc.parse_file(opt.dir_path)

channel = grpc.beta.implementations.insecure_channel(manager_server[0], int(manager_server[1]))
channel = grpc.beta.implementations.insecure_channel(
manager_server[0], int(manager_server[1]))

with api_pb2.beta_create_Manager_stub(channel) as client:
logger.info("In " + opt.trial_name + " " + str(len(observation_log.metric_logs)) + " metrics will be reported.")
logger.info("In " + opt.trial_name + " " +
str(len(observation_log.metric_logs)) + " metrics will be reported.")
client.ReportObservationLog(api_pb2.ReportObservationLogRequest(
trial_name=opt.trial_name,
observation_log=observation_log
), 10)
), timeout=timeout_in_seconds)
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def parse_file(self, directory):
try:
self.logger.info(f + " will be parsed.")
mls = self.parser.parse_summary(f, self.metrics)
except Exception, e:
except Exception as e:
self.logger.warning("Unexpected error: "+ str(e))
continue
return api_pb2.ObservationLog(metric_logs=mls)