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)) 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) 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..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,17 +12,14 @@ # 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 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 @@ -323,48 +320,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):