diff --git a/doc/source/tune-usage.rst b/doc/source/tune-usage.rst index 04c1bd08b..d44ede6ac 100644 --- a/doc/source/tune-usage.rst +++ b/doc/source/tune-usage.rst @@ -535,11 +535,11 @@ The following fields will automatically show up on the console output, if provid TensorBoard ----------- -To visualize learning in tensorboard, install TensorFlow: +To visualize learning in tensorboard, install TensorFlow or tensorboardX: .. code-block:: bash - $ pip install tensorflow + $ pip install tensorboardX # or pip install tensorflow Then, after you run a experiment, you can visualize your experiment with TensorBoard by specifying the output directory of your results. Note that if you running Ray on a remote cluster, you can forward the tensorboard port to your local machine through SSH using ``ssh -L 6006:localhost:6006
``: @@ -603,12 +603,10 @@ You can pass in your own logging mechanisms to output logs in custom formats as These loggers will be called along with the default Tune loggers. All loggers must inherit the `Logger interface `__. Tune enables default loggers for Tensorboard, CSV, and JSON formats. You can also check out `logger.py `__ for implementation details. An example can be found in `logging_example.py `__. -.. warning:: If you run into issues for TensorBoard logging, consider using the TensorBoardX Logger (``from ray.tune.logger import TBXLogger``) - TBXLogger (TensorboardX) ~~~~~~~~~~~~~~~~~~~~~~~~ -Tune provides a logger using `TensorBoardX `_. You can install tensorboardX via ``pip install tensorboardX``. This logger automatically outputs loggers similar to the default TensorFlow logging format but is nice if you are undergoing a TF1 to TF2 transition. By default, it will log any scalar value provided via the result dictionary along with HParams information. +Tune provides a logger using `TensorBoardX `_. You can install tensorboardX via ``pip install tensorboardX`` or ``pip install 'ray[tune]'``. This logger automatically outputs loggers similar to using a default TensorFlow logging format. By default, it will log any scalar value provided via the result dictionary along with HParams information. .. code-block:: python diff --git a/doc/source/tune.rst b/doc/source/tune.rst index 85a1d3f7a..36024ca42 100644 --- a/doc/source/tune.rst +++ b/doc/source/tune.rst @@ -38,7 +38,7 @@ To run this example, you will need to install the following: .. code-block:: bash - $ pip install ray[tune] torch torchvision filelock + $ pip install 'ray[tune]' torch torchvision This example runs a small grid search to train a CNN using PyTorch and Tune. @@ -81,8 +81,7 @@ Below are some blog posts and talks about Tune: - [blog] `Simple hyperparameter and architecture search in tensorflow with Ray Tune `_ - [slides] `Talk given at RISECamp 2019 `_ - [video] `Talk given at RISECamp 2018 `_ - - [video] `A Guide to Modern Hyperparameter Optimization (PyData LA 2019) `_ - - [slides] `A Guide to Modern Hyperparameter Optimization (PyData LA 2019) `_ + - [video] `A Guide to Modern Hyperparameter Optimization (PyData LA 2019) `_ (`slides `_) Open Source Projects using Tune ------------------------------- diff --git a/python/ray/tune/logger.py b/python/ray/tune/logger.py index c41719792..2ca31b8d9 100644 --- a/python/ray/tune/logger.py +++ b/python/ray/tune/logger.py @@ -315,7 +315,8 @@ class CSVLogger(Logger): class TBXLogger(Logger): """TensorBoardX Logger. - Automatically flattens nested dicts to show on TensorBoard: + Note that hparams will be written only after a trial has terminated. + This logger automatically flattens nested dicts to show on TensorBoard: {"a": {"b": 1, "c": 2}} -> {"a/b": 1, "a/c": 2} """ @@ -324,7 +325,7 @@ class TBXLogger(Logger): try: from tensorboardX import SummaryWriter except ImportError: - logger.error("pip install tensorboardX to see TensorBoard files.") + logger.error("pip install 'ray[tune]' to see TensorBoard files.") raise self._file_writer = SummaryWriter(self.logdir, flush_secs=30) self.last_result = None @@ -359,17 +360,24 @@ 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: - from tensorboardX.summary import hparams - experiment_tag, session_start_tag, session_end_tag = hparams( - hparam_dict=self.trial.evaluated_params, - metric_dict=self.last_result) - self._file_writer.file_writer.add_summary(experiment_tag) - self._file_writer.file_writer.add_summary(session_start_tag) - self._file_writer.file_writer.add_summary(session_end_tag) + self._try_log_hparams(self.last_result) self._file_writer.close() + def _try_log_hparams(self, result): + # TBX currently errors if the hparams value is None. + scrubbed_params = { + k: v + for k, v in self.trial.evaluated_params.items() if v is not None + } + from tensorboardX.summary import hparams + experiment_tag, session_start_tag, session_end_tag = hparams( + hparam_dict=scrubbed_params, metric_dict=result) + self._file_writer.file_writer.add_summary(experiment_tag) + self._file_writer.file_writer.add_summary(session_start_tag) + self._file_writer.file_writer.add_summary(session_end_tag) -DEFAULT_LOGGERS = (JsonLogger, CSVLogger, tf2_compat_logger) + +DEFAULT_LOGGERS = (JsonLogger, CSVLogger, TBXLogger) class UnifiedLogger(Logger): diff --git a/python/setup.py b/python/setup.py index c6e666e04..a29d4d542 100644 --- a/python/setup.py +++ b/python/setup.py @@ -72,16 +72,20 @@ if "RAY_USE_NEW_GCS" in os.environ and os.environ["RAY_USE_NEW_GCS"] == "on": ] extras = { - "rllib": [ - "pyyaml", "gym[atari]", "opencv-python-headless", "lz4", "scipy", - "tabulate" - ], "debug": ["psutil", "setproctitle", "py-spy >= 0.2.0"], "dashboard": ["aiohttp", "google", "grpcio", "psutil", "setproctitle"], "serve": ["uvicorn", "pygments", "werkzeug", "flask", "pandas", "blist"], - "tune": ["tabulate"], + "tune": ["tabulate", "tensorboardX"], } +extras["rllib"] = extras["tune"] + [ + "pyyaml", + "gym[atari]", + "opencv-python-headless", + "lz4", + "scipy", +] + extras["all"] = list(set(chain.from_iterable(extras.values())))