mirror of
https://github.com/wassname/ray.git
synced 2026-07-01 09:27:40 +08:00
[tune] IP Check, Flatten Results for TBX (#7705)
* support_flattened * loggers * Format logger changes Co-authored-by: Kristian Hartikainen <kristian.hartikainen@gmail.com>
This commit is contained in:
@@ -239,9 +239,10 @@ class TBXLogger(Logger):
|
||||
def close(self):
|
||||
if self._file_writer is not None:
|
||||
if self.trial and self.trial.evaluated_params and self.last_result:
|
||||
flat_result = flatten_dict(self.last_result, delimiter="/")
|
||||
scrubbed_result = {
|
||||
k: value
|
||||
for k, value in self.last_result.items()
|
||||
for k, value in flat_result.items()
|
||||
if type(value) in VALID_SUMMARY_TYPES
|
||||
}
|
||||
self._try_log_hparams(scrubbed_result)
|
||||
@@ -249,9 +250,10 @@ class TBXLogger(Logger):
|
||||
|
||||
def _try_log_hparams(self, result):
|
||||
# TBX currently errors if the hparams value is None.
|
||||
flat_params = flatten_dict(self.trial.evaluated_params)
|
||||
scrubbed_params = {
|
||||
k: v
|
||||
for k, v in self.trial.evaluated_params.items() if v is not None
|
||||
for k, v in flat_params.items() if v is not None
|
||||
}
|
||||
from tensorboardX.summary import hparams
|
||||
experiment_tag, session_start_tag, session_end_tag = hparams(
|
||||
|
||||
@@ -28,30 +28,30 @@ class LoggerSuite(unittest.TestCase):
|
||||
shutil.rmtree(self.test_dir, ignore_errors=True)
|
||||
|
||||
def testCSV(self):
|
||||
config = {"a": 2, "b": 5}
|
||||
config = {"a": 2, "b": 5, "c": {"c": {"D": 123}, "e": None}}
|
||||
t = Trial(evaluated_params=config, trial_id="csv")
|
||||
logger = CSVLogger(config=config, logdir=self.test_dir, trial=t)
|
||||
logger.on_result(result(2, 4))
|
||||
logger.on_result(result(2, 4))
|
||||
logger.on_result(result(2, 4, score=[1, 2, 3]))
|
||||
logger.on_result(result(2, 4, score=[1, 2, 3], hello={"world": 1}))
|
||||
logger.close()
|
||||
|
||||
def testJSON(self):
|
||||
config = {"a": 2, "b": 5}
|
||||
config = {"a": 2, "b": 5, "c": {"c": {"D": 123}, "e": None}}
|
||||
t = Trial(evaluated_params=config, trial_id="json")
|
||||
logger = JsonLogger(config=config, logdir=self.test_dir, trial=t)
|
||||
logger.on_result(result(0, 4))
|
||||
logger.on_result(result(1, 4))
|
||||
logger.on_result(result(2, 4, score=[1, 2, 3]))
|
||||
logger.on_result(result(2, 4, score=[1, 2, 3], hello={"world": 1}))
|
||||
logger.close()
|
||||
|
||||
def testTBX(self):
|
||||
config = {"a": 2, "b": 5}
|
||||
config = {"a": 2, "b": 5, "c": {"c": {"D": 123}, "e": None}}
|
||||
t = Trial(evaluated_params=config, trial_id="tbx")
|
||||
logger = TBXLogger(config=config, logdir=self.test_dir, trial=t)
|
||||
logger.on_result(result(0, 4))
|
||||
logger.on_result(result(1, 4))
|
||||
logger.on_result(result(2, 4, score=[1, 2, 3]))
|
||||
logger.on_result(result(2, 4, score=[1, 2, 3], hello={"world": 1}))
|
||||
logger.close()
|
||||
|
||||
|
||||
|
||||
@@ -178,7 +178,7 @@ class Trainable:
|
||||
"slow to initialize, consider setting "
|
||||
"reuse_actors=True to reduce actor creation "
|
||||
"overheads.".format(setup_time))
|
||||
self._local_ip = ray.services.get_node_ip_address()
|
||||
self._local_ip = self.get_current_ip()
|
||||
log_sys_usage = self.config.get("log_sys_usage", False)
|
||||
self._monitor = UtilMonitor(start=log_sys_usage)
|
||||
|
||||
@@ -213,7 +213,7 @@ class Trainable:
|
||||
"""
|
||||
return ""
|
||||
|
||||
def current_ip(self):
|
||||
def get_current_ip(self):
|
||||
logger.info("Getting current IP.")
|
||||
self._local_ip = ray.services.get_node_ip_address()
|
||||
return self._local_ip
|
||||
@@ -419,8 +419,8 @@ class Trainable:
|
||||
self._timesteps_since_restore = 0
|
||||
self._iterations_since_restore = 0
|
||||
self._restored = True
|
||||
logger.info("Restored on %s from checkpoint: %s", self.current_ip(),
|
||||
checkpoint_path)
|
||||
logger.info("Restored on %s from checkpoint: %s",
|
||||
self.get_current_ip(), checkpoint_path)
|
||||
state = {
|
||||
"_iteration": self._iteration,
|
||||
"_timesteps_total": self._timesteps_total,
|
||||
|
||||
Reference in New Issue
Block a user