mirror of
https://github.com/wassname/ray.git
synced 2026-08-11 11:24:51 +08:00
[tune] Default to TensorboardX and include in requirements. (#6836)
This commit is contained in:
@@ -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 <address>``:
|
||||
|
||||
@@ -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-package-ref.html#ray.tune.logger.Logger>`__. Tune enables default loggers for Tensorboard, CSV, and JSON formats. You can also check out `logger.py <https://github.com/ray-project/ray/blob/master/python/ray/tune/logger.py>`__ for implementation details. An example can be found in `logging_example.py <https://github.com/ray-project/ray/blob/master/python/ray/tune/examples/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 <https://github.com/lanpa/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 <https://github.com/lanpa/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
|
||||
|
||||
|
||||
+2
-3
@@ -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 <http://louiskirsch.com/ai/ray-tune>`_
|
||||
- [slides] `Talk given at RISECamp 2019 <https://docs.google.com/presentation/d/1v3IldXWrFNMK-vuONlSdEuM82fuGTrNUDuwtfx4axsQ/edit?usp=sharing>`_
|
||||
- [video] `Talk given at RISECamp 2018 <https://www.youtube.com/watch?v=38Yd_dXW51Q>`_
|
||||
- [video] `A Guide to Modern Hyperparameter Optimization (PyData LA 2019) <https://www.youtube.com/watch?v=10uz5U3Gy6E>`_
|
||||
- [slides] `A Guide to Modern Hyperparameter Optimization (PyData LA 2019) <https://speakerdeck.com/richardliaw/a-modern-guide-to-hyperparameter-optimization>`_
|
||||
- [video] `A Guide to Modern Hyperparameter Optimization (PyData LA 2019) <https://www.youtube.com/watch?v=10uz5U3Gy6E>`_ (`slides <https://speakerdeck.com/richardliaw/a-modern-guide-to-hyperparameter-optimization>`_)
|
||||
|
||||
Open Source Projects using Tune
|
||||
-------------------------------
|
||||
|
||||
+18
-10
@@ -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):
|
||||
|
||||
+9
-5
@@ -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())))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user