def _add_session(self, session, start_info, groups_by_name): """Adds a new Session protobuffer to the 'groups_by_name' dictionary. Called by _build_session_groups when we encounter a new session. Creates the Session protobuffer and adds it to the relevant group in the 'groups_by_name' dict. Creates the session group if this is the first time we encounter it. Args: session: api_pb2.Session. The session to add. start_info: The SessionStartInfo protobuffer associated with the session. groups_by_name: A str to SessionGroup protobuffer dict. Representing the session groups and sessions found so far. """ # If the group_name is empty, this session's group contains only # this session. Use the session name for the group name since session # names are unique. group_name = start_info.group_name or session.name if group_name in groups_by_name: groups_by_name[group_name].sessions.extend([session]) else: # Create the group and add the session as the first one. group = api_pb2.SessionGroup( name=group_name, sessions=[session], monitor_url=start_info.monitor_url) # Copy hparams from the first session (all sessions should have the same # hyperparameter values) into result. # There doesn't seem to be a way to initialize a protobuffer map in the # constructor. for (key, value) in six.iteritems(start_info.hparams): group.hparams[key].CopyFrom(value) groups_by_name[group_name] = group
def _build_group_from_sessions(self, sessions, session_infos_by_name): assert sessions # Make sure sessions is non-empty # Sort sessions by name so the order is deterministic. sessions = sorted(sessions, key=lambda session: session.name) # TODO(erez): Do proper metric aggregation. For now we just take # the metric values from the first session. result = api_pb2.SessionGroup( name=session_infos_by_name[sessions[0].name].start_info.group_name, metric_values=sessions[0].metric_values, sessions=sessions, monitor_url=(session_infos_by_name[ sessions[0].name].start_info.monitor_url), ) # Copy hparams from the first session (all sessions should have the same # hyperparameter values) into result. # There doesn't seem to be a way to initialize a protobuffer map in the # constructor. hparams = session_infos_by_name[sessions[0].name].start_info.hparams for (key, value) in six.iteritems(hparams): result.hparams[key].CopyFrom(value) return result