Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[air] Deprecate some fields/classes that are supposed to be gone in 2.6. #38794

Merged
merged 14 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[air] Deprecate some fields/classes that are supposed to be gone in 2.6.
Signed-off-by: xwjiang2010 <xwjiang2010@gmail.com>
  • Loading branch information
xwjiang2010 committed Aug 23, 2023
commit 1121f952443739edeabc53e482659c2f1e82c52e
50 changes: 1 addition & 49 deletions python/ray/air/integrations/keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ray
from ray.train._internal.storage import _use_storage_context
from ray.train.tensorflow import TensorflowCheckpoint, LegacyTensorflowCheckpoint
from ray.util.annotations import PublicAPI, Deprecated
from ray.util.annotations import PublicAPI


class _Callback(KerasCallback):
Expand Down Expand Up @@ -183,51 +183,3 @@ def _get_reported_metrics(self, logs: Dict) -> Dict:

assert isinstance(reported_metrics, dict)
return reported_metrics


@Deprecated
class Callback(_Callback):
"""
Keras callback for Ray AIR reporting and checkpointing.

You can use this in both TuneSession and TrainSession.

Example:
.. code-block: python

############# Using it in TrainSession ###############
from ray.air.integrations.keras import Callback
def train_loop_per_worker():
strategy = tf.distribute.MultiWorkerMirroredStrategy()
with strategy.scope():
model = build_model()
#model.compile(...)
model.fit(dataset_shard, callbacks=[Callback()])

Args:
metrics: Metrics to report. If this is a list, each item describes
the metric key reported to Keras, and it will reported under the
same name. If this is a dict, each key will be the name reported
and the respective value will be the metric key reported to Keras.
If this is None, all Keras logs will be reported.
on: When to report metrics. Must be one of
the Keras event hooks (less the ``on_``), e.g.
"train_start", or "predict_end". Defaults to "epoch_end".
frequency: Checkpoint frequency. If this is an integer `n`,
checkpoints are saved every `n` times each hook was called. If
this is a list, it specifies the checkpoint frequencies for each
hook individually.

"""

def __init__(
self,
metrics: Optional[Union[str, List[str], Dict[str, str]]] = None,
on: Union[str, List[str]] = "epoch_end",
frequency: Union[int, List[int]] = 1,
):
# TODO: Remove this class in 2.6.
raise DeprecationWarning(
"`ray.air.integrations.keras.Callback` is deprecated. Use "
"`ray.air.integrations.keras.ReportCheckpointCallback` instead.",
)
18 changes: 0 additions & 18 deletions python/ray/air/result.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import json
import pandas as pd
import warnings
from dataclasses import dataclass
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple, Union
Expand All @@ -13,7 +12,6 @@
EXPR_PROGRESS_FILE,
EXPR_ERROR_PICKLE_FILE,
)
from ray.util import log_once
from ray.util.annotations import PublicAPI

import logging
Expand Down Expand Up @@ -57,22 +55,6 @@ class Result:
_local_path: Optional[str] = None
_remote_path: Optional[str] = None
_items_to_repr = ["error", "metrics", "path", "checkpoint"]
# Deprecate: raise in 2.5, remove in 2.6
log_dir: Optional[Path] = None

def __post_init__(self):
if self.log_dir and log_once("result_log_dir_deprecated"):
warnings.warn(
"The `Result.log_dir` property is deprecated. "
"Use `local_path` instead."
)
self._local_path = str(self.log_dir)

# Duplicate for retrieval
self.log_dir = Path(self._local_path) if self._local_path else None
# Backwards compatibility: Make sure to cast Path to string
# Deprecate: Remove this line after 2.6
self._local_path = str(self._local_path) if self._local_path else None

@property
def config(self) -> Optional[Dict[str, Any]]:
Expand Down
8 changes: 0 additions & 8 deletions python/ray/train/tensorflow/tensorflow_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ def from_saved_model(
def get_model(
self,
model: Optional[Union[tf.keras.Model, Callable[[], tf.keras.Model]]] = None,
model_definition: Optional[Callable[[], tf.keras.Model]] = None,
) -> tf.keras.Model:
"""Retrieve the model stored in this checkpoint.

Expand All @@ -308,13 +307,6 @@ def get_model(
Returns:
The Tensorflow Keras model stored in the checkpoint.
"""
# TODO: Remove `model_definition` in 2.6.
if model_definition is not None:
raise DeprecationWarning(
"The `model_definition` parameter is deprecated. Use the `model` "
"parameter instead."
)

if model is not None and self._flavor is not self.Flavor.MODEL_WEIGHTS:
warnings.warn(
"TensorflowCheckpoint was created from "
Expand Down