def stream_tfevents(path, file_api, run, step=0, namespace=""): """Parses and streams a tfevents file to the server""" last_step = 0 row = {} buffer = [] last_row = {} global_step_key = namespaced_tag("global_step", namespace) try: for summary in tf.train.summary_iterator(path): parsed = tf_summary_to_dict(summary, namespace=namespace) if last_step != parsed[global_step_key]: last_step = parsed[global_step_key] if len(row) > 3: # Must have more than _timestamp, _step, and global_step step += 1 row["_step"] = step last_row = history_dict_to_json(run, deepcopy(row)) file_api.push("wandb-history.jsonl", util.json_dumps_safer_history(last_row)) row = {} row.update(parsed) except tf.errors.DataLossError: wandb.termwarn("Found a truncated record in tfevents file, stopping parse") step += 1 row["_step"] = step last_row = history_dict_to_json(run, deepcopy(row)) file_api.push("wandb-history.jsonl", util.json_dumps_safer_history(last_row)) return last_row
def publish_history(self, data, step=None, run=None): run = run or self._run data = data_types.history_dict_to_json(run, data, step=step) history = wandb_internal_pb2.HistoryRecord() for k, v in six.iteritems(data): item = history.item.add() item.key = k item.value_json = json_dumps_safer_history(v) self._publish_history(history)
def send_history(self, data): rec = wandb_internal_pb2.Record() data = data_types.history_dict_to_json(self._run, data) history = rec.history for k, v in six.iteritems(data): item = history.item.add() item.key = k item.value_json = json_dumps_safer_history(v) self._queue_process(rec)
def publish_history(self, data, step=None, run=None, publish_step=True): run = run or self._run data = data_types.history_dict_to_json(run, data, step=step) history = pb.HistoryRecord() if publish_step: assert step is not None history.step.num = step data.pop("_step", None) for k, v in six.iteritems(data): item = history.item.add() item.key = k item.value_json = json_dumps_safer_history(v) # type: ignore self._publish_history(history)
def stream_tfevents(path, file_api, run, step=0, namespace=""): """Parses and streams a tfevents file to the server""" last_step = 0 row = {} buffer = [] last_row = {} global_step_key = namespaced_tag("global_step", namespace) for summary in tf.train.summary_iterator(path): parsed = tf_summary_to_dict(summary, namespace=namespace) if last_step != parsed[global_step_key]: step += 1 row["_step"] = step last_step = parsed[global_step_key] # TODO: handle time if len(row) > 0: last_row = history_dict_to_json(run, row) file_api.push("wandb-history.jsonl", util.json_dumps_safer_history(last_row)) row.update(parsed) # TODO: It's not clear to me why we still have wandb.data_types in last_row here, # but we do so we convert again return history_dict_to_json(run, last_row)
def _transform(self): """Transforms special classes into the proper format before writing""" self.row = data_types.history_dict_to_json(self._run, self.row)