diff --git a/doc/source/train/getting-started-pytorch-lightning.rst b/doc/source/train/getting-started-pytorch-lightning.rst index 8768095bd23e..00b8af39828e 100644 --- a/doc/source/train/getting-started-pytorch-lightning.rst +++ b/doc/source/train/getting-started-pytorch-lightning.rst @@ -356,7 +356,7 @@ information about the training run, including the metrics and checkpoints report result.metrics # The metrics reported during training. result.checkpoint # The latest checkpoint reported during training. - result.log_dir # The path where logs are stored. + result.path # The path where logs are stored. result.error # The exception that was raised, if training failed. .. TODO: Add results guide diff --git a/doc/source/train/getting-started-pytorch.rst b/doc/source/train/getting-started-pytorch.rst index 8ecb0a6bac54..b903ac7937c1 100644 --- a/doc/source/train/getting-started-pytorch.rst +++ b/doc/source/train/getting-started-pytorch.rst @@ -278,7 +278,7 @@ information about the training run, including the metrics and checkpoints report result.metrics # The metrics reported during training. result.checkpoint # The latest checkpoint reported during training. - result.log_dir # The path where logs are stored. + result.path # The path where logs are stored. result.error # The exception that was raised, if training failed. .. TODO: Add results guide diff --git a/doc/source/train/getting-started-transformers.rst b/doc/source/train/getting-started-transformers.rst index dfcb80145dff..9c9f84081b95 100644 --- a/doc/source/train/getting-started-transformers.rst +++ b/doc/source/train/getting-started-transformers.rst @@ -280,7 +280,7 @@ information about the training run, including the metrics and checkpoints report result.metrics # The metrics reported during training. result.checkpoint # The latest checkpoint reported during training. - result.log_dir # The path where logs are stored. + result.path # The path where logs are stored. result.error # The exception that was raised, if training failed. .. TODO: Add results guide diff --git a/doc/source/tune/doc_code/key_concepts.py b/doc/source/tune/doc_code/key_concepts.py index 404fa3fa304b..98c2b8417e38 100644 --- a/doc/source/tune/doc_code/key_concepts.py +++ b/doc/source/tune/doc_code/key_concepts.py @@ -148,7 +148,7 @@ def load_checkpoint(self, checkpoint_dir): best_result = results.get_best_result() # Get best result object best_config = best_result.config # Get best trial's hyperparameters -best_logdir = best_result.log_dir # Get best trial's logdir +best_logdir = best_result.path # Get best trial's result directory best_checkpoint = best_result.checkpoint # Get best trial's best checkpoint best_metrics = best_result.metrics # Get best trial's last results best_result_df = best_result.metrics_dataframe # Get best result as pandas dataframe diff --git a/doc/source/tune/examples/pbt_guide.ipynb b/doc/source/tune/examples/pbt_guide.ipynb index 70cf24575082..8f0700a1d572 100644 --- a/doc/source/tune/examples/pbt_guide.ipynb +++ b/doc/source/tune/examples/pbt_guide.ipynb @@ -285,8 +285,8 @@ "# Get the best trial result\n", "best_result = results_grid.get_best_result(metric=\"mean_accuracy\", mode=\"max\")\n", "\n", - "# Print `log_dir` where checkpoints are stored\n", - "print(\"Best result logdir:\", best_result.log_dir)\n", + "# Print `path` where checkpoints are stored\n", + "print('Best result path:', best_result.path)\n", "\n", "# Print the best trial `config` reported at the last iteration\n", "# NOTE: This config is just what the trial ended up with at the last iteration.\n", diff --git a/python/ray/air/integrations/keras.py b/python/ray/air/integrations/keras.py index a4e147f40c53..f37c562efa66 100644 --- a/python/ray/air/integrations/keras.py +++ b/python/ray/air/integrations/keras.py @@ -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): @@ -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.", - ) diff --git a/python/ray/air/result.py b/python/ray/air/result.py index baef4fbd0fac..43d19793839c 100644 --- a/python/ray/air/result.py +++ b/python/ray/air/result.py @@ -2,7 +2,6 @@ import json import pandas as pd import pyarrow -import warnings from dataclasses import dataclass from pathlib import Path from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union @@ -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 @@ -60,22 +58,6 @@ class Result: _remote_path: Optional[str] = None _storage_filesystem: Optional[pyarrow.fs.FileSystem] = None _items_to_repr = ["error", "metrics", "path", "filesystem", "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]]: diff --git a/python/ray/air/tests/test_keras_callback.py b/python/ray/air/tests/test_keras_callback.py index a70b8abe9970..fdeb494e3480 100644 --- a/python/ray/air/tests/test_keras_callback.py +++ b/python/ray/air/tests/test_keras_callback.py @@ -7,7 +7,7 @@ import ray from ray import train -from ray.air.integrations.keras import Callback, ReportCheckpointCallback +from ray.air.integrations.keras import ReportCheckpointCallback from ray.train.constants import TRAIN_DATASET_KEY from ray.train import ScalingConfig from ray.train.tensorflow import ( @@ -207,11 +207,6 @@ def test_keras_callback_e2e(): predictor.predict(data=items) -def test_keras_callback_is_deprecated(): - with pytest.raises(DeprecationWarning): - Callback() - - if __name__ == "__main__": import sys diff --git a/python/ray/train/examples/mlflow_simple_example.py b/python/ray/train/examples/mlflow_simple_example.py index 7b45edfdace8..acb842f45652 100644 --- a/python/ray/train/examples/mlflow_simple_example.py +++ b/python/ray/train/examples/mlflow_simple_example.py @@ -1,3 +1,4 @@ +from pathlib import Path from ray import train from ray.train import ScalingConfig, RunConfig from ray.train.torch import TorchTrainer @@ -41,7 +42,7 @@ def train_func(): # Print the latest run directory and keep note of it. # For example: /home/ubuntu/ray_results/TorchTrainer_2022-06-13_20-31-06 -print("Run directory:", result.log_dir.parent) # TensorBoard is saved in parent dir +print("Run directory:", Path(result.path).parent) # TensorBoard is saved in parent dir # How to visualize the logs diff --git a/python/ray/train/tensorflow/tensorflow_checkpoint.py b/python/ray/train/tensorflow/tensorflow_checkpoint.py index 23a9c25f6ad1..cc2c26692e35 100644 --- a/python/ray/train/tensorflow/tensorflow_checkpoint.py +++ b/python/ray/train/tensorflow/tensorflow_checkpoint.py @@ -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. @@ -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 " diff --git a/python/ray/train/tests/test_lightning_trainer_restore.py b/python/ray/train/tests/test_lightning_trainer_restore.py index 25889fa674d7..54f0686f468b 100644 --- a/python/ray/train/tests/test_lightning_trainer_restore.py +++ b/python/ray/train/tests/test_lightning_trainer_restore.py @@ -1,8 +1,8 @@ import os import numpy as np +from pathlib import Path import pytest import pytorch_lightning as pl -from pathlib import Path from pytorch_lightning.callbacks import ModelCheckpoint import ray diff --git a/python/ray/tune/tests/test_tuner.py b/python/ray/tune/tests/test_tuner.py index 8c8204ff12ec..3162be3c2294 100644 --- a/python/ray/tune/tests/test_tuner.py +++ b/python/ray/tune/tests/test_tuner.py @@ -423,7 +423,7 @@ def train_func(config): results = tuner.fit() assert not results.errors for result in results: - artifact_data = open(result.log_dir / "write.txt", "r").read() + artifact_data = open(os.path.join(result.path, "write.txt"), "r").read() assert artifact_data == f"{result.config['id']}" @@ -467,7 +467,7 @@ def train_func(config): results = tuner.fit() assert not results.errors for result in results: - artifact_data = open(result.log_dir / "write.txt", "r").read() + artifact_data = open(os.path.join(result.path, "write.txt"), "r").read() assert artifact_data == f"{result.config['id']}" diff --git a/python/ray/tune/tests/test_tuner_restore.py b/python/ray/tune/tests/test_tuner_restore.py index b023625c37d8..e010a6a7f258 100644 --- a/python/ray/tune/tests/test_tuner_restore.py +++ b/python/ray/tune/tests/test_tuner_restore.py @@ -915,6 +915,7 @@ def failing_fn(config): if path.startswith("experiment_state") ] ) + assert num_experiment_checkpoints == 2 num_trial_checkpoints = len( diff --git a/python/ray/tune/tests/tutorial.py b/python/ray/tune/tests/tutorial.py index 79a18862b1c1..42ac835e9ce6 100644 --- a/python/ray/tune/tests/tutorial.py +++ b/python/ray/tune/tests/tutorial.py @@ -133,7 +133,7 @@ def train_mnist(config): # __eval_func_end__ # __plot_begin__ -dfs = {result.log_dir: result.metrics_dataframe for result in results} +dfs = {result.path: result.metrics_dataframe for result in results} [d.mean_accuracy.plot() for d in dfs.values()] # __plot_end__ @@ -149,7 +149,7 @@ def train_mnist(config): results = tuner.fit() # Obtain a trial dataframe from all run trials of this `tune.run` call. -dfs = {result.log_dir: result.metrics_dataframe for result in results} +dfs = {result.path: result.metrics_dataframe for result in results} # __run_scheduler_end__ # fmt: off @@ -190,7 +190,7 @@ def train_mnist(config): # __run_analysis_begin__ import os -logdir = results.get_best_result("mean_accuracy", mode="max").log_dir +logdir = results.get_best_result("mean_accuracy", mode="max").path state_dict = torch.load(os.path.join(logdir, "model.pth")) model = ConvNet()