From e4565c9cc6caa15e0d32694d974d8db28841630e Mon Sep 17 00:00:00 2001 From: Eric Liang Date: Wed, 13 Nov 2019 18:50:45 -0800 Subject: [PATCH] Reduce RLlib log verbosity (#6154) --- doc/source/rllib-training.rst | 7 ++++++- rllib/agents/trainer.py | 7 ++++++- rllib/train.py | 12 ++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/doc/source/rllib-training.rst b/doc/source/rllib-training.rst index d9f3c407e..7d7772657 100644 --- a/doc/source/rllib-training.rst +++ b/doc/source/rllib-training.rst @@ -567,13 +567,18 @@ You can use the `data output API `__ to save episode traces Log Verbosity ~~~~~~~~~~~~~ -You can control the trainer log level via the ``"log_level"`` flag. Valid values are "INFO" (default), "DEBUG", "WARN", and "ERROR". This can be used to increase or decrease the verbosity of internal logging. For example: +You can control the trainer log level via the ``"log_level"`` flag. Valid values are "DEBUG", "INFO", "WARN" (default), and "ERROR". This can be used to increase or decrease the verbosity of internal logging. You can also use the ``-v`` and ``-vv`` flags. For example, the following two commands are about equivalent: .. code-block:: bash rllib train --env=PongDeterministic-v4 \ --run=A2C --config '{"num_workers": 2, "log_level": "DEBUG"}' + rllib train --env=PongDeterministic-v4 \ + --run=A2C --config '{"num_workers": 2}' -vv + +The default log level is ``WARN``. We strongly recommend using at least ``INFO`` level logging for development. + Stack Traces ~~~~~~~~~~~~ diff --git a/rllib/agents/trainer.py b/rllib/agents/trainer.py index 38002c19f..a22e8e36e 100644 --- a/rllib/agents/trainer.py +++ b/rllib/agents/trainer.py @@ -47,7 +47,7 @@ COMMON_CONFIG = { # Should be one of DEBUG, INFO, WARN, or ERROR. The DEBUG level will also # periodically print out summaries of relevant internal dataflow (this is # also printed out once at startup at the INFO level). - "log_level": "INFO", + "log_level": "WARN", # Callbacks that will be run during various phases of training. These all # take a single "info" dict as an argument. For episode callbacks, custom # metrics can be attached to the episode by updating the episode object's @@ -479,6 +479,11 @@ class Trainer(Trainable): self.raw_user_config = config self.config = merged_config Trainer._validate_config(self.config) + log_level = self.config.get("log_level") + if log_level in ["WARN", "ERROR"]: + logger.info("Current log_level is {}. For more information, " + "set 'log_level': 'INFO' / 'DEBUG' or use the -v and " + "-vv flags.".format(log_level)) if self.config.get("log_level"): logging.getLogger("ray.rllib").setLevel(self.config["log_level"]) diff --git a/rllib/train.py b/rllib/train.py index a46930e90..907cfc785 100755 --- a/rllib/train.py +++ b/rllib/train.py @@ -88,6 +88,10 @@ def create_parser(parser_creator=None): default="", type=str, help="Optional URI to sync training results to (e.g. s3://bucket).") + parser.add_argument( + "-v", action="store_true", help="Whether to use INFO level logging.") + parser.add_argument( + "-vv", action="store_true", help="Whether to use DEBUG level logging.") parser.add_argument( "--resume", action="store_true", @@ -143,6 +147,7 @@ def run(args, parser): } } + verbose = 1 for exp in experiments.values(): if not exp.get("run"): parser.error("the following arguments are required: --run") @@ -150,6 +155,12 @@ def run(args, parser): parser.error("the following arguments are required: --env") if args.eager: exp["config"]["eager"] = True + if args.v: + exp["config"]["log_level"] = "INFO" + verbose = 2 + if args.vv: + exp["config"]["log_level"] = "DEBUG" + verbose = 3 if args.trace: if not exp["config"].get("eager"): raise ValueError("Must enable --eager to enable tracing.") @@ -178,6 +189,7 @@ def run(args, parser): scheduler=_make_scheduler(args), queue_trials=args.queue_trials, resume=args.resume, + verbose=verbose, concurrent=True)