mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 14:31:15 +08:00
[Core/RLlib] Move log_once from rllib to ray.util. (#7273)
* Move log_once from rllib to tune. * Move log_once from rllib to tune. * LINT. * Move to ray.util.debug.
This commit is contained in:
@@ -7,6 +7,7 @@ import numbers
|
||||
import numpy as np
|
||||
|
||||
import ray.cloudpickle as cloudpickle
|
||||
from ray.util.debug import log_once
|
||||
from ray.tune.result import (NODE_IP, TRAINING_ITERATION, TIME_TOTAL_S,
|
||||
TIMESTEPS_TOTAL, EXPR_PARAM_FILE,
|
||||
EXPR_PARAM_PICKLE_FILE, EXPR_PROGRESS_FILE,
|
||||
@@ -214,10 +215,11 @@ class TBXLogger(Logger):
|
||||
# In case TensorboardX still doesn't think it's a valid value
|
||||
# (e.g. `[[]]`), warn and move on.
|
||||
except (ValueError, TypeError):
|
||||
logger.warning(
|
||||
"You are trying to log an invalid value ({}={}) "
|
||||
"via {}!".format(full_attr, value,
|
||||
type(self).__name__))
|
||||
if log_once("invalid_tbx_value"):
|
||||
logger.warning(
|
||||
"You are trying to log an invalid value ({}={}) "
|
||||
"via {}!".format(full_attr, value,
|
||||
type(self).__name__))
|
||||
|
||||
self.last_result = valid_result
|
||||
self._file_writer.flush()
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
from ray.tune.utils.util import (deep_update, flatten_dict, get_pinned_object,
|
||||
merge_dicts, pin_in_object_store, UtilMonitor,
|
||||
validate_save_restore, warn_if_slow)
|
||||
from ray.tune.utils.util import deep_update, flatten_dict, get_pinned_object, \
|
||||
merge_dicts, pin_in_object_store, UtilMonitor, validate_save_restore, \
|
||||
warn_if_slow
|
||||
|
||||
__all__ = [
|
||||
"deep_update", "flatten_dict", "get_pinned_object", "merge_dicts",
|
||||
"pin_in_object_store", "UtilMonitor", "validate_save_restore",
|
||||
"warn_if_slow"
|
||||
"deep_update",
|
||||
"flatten_dict",
|
||||
"get_pinned_object",
|
||||
"merge_dicts",
|
||||
"pin_in_object_store",
|
||||
"UtilMonitor",
|
||||
"validate_save_restore",
|
||||
"warn_if_slow",
|
||||
]
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
from .named_actors import get_actor, register_actor
|
||||
from .actor_pool import ActorPool
|
||||
from . import iter
|
||||
from ray.util import iter
|
||||
from ray.util.actor_pool import ActorPool
|
||||
from ray.util.debug import log_once, disable_log_once_globally, \
|
||||
enable_periodic_logging
|
||||
from ray.util.named_actors import get_actor, register_actor
|
||||
|
||||
__all__ = [
|
||||
"ActorPool",
|
||||
"iter",
|
||||
"disable_log_once_globally",
|
||||
"enable_periodic_logging",
|
||||
"get_actor",
|
||||
"iter",
|
||||
"log_once",
|
||||
"register_actor",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import time
|
||||
|
||||
_logged = set()
|
||||
_disabled = False
|
||||
_periodic_log = False
|
||||
_last_logged = 0.0
|
||||
|
||||
|
||||
def log_once(key):
|
||||
"""Returns True if this is the "first" call for a given key.
|
||||
|
||||
Various logging settings can adjust the definition of "first".
|
||||
|
||||
Example:
|
||||
>>> if log_once("some_key"):
|
||||
... logger.info("Some verbose logging statement")
|
||||
"""
|
||||
|
||||
global _last_logged
|
||||
|
||||
if _disabled:
|
||||
return False
|
||||
elif key not in _logged:
|
||||
_logged.add(key)
|
||||
_last_logged = time.time()
|
||||
return True
|
||||
elif _periodic_log and time.time() - _last_logged > 60.0:
|
||||
_logged.clear()
|
||||
_last_logged = time.time()
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def disable_log_once_globally():
|
||||
"""Make log_once() return False in this process."""
|
||||
|
||||
global _disabled
|
||||
_disabled = True
|
||||
|
||||
|
||||
def enable_periodic_logging():
|
||||
"""Make log_once() periodically return True in this process."""
|
||||
|
||||
global _periodic_log
|
||||
_periodic_log = True
|
||||
Reference in New Issue
Block a user