From f6614b370c4230c305a1ea6dfe4f5f75c62b8297 Mon Sep 17 00:00:00 2001 From: "B. Kerim Tshimanga" Date: Tue, 31 Aug 2021 02:30:43 -0700 Subject: [PATCH] =?UTF-8?q?scheduled=20removal=20of=20BaseProfiler.output?= =?UTF-8?q?=5Ffilename=20in=20favor=20of=20dirpath=E2=80=A6=20(#9214)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 +++++ pytorch_lightning/profiler/__init__.py | 2 +- pytorch_lightning/profiler/advanced.py | 3 +-- pytorch_lightning/profiler/base.py | 10 ---------- pytorch_lightning/profiler/pytorch.py | 3 +-- pytorch_lightning/profiler/simple.py | 3 +-- pytorch_lightning/profiler/xla.py | 2 +- tests/deprecated_api/test_remove_1-5.py | 10 ---------- 8 files changed, 10 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f48f1c3f7..69c194bfac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -241,8 +241,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Removed deprecated property `Trainer.running_sanity_check` in favor of `Trainer.sanity_checking` ([#9209](https://github.com/PyTorchLightning/pytorch-lightning/pull/9209)) +- Removed deprecated `BaseProfiler.output_filename` arg from it and its descendants in favor of `dirpath` and `filename` ([#9214](https://github.com/PyTorchLightning/pytorch-lightning/pull/9214)) + + - Removed deprecated property `ModelCheckpoint.period` in favor of `ModelCheckpoint.every_n_epochs` ([#9213](https://github.com/PyTorchLightning/pytorch-lightning/pull/9213)) + + ### Fixed - Fixed save/load/resume from checkpoint for DeepSpeed Plugin ( diff --git a/pytorch_lightning/profiler/__init__.py b/pytorch_lightning/profiler/__init__.py index f8f537b6ad..e2021d9f67 100644 --- a/pytorch_lightning/profiler/__init__.py +++ b/pytorch_lightning/profiler/__init__.py @@ -67,7 +67,7 @@ This option uses Python's cProfiler_ to provide a report of time spent on *each* trainer = Trainer(..., profiler=profiler) The profiler's results will be printed at the completion of a training `fit()`. This profiler -report can be quite long, so you can also specify an `output_filename` to save the report instead +report can be quite long, so you can also specify a `dirpath` and `filename` to save the report instead of logging it to the output in your terminal. The output below shows the profiling for the action `get_train_batch`. diff --git a/pytorch_lightning/profiler/advanced.py b/pytorch_lightning/profiler/advanced.py index fa9422ae9b..01531e1514 100644 --- a/pytorch_lightning/profiler/advanced.py +++ b/pytorch_lightning/profiler/advanced.py @@ -36,7 +36,6 @@ class AdvancedProfiler(BaseProfiler): dirpath: Optional[Union[str, Path]] = None, filename: Optional[str] = None, line_count_restriction: float = 1.0, - output_filename: Optional[str] = None, ) -> None: """ Args: @@ -55,7 +54,7 @@ class AdvancedProfiler(BaseProfiler): ValueError: If you attempt to stop recording an action which was never started. """ - super().__init__(dirpath=dirpath, filename=filename, output_filename=output_filename) + super().__init__(dirpath=dirpath, filename=filename) self.profiled_actions: Dict[str, cProfile.Profile] = {} self.line_count_restriction = line_count_restriction diff --git a/pytorch_lightning/profiler/base.py b/pytorch_lightning/profiler/base.py index af885efe28..7c06cb8fe4 100644 --- a/pytorch_lightning/profiler/base.py +++ b/pytorch_lightning/profiler/base.py @@ -19,7 +19,6 @@ from contextlib import contextmanager from pathlib import Path from typing import Any, Callable, Dict, Generator, Iterable, Optional, TextIO, Union -from pytorch_lightning.utilities import rank_zero_deprecation from pytorch_lightning.utilities.cloud_io import get_filesystem log = logging.getLogger(__name__) @@ -58,18 +57,9 @@ class BaseProfiler(AbstractProfiler): self, dirpath: Optional[Union[str, Path]] = None, filename: Optional[str] = None, - output_filename: Optional[str] = None, ) -> None: self.dirpath = dirpath self.filename = filename - if output_filename is not None: - rank_zero_deprecation( - "`Profiler` signature has changed in v1.3. The `output_filename` parameter has been removed in" - " favor of `dirpath` and `filename`. Support for the old signature will be removed in v1.5" - ) - filepath = Path(output_filename) - self.dirpath = filepath.parent - self.filename = filepath.stem self._output_file: Optional[TextIO] = None self._write_stream: Optional[Callable] = None diff --git a/pytorch_lightning/profiler/pytorch.py b/pytorch_lightning/profiler/pytorch.py index a196495a2b..f6ae7a8def 100644 --- a/pytorch_lightning/profiler/pytorch.py +++ b/pytorch_lightning/profiler/pytorch.py @@ -222,7 +222,6 @@ class PyTorchProfiler(BaseProfiler): sort_by_key: Optional[str] = None, record_functions: Set[str] = None, record_module_names: bool = True, - output_filename: Optional[str] = None, **profiler_kwargs: Any, ) -> None: """ @@ -274,7 +273,7 @@ class PyTorchProfiler(BaseProfiler): If arg ``schedule`` is not a ``Callable``. If arg ``schedule`` does not return a ``torch.profiler.ProfilerAction``. """ - super().__init__(dirpath=dirpath, filename=filename, output_filename=output_filename) + super().__init__(dirpath=dirpath, filename=filename) self._group_by_input_shapes = group_by_input_shapes and profiler_kwargs.get("record_shapes", False) self._emit_nvtx = emit_nvtx diff --git a/pytorch_lightning/profiler/simple.py b/pytorch_lightning/profiler/simple.py index 8616f72345..37570fdb44 100644 --- a/pytorch_lightning/profiler/simple.py +++ b/pytorch_lightning/profiler/simple.py @@ -37,7 +37,6 @@ class SimpleProfiler(BaseProfiler): dirpath: Optional[Union[str, Path]] = None, filename: Optional[str] = None, extended: bool = True, - output_filename: Optional[str] = None, ) -> None: """ Args: @@ -53,7 +52,7 @@ class SimpleProfiler(BaseProfiler): If you attempt to start an action which has already started, or if you attempt to stop recording an action which was never started. """ - super().__init__(dirpath=dirpath, filename=filename, output_filename=output_filename) + super().__init__(dirpath=dirpath, filename=filename) self.current_actions: Dict[str, float] = {} self.recorded_durations = defaultdict(list) self.extended = extended diff --git a/pytorch_lightning/profiler/xla.py b/pytorch_lightning/profiler/xla.py index b96fa566f2..402dfbd6ca 100644 --- a/pytorch_lightning/profiler/xla.py +++ b/pytorch_lightning/profiler/xla.py @@ -69,7 +69,7 @@ class XLAProfiler(BaseProfiler): This Profiler will help you debug and optimize training workload performance for your models using Cloud TPU performance tools. """ - super().__init__(dirpath=None, filename=None, output_filename=None) + super().__init__(dirpath=None, filename=None) self.port = port self._recording_map: Dict = {} self._step_recoding_map: Dict = {} diff --git a/tests/deprecated_api/test_remove_1-5.py b/tests/deprecated_api/test_remove_1-5.py index 8f0c4a6482..bf905f8265 100644 --- a/tests/deprecated_api/test_remove_1-5.py +++ b/tests/deprecated_api/test_remove_1-5.py @@ -17,21 +17,11 @@ import pytest from pytorch_lightning import Trainer from pytorch_lightning.core.decorators import auto_move_data from pytorch_lightning.plugins import DeepSpeedPlugin -from pytorch_lightning.profiler import AdvancedProfiler, BaseProfiler, PyTorchProfiler, SimpleProfiler from tests.deprecated_api import no_deprecated_call from tests.helpers import BoringDataModule, BoringModel from tests.helpers.runif import RunIf -@pytest.mark.parametrize("cls", (BaseProfiler, SimpleProfiler, AdvancedProfiler, PyTorchProfiler)) -def test_v1_5_0_profiler_output_filename(tmpdir, cls): - filepath = str(tmpdir / "test.txt") - with pytest.deprecated_call(match="`output_filename` parameter has been removed"): - profiler = cls(output_filename=filepath) - assert profiler.dirpath == tmpdir - assert profiler.filename == "test" - - def test_v1_5_0_auto_move_data(): with pytest.deprecated_call(match="deprecated in v1.3 and will be removed in v1.5.*was applied to `bar`"):