Remove the deprecated `profile_iterable` (#14864)

* remove profile_iterable
* remove imports
* remove depricated api
* update changelog

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Krishna Kalyan 2022-09-24 14:01:18 +02:00 committed by GitHub
parent abb6049fa3
commit d38633592d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 69 deletions

View File

@ -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))

View File

@ -17,10 +17,9 @@ import os
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 @@ class Profiler(ABC):
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)

View File

@ -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 test_v1_8_0_callback_on_pretrain_routine_start_end(tmpdir):
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):