Skip to content

Commit

Permalink
[AIR] Deprecate ray.tune.logger.Logger interface (#35162)
Browse files Browse the repository at this point in the history
This PR deprecates:
1. Soft-deprecated, for removal in 2.7.
    - `ray.tune.logger.Logger`, in favor of `ray.tune.logger.LoggerCallback`
         - Also, deprecated any built-in `Logger` subclasses, including `CSVLogger`, `JsonLogger`, `TBXLogger`, etc.

Signed-off-by: Justin Yu <[email protected]>
  • Loading branch information
justinvyu authored May 15, 2023
1 parent 6088de3 commit 5d0b15e
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 17 deletions.
2 changes: 1 addition & 1 deletion python/ray/air/integrations/mlflow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import warnings
from types import ModuleType
from typing import Dict, Optional, Union
import warnings

import ray
from ray.air import session
Expand Down
4 changes: 2 additions & 2 deletions python/ray/tune/integration/comet.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ def __init__(
save_checkpoints: bool = False,
**experiment_kwargs
):
logging.warning(callback_deprecation_message)
super().__init__(online, tags, save_checkpoints, **experiment_kwargs)
# TODO(ml-team): Remove in 2.6.
raise DeprecationWarning(callback_deprecation_message)
10 changes: 8 additions & 2 deletions python/ray/tune/logger/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@

from typing import TYPE_CHECKING, Dict, TextIO

from ray.tune.logger.logger import Logger, LoggerCallback
from ray.tune.logger.logger import _LOGGER_DEPRECATION_WARNING, Logger, LoggerCallback
from ray.tune.result import EXPR_PROGRESS_FILE
from ray.tune.utils import flatten_dict
from ray.util.annotations import PublicAPI
from ray.util.annotations import Deprecated, PublicAPI

if TYPE_CHECKING:
from ray.tune.experiment.trial import Trial # noqa: F401

logger = logging.getLogger(__name__)


@Deprecated(
message=_LOGGER_DEPRECATION_WARNING.format(
old="CSVLogger", new="ray.tune.csv.CSVLoggerCallback"
),
warning=True,
)
@PublicAPI
class CSVLogger(Logger):
"""Logs results to progress.csv under the trial directory.
Expand Down
10 changes: 8 additions & 2 deletions python/ray/tune/logger/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import ray.cloudpickle as cloudpickle

from ray.tune.logger.logger import Logger, LoggerCallback
from ray.tune.logger.logger import _LOGGER_DEPRECATION_WARNING, Logger, LoggerCallback
from ray.tune.utils.util import SafeFallbackEncoder
from ray.tune.result import (
EXPR_PARAM_FILE,
EXPR_PARAM_PICKLE_FILE,
EXPR_RESULT_FILE,
)
from ray.util.annotations import PublicAPI
from ray.util.annotations import Deprecated, PublicAPI

if TYPE_CHECKING:
from ray.tune.experiment.trial import Trial # noqa: F401
Expand All @@ -25,6 +25,12 @@
VALID_SUMMARY_TYPES = [int, float, np.float32, np.float64, np.int32, np.int64]


@Deprecated(
message=_LOGGER_DEPRECATION_WARNING.format(
old="JsonLogger", new="ray.tune.json.JsonLoggerCallback"
),
warning=True,
)
@PublicAPI
class JsonLogger(Logger):
"""Logs trial results in json format.
Expand Down
12 changes: 11 additions & 1 deletion python/ray/tune/logger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import yaml
from ray.air._internal.json import SafeFallbackEncoder
from ray.tune.callback import Callback
from ray.util.annotations import PublicAPI, DeveloperAPI
from ray.util.annotations import Deprecated, DeveloperAPI, PublicAPI

if TYPE_CHECKING:
from ray.tune.experiment.trial import Trial # noqa: F401
Expand All @@ -18,7 +18,17 @@
# Apply flow style for sequences of this length
_SEQUENCE_LEN_FLOW_STYLE = 3

_LOGGER_DEPRECATION_WARNING = (
"The `{old} interface is deprecated in favor of the "
"`{new}` interface and will be removed in Ray 2.7."
)


@Deprecated(
message=_LOGGER_DEPRECATION_WARNING.format(
old="Logger", new="ray.tune.logger.LoggerCallback"
),
)
@DeveloperAPI
class Logger(abc.ABC):
"""Logging interface for ray.tune.
Expand Down
3 changes: 2 additions & 1 deletion python/ray/tune/logger/noop.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from ray.tune.logger.logger import Logger
from ray.util.annotations import PublicAPI
from ray.util.annotations import Deprecated, PublicAPI


@Deprecated(message="`NoopLogger` will be removed in Ray 2.7.")
@PublicAPI
class NoopLogger(Logger):
def on_result(self, result):
Expand Down
10 changes: 8 additions & 2 deletions python/ray/tune/logger/tensorboardx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

from typing import TYPE_CHECKING, Dict

from ray.tune.logger.logger import Logger, LoggerCallback
from ray.tune.logger.logger import _LOGGER_DEPRECATION_WARNING, Logger, LoggerCallback
from ray.util.debug import log_once
from ray.tune.result import (
TRAINING_ITERATION,
TIME_TOTAL_S,
TIMESTEPS_TOTAL,
)
from ray.tune.utils import flatten_dict
from ray.util.annotations import PublicAPI
from ray.util.annotations import Deprecated, PublicAPI

if TYPE_CHECKING:
from ray.tune.experiment.trial import Trial # noqa: F401
Expand All @@ -21,6 +21,12 @@
VALID_SUMMARY_TYPES = [int, float, np.float32, np.float64, np.int32, np.int64]


@Deprecated(
message=_LOGGER_DEPRECATION_WARNING.format(
old="TBXLogger", new="ray.tune.tensorboardx.TBXLoggerCallback"
),
warning=True,
)
@PublicAPI
class TBXLogger(Logger):
"""TensorBoardX Logger.
Expand Down
4 changes: 3 additions & 1 deletion python/ray/tune/logger/unified.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from ray.tune.logger import DEFAULT_LOGGERS
from ray.tune.logger.json import JsonLogger
from ray.tune.logger.logger import Logger
from ray.util import log_once, PublicAPI
from ray.util import log_once
from ray.util.annotations import Deprecated, PublicAPI

logger = logging.getLogger(__name__)

Expand All @@ -13,6 +14,7 @@
from ray.tune.experiment.trial import Trial # noqa: F401


@Deprecated(message="`UnifiedLogger` will be removed in Ray 2.7.", warning=True)
@PublicAPI
class UnifiedLogger(Logger):
"""Unified result logger for TensorBoard, rllab/viskit, plain json.
Expand Down
11 changes: 6 additions & 5 deletions python/ray/tune/trainable/trainable.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import tempfile
import time
from contextlib import redirect_stderr, redirect_stdout
from typing import Any, Callable, Dict, List, Optional, Union, Type, TYPE_CHECKING
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union, Type
import warnings

import ray
Expand Down Expand Up @@ -108,10 +108,10 @@ class Trainable:
def __init__(
self,
config: Dict[str, Any] = None,
logger_creator: Callable[[Dict[str, Any]], "Logger"] = None,
logger_creator: Callable[[Dict[str, Any]], "Logger"] = None, # Deprecated (2.7)
remote_checkpoint_dir: Optional[str] = None,
custom_syncer: Optional[Syncer] = None, # Deprecated
sync_timeout: Optional[int] = None, # Deprecated
custom_syncer: Optional[Syncer] = None, # Deprecated (2.6)
sync_timeout: Optional[int] = None, # Deprecated (2.6)
sync_config: Optional[SyncConfig] = None,
):
"""Initialize a Trainable.
Expand All @@ -125,7 +125,7 @@ def __init__(
Args:
config: Trainable-specific configuration data. By default
will be saved as ``self.config``.
logger_creator: Function that creates a ray.tune.Logger
logger_creator: (Deprecated) Function that creates a ray.tune.Logger
object. If unspecified, a default logger is created.
remote_checkpoint_dir: Upload directory (S3 or GS path).
This is **per trial** directory,
Expand All @@ -140,6 +140,7 @@ def __init__(
if self.is_actor():
disable_ipython()

# TODO(ml-team): Remove `logger_creator` in 2.7.
self._result_logger = self._logdir = None
self._create_logger(self.config, logger_creator)

Expand Down

0 comments on commit 5d0b15e

Please sign in to comment.