Skip to content

[bugfix] summary writer no longer crashes if Hyperparameters could not be written #4265

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

Merged
merged 2 commits into from
Jul 23, 2020
Merged
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
17 changes: 11 additions & 6 deletions ml-agents/mlagents/trainers/stats.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import defaultdict
from enum import Enum
from typing import List, Dict, NamedTuple, Any
from typing import List, Dict, NamedTuple, Any, Optional
import numpy as np
import abc
import csv
Expand Down Expand Up @@ -211,11 +211,14 @@ def add_property(
) -> None:
if property_type == StatsPropertyType.HYPERPARAMETERS:
assert isinstance(value, dict)
text = self._dict_to_tensorboard("Hyperparameters", value)
summary = self._dict_to_tensorboard("Hyperparameters", value)
self._maybe_create_summary_writer(category)
self.summary_writers[category].add_summary(text, 0)
if summary is not None:
self.summary_writers[category].add_summary(summary, 0)

def _dict_to_tensorboard(self, name: str, input_dict: Dict[str, Any]) -> str:
def _dict_to_tensorboard(
self, name: str, input_dict: Dict[str, Any]
) -> Optional[bytes]:
"""
Convert a dict to a Tensorboard-encoded string.
:param name: The name of the text.
Expand All @@ -232,8 +235,10 @@ def _dict_to_tensorboard(self, name: str, input_dict: Dict[str, Any]) -> str:
s = sess.run(s_op)
return s
except Exception:
logger.warning("Could not write text summary for Tensorboard.")
return ""
logger.warning(
f"Could not write {name} summary for Tensorboard: {input_dict}"
)
return None


class CSVWriter(StatsWriter):
Expand Down