From 127f646113a66a796a4f15efdd62453f3223cd5c Mon Sep 17 00:00:00 2001 From: krishna Date: Fri, 23 Sep 2022 11:41:01 +0200 Subject: [PATCH 1/6] remove profile_iterable --- .../deprecated_api/test_remove_1-8.py | 42 ------------------- 1 file changed, 42 deletions(-) diff --git a/tests/tests_pytorch/deprecated_api/test_remove_1-8.py b/tests/tests_pytorch/deprecated_api/test_remove_1-8.py index 7946dadaa9398..b0f88898917ab 100644 --- a/tests/tests_pytorch/deprecated_api/test_remove_1-8.py +++ b/tests/tests_pytorch/deprecated_api/test_remove_1-8.py @@ -323,48 +323,6 @@ def on_pretrain_routine_end(self, trainer, pl_module): trainer.fit(model) -@pytest.mark.flaky(reruns=3) -@pytest.mark.parametrize(["action", "expected"], [("a", [3, 1]), ("b", [2]), ("c", [1])]) -def test_simple_profiler_iterable_durations(tmpdir, action: str, expected: list): - """Ensure the reported durations are reasonably accurate.""" - - def _sleep_generator(durations): - """the profile_iterable method needs an iterable in which we can ensure that we're properly timing how long - it takes to call __next__""" - for duration in durations: - time.sleep(duration) - yield duration - - def _get_python_cprofile_total_duration(profile): - return sum(x.inlinetime for x in profile.getstats()) - - simple_profiler = SimpleProfiler() - iterable = _sleep_generator(expected) - - with pytest.deprecated_call( - match="`SimpleProfiler.profile_iterable` is deprecated in v1.6 and will be removed in v1.8." - ): - for _ in simple_profiler.profile_iterable(iterable, action): - pass - - # we exclude the last item in the recorded durations since that's when StopIteration is raised - np.testing.assert_allclose(simple_profiler.recorded_durations[action][:-1], expected, rtol=0.2) - - advanced_profiler = AdvancedProfiler(dirpath=tmpdir, filename="profiler") - - iterable = _sleep_generator(expected) - - with pytest.deprecated_call( - match="`AdvancedProfiler.profile_iterable` is deprecated in v1.6 and will be removed in v1.8." - ): - for _ in advanced_profiler.profile_iterable(iterable, action): - pass - - recorded_total_duration = _get_python_cprofile_total_duration(advanced_profiler.profiled_actions[action]) - expected_total_duration = np.sum(expected) - np.testing.assert_allclose(recorded_total_duration, expected_total_duration, rtol=0.2) - - def test_v1_8_0_datamodule_checkpointhooks(): class CustomBoringDataModuleSave(BoringDataModule): def on_save_checkpoint(self, checkpoint): From bb5ae1256a7b6fb22b28ab15275116d5ac5d1ff4 Mon Sep 17 00:00:00 2001 From: krishna Date: Fri, 23 Sep 2022 11:51:15 +0200 Subject: [PATCH 2/6] remove imports --- tests/tests_pytorch/deprecated_api/test_remove_1-8.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/tests_pytorch/deprecated_api/test_remove_1-8.py b/tests/tests_pytorch/deprecated_api/test_remove_1-8.py index b0f88898917ab..9ac66ac39caec 100644 --- a/tests/tests_pytorch/deprecated_api/test_remove_1-8.py +++ b/tests/tests_pytorch/deprecated_api/test_remove_1-8.py @@ -22,7 +22,6 @@ from pytorch_lightning import Callback, Trainer from pytorch_lightning.callbacks import ModelCheckpoint from pytorch_lightning.demos.boring_classes import BoringDataModule, BoringModel -from pytorch_lightning.profilers import AdvancedProfiler, SimpleProfiler from pytorch_lightning.strategies.ipu import LightningIPUModule from pytorch_lightning.trainer.configuration_validator import _check_datamodule_checkpoint_hooks from pytorch_lightning.trainer.states import RunningStage @@ -322,7 +321,6 @@ def on_pretrain_routine_end(self, trainer, pl_module): ): trainer.fit(model) - def test_v1_8_0_datamodule_checkpointhooks(): class CustomBoringDataModuleSave(BoringDataModule): def on_save_checkpoint(self, checkpoint): From 3ea8aa3f090824a4f622fe6b57213ddaac22fcee Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 23 Sep 2022 09:53:05 +0000 Subject: [PATCH 3/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/tests_pytorch/deprecated_api/test_remove_1-8.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tests_pytorch/deprecated_api/test_remove_1-8.py b/tests/tests_pytorch/deprecated_api/test_remove_1-8.py index 9ac66ac39caec..4b87d235a885e 100644 --- a/tests/tests_pytorch/deprecated_api/test_remove_1-8.py +++ b/tests/tests_pytorch/deprecated_api/test_remove_1-8.py @@ -321,6 +321,7 @@ def on_pretrain_routine_end(self, trainer, pl_module): ): trainer.fit(model) + def test_v1_8_0_datamodule_checkpointhooks(): class CustomBoringDataModuleSave(BoringDataModule): def on_save_checkpoint(self, checkpoint): From d70e2203ffbdef84ccc8b0e07296f52bb0d8731e Mon Sep 17 00:00:00 2001 From: krishna Date: Fri, 23 Sep 2022 11:56:17 +0200 Subject: [PATCH 4/6] remove depricated api --- src/pytorch_lightning/profilers/profiler.py | 25 +-------------------- 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/src/pytorch_lightning/profilers/profiler.py b/src/pytorch_lightning/profilers/profiler.py index 1dc91efc83bb1..55e5b4d2acc67 100644 --- a/src/pytorch_lightning/profilers/profiler.py +++ b/src/pytorch_lightning/profilers/profiler.py @@ -17,10 +17,9 @@ from abc import ABC, abstractmethod from contextlib import contextmanager from pathlib import Path -from typing import Any, Callable, Dict, Generator, Iterable, Optional, TextIO, Union +from typing import Any, Callable, Dict, Generator, Optional, TextIO, Union from lightning_lite.utilities.cloud_io import get_filesystem -from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation log = logging.getLogger(__name__) @@ -70,28 +69,6 @@ def profile(self, action_name: str) -> Generator: finally: self.stop(action_name) - def profile_iterable(self, iterable: Iterable, action_name: str) -> Generator: - """Profiles over each value of an iterable. - - See deprecation message below. - - .. deprecated:: v1.6 - `Profiler.profile_iterable` is deprecated in v1.6 and will be removed in v1.8. - """ - rank_zero_deprecation( - f"`{self.__class__.__name__}.profile_iterable` is deprecated in v1.6 and will be removed in v1.8." - ) - iterator = iter(iterable) - while True: - try: - self.start(action_name) - value = next(iterator) - self.stop(action_name) - yield value - except StopIteration: - self.stop(action_name) - break - def _rank_zero_info(self, *args: Any, **kwargs: Any) -> None: if self._local_rank in (None, 0): log.info(*args, **kwargs) From 7aa9be352b23c6bf3cd4b4e8b6c439db279758c3 Mon Sep 17 00:00:00 2001 From: krishna Date: Fri, 23 Sep 2022 12:00:22 +0200 Subject: [PATCH 5/6] update changelog --- src/pytorch_lightning/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pytorch_lightning/CHANGELOG.md b/src/pytorch_lightning/CHANGELOG.md index 3739bfcc42405..6085c026f9553 100644 --- a/src/pytorch_lightning/CHANGELOG.md +++ b/src/pytorch_lightning/CHANGELOG.md @@ -222,6 +222,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Removed the deprecated `Trainer.use_amp` and `LightningModule.use_amp` attributes ([#14832](https://github.com/Lightning-AI/lightning/pull/14832)) +- Removed the deprecated `SimpleProfiler.profile_iterable` and `AdvancedProfiler.profile_iterable` attributes ([#14864](https://github.com/Lightning-AI/lightning/pull/14864)) + + ### Fixed - Fixed an issue with `LightningLite.setup()` not setting the `.device` attribute correctly on the returned wrapper ([#14822](https://github.com/Lightning-AI/lightning/pull/14822)) From e41dc5901fd5be44ab905ff0a2d89a9e2f2912ec Mon Sep 17 00:00:00 2001 From: rohitgr7 Date: Sat, 24 Sep 2022 16:54:05 +0530 Subject: [PATCH 6/6] pep8 --- tests/tests_pytorch/deprecated_api/test_remove_1-8.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/tests_pytorch/deprecated_api/test_remove_1-8.py b/tests/tests_pytorch/deprecated_api/test_remove_1-8.py index 4b87d235a885e..a7ba047b05c7f 100644 --- a/tests/tests_pytorch/deprecated_api/test_remove_1-8.py +++ b/tests/tests_pytorch/deprecated_api/test_remove_1-8.py @@ -12,11 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. """Test deprecated functionality which will be removed in v1.8.0.""" -import time from unittest import mock from unittest.mock import Mock -import numpy as np import pytest from pytorch_lightning import Callback, Trainer