From 5774e1ce88e7df1e9aa064d242210bb0b356c8c3 Mon Sep 17 00:00:00 2001 From: Jan Blumenkamp Date: Tue, 1 Sep 2020 00:28:46 +0200 Subject: [PATCH] [tune/rllib/wandb] Flatten result dict so that nested result dicts are shown in W&B logger (#10429) --- python/ray/tune/integration/wandb.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/python/ray/tune/integration/wandb.py b/python/ray/tune/integration/wandb.py index 66d13ee4e..b00d3cdd8 100644 --- a/python/ray/tune/integration/wandb.py +++ b/python/ray/tune/integration/wandb.py @@ -7,6 +7,7 @@ from ray import logger from ray.tune import Trainable from ray.tune.function_runner import FunctionRunner from ray.tune.logger import Logger +from ray.tune.utils import flatten_dict try: import wandb @@ -145,11 +146,16 @@ class _WandbLoggingProcess(Process): def _handle_result(self, result): config_update = result.get("config", {}).copy() log = {} + flat_result = flatten_dict(result, delimiter="/") - for k, v in result.items(): - if k in self._to_config: + for k, v in flat_result.items(): + if any( + k.startswith(item + "/") or k == item + for item in self._to_config): config_update[k] = v - elif k in self._exclude: + elif any( + k.startswith(item + "/") or k == item + for item in self._exclude): continue elif not isinstance(v, Number): continue