From b566a67f8a334ccd1d85552d930f94ec4c0eb375 Mon Sep 17 00:00:00 2001 From: Tshimanga Date: Mon, 30 Aug 2021 18:02:20 -0700 Subject: [PATCH 1/5] scheduled removal of BaseProfiler.output_filename in favor of dirpath and filename --- pytorch_lightning/profiler/__init__.py | 2 +- pytorch_lightning/profiler/advanced.py | 3 +-- pytorch_lightning/profiler/base.py | 9 --------- 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 | 9 --------- 7 files changed, 5 insertions(+), 26 deletions(-) diff --git a/pytorch_lightning/profiler/__init__.py b/pytorch_lightning/profiler/__init__.py index f8f537b6ad3a3..e2021d9f6734b 100644 --- a/pytorch_lightning/profiler/__init__.py +++ b/pytorch_lightning/profiler/__init__.py @@ -67,7 +67,7 @@ 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 fa9422ae9b992..01531e15141e6 100644 --- a/pytorch_lightning/profiler/advanced.py +++ b/pytorch_lightning/profiler/advanced.py @@ -36,7 +36,6 @@ def __init__( 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 @@ def __init__( 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 af885efe28ae7..b6780838902fc 100644 --- a/pytorch_lightning/profiler/base.py +++ b/pytorch_lightning/profiler/base.py @@ -58,18 +58,9 @@ def __init__( 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 a196495a2b720..f6ae7a8defd9e 100644 --- a/pytorch_lightning/profiler/pytorch.py +++ b/pytorch_lightning/profiler/pytorch.py @@ -222,7 +222,6 @@ def __init__( 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 @@ def __init__( 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 8616f723457ab..37570fdb44d01 100644 --- a/pytorch_lightning/profiler/simple.py +++ b/pytorch_lightning/profiler/simple.py @@ -37,7 +37,6 @@ def __init__( dirpath: Optional[Union[str, Path]] = None, filename: Optional[str] = None, extended: bool = True, - output_filename: Optional[str] = None, ) -> None: """ Args: @@ -53,7 +52,7 @@ def __init__( 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 b96fa566f21cb..402dfbd6ca0b8 100644 --- a/pytorch_lightning/profiler/xla.py +++ b/pytorch_lightning/profiler/xla.py @@ -69,7 +69,7 @@ def __init__(self, port: int = 9012) -> None: 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 735574dda1a23..bfa2ca82b0a70 100644 --- a/tests/deprecated_api/test_remove_1-5.py +++ b/tests/deprecated_api/test_remove_1-5.py @@ -32,15 +32,6 @@ def test_v1_5_0_model_checkpoint_period(tmpdir): ModelCheckpoint(dirpath=tmpdir, period=1) -@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`"): From f07b4db9a01cabe7acede2401c628b2844772caa Mon Sep 17 00:00:00 2001 From: Tshimanga Date: Mon, 30 Aug 2021 18:06:21 -0700 Subject: [PATCH 2/5] update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b193c190a3131..b32552a36b001 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -240,6 +240,9 @@ 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 descendents in favor of `dirpath` and `filename` ([#9214](https://github.com/PyTorchLightning/pytorch-lightning/pull/9214)) + ### Fixed - Fixed save/load/resume from checkpoint for DeepSpeed Plugin ( From 437e671201eff024afac2be077e0be1273c77133 Mon Sep 17 00:00:00 2001 From: Tshimanga Date: Mon, 30 Aug 2021 19:35:20 -0700 Subject: [PATCH 3/5] remove unused imports caught by linter --- tests/deprecated_api/test_remove_1-5.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/deprecated_api/test_remove_1-5.py b/tests/deprecated_api/test_remove_1-5.py index bfa2ca82b0a70..fcb6b635e51bf 100644 --- a/tests/deprecated_api/test_remove_1-5.py +++ b/tests/deprecated_api/test_remove_1-5.py @@ -18,7 +18,6 @@ from pytorch_lightning.callbacks import ModelCheckpoint 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 From fe6fd18e1e4d457633a2061b301e4db58d0068bb Mon Sep 17 00:00:00 2001 From: Tshimanga Date: Mon, 30 Aug 2021 19:40:11 -0700 Subject: [PATCH 4/5] sigh... one last unused import --- pytorch_lightning/profiler/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pytorch_lightning/profiler/base.py b/pytorch_lightning/profiler/base.py index b6780838902fc..7c06cb8fe4cfa 100644 --- a/pytorch_lightning/profiler/base.py +++ b/pytorch_lightning/profiler/base.py @@ -19,7 +19,6 @@ 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__) From 5a27adbdeb5ec66a2ca361a90c51eed2a77949d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20W=C3=A4lchli?= Date: Tue, 31 Aug 2021 10:01:35 +0200 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b32552a36b001..b7afcb92d9387 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -241,7 +241,7 @@ 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 descendents in favor of `dirpath` and `filename` ([#9214](https://github.com/PyTorchLightning/pytorch-lightning/pull/9214)) +- 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)) ### Fixed