Skip to content

Commit d386335

Browse files
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>
1 parent abb6049 commit d386335

File tree

3 files changed

+4
-69
lines changed

3 files changed

+4
-69
lines changed

src/pytorch_lightning/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
222222
- Removed the deprecated `Trainer.use_amp` and `LightningModule.use_amp` attributes ([#14832](https://github.com/Lightning-AI/lightning/pull/14832))
223223

224224

225+
- Removed the deprecated `SimpleProfiler.profile_iterable` and `AdvancedProfiler.profile_iterable` attributes ([#14864](https://github.com/Lightning-AI/lightning/pull/14864))
226+
227+
225228
### Fixed
226229

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

src/pytorch_lightning/profilers/profiler.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
from abc import ABC, abstractmethod
1818
from contextlib import contextmanager
1919
from pathlib import Path
20-
from typing import Any, Callable, Dict, Generator, Iterable, Optional, TextIO, Union
20+
from typing import Any, Callable, Dict, Generator, Optional, TextIO, Union
2121

2222
from lightning_lite.utilities.cloud_io import get_filesystem
23-
from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation
2423

2524
log = logging.getLogger(__name__)
2625

@@ -70,28 +69,6 @@ def profile(self, action_name: str) -> Generator:
7069
finally:
7170
self.stop(action_name)
7271

73-
def profile_iterable(self, iterable: Iterable, action_name: str) -> Generator:
74-
"""Profiles over each value of an iterable.
75-
76-
See deprecation message below.
77-
78-
.. deprecated:: v1.6
79-
`Profiler.profile_iterable` is deprecated in v1.6 and will be removed in v1.8.
80-
"""
81-
rank_zero_deprecation(
82-
f"`{self.__class__.__name__}.profile_iterable` is deprecated in v1.6 and will be removed in v1.8."
83-
)
84-
iterator = iter(iterable)
85-
while True:
86-
try:
87-
self.start(action_name)
88-
value = next(iterator)
89-
self.stop(action_name)
90-
yield value
91-
except StopIteration:
92-
self.stop(action_name)
93-
break
94-
9572
def _rank_zero_info(self, *args: Any, **kwargs: Any) -> None:
9673
if self._local_rank in (None, 0):
9774
log.info(*args, **kwargs)

tests/tests_pytorch/deprecated_api/test_remove_1-8.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
"""Test deprecated functionality which will be removed in v1.8.0."""
15-
import time
1615
from unittest import mock
1716
from unittest.mock import Mock
1817

19-
import numpy as np
2018
import pytest
2119

2220
from pytorch_lightning import Callback, Trainer
2321
from pytorch_lightning.callbacks import ModelCheckpoint
2422
from pytorch_lightning.demos.boring_classes import BoringDataModule, BoringModel
25-
from pytorch_lightning.profilers import AdvancedProfiler, SimpleProfiler
2623
from pytorch_lightning.strategies.ipu import LightningIPUModule
2724
from pytorch_lightning.trainer.configuration_validator import _check_datamodule_checkpoint_hooks
2825
from pytorch_lightning.trainer.states import RunningStage
@@ -323,48 +320,6 @@ def on_pretrain_routine_end(self, trainer, pl_module):
323320
trainer.fit(model)
324321

325322

326-
@pytest.mark.flaky(reruns=3)
327-
@pytest.mark.parametrize(["action", "expected"], [("a", [3, 1]), ("b", [2]), ("c", [1])])
328-
def test_simple_profiler_iterable_durations(tmpdir, action: str, expected: list):
329-
"""Ensure the reported durations are reasonably accurate."""
330-
331-
def _sleep_generator(durations):
332-
"""the profile_iterable method needs an iterable in which we can ensure that we're properly timing how long
333-
it takes to call __next__"""
334-
for duration in durations:
335-
time.sleep(duration)
336-
yield duration
337-
338-
def _get_python_cprofile_total_duration(profile):
339-
return sum(x.inlinetime for x in profile.getstats())
340-
341-
simple_profiler = SimpleProfiler()
342-
iterable = _sleep_generator(expected)
343-
344-
with pytest.deprecated_call(
345-
match="`SimpleProfiler.profile_iterable` is deprecated in v1.6 and will be removed in v1.8."
346-
):
347-
for _ in simple_profiler.profile_iterable(iterable, action):
348-
pass
349-
350-
# we exclude the last item in the recorded durations since that's when StopIteration is raised
351-
np.testing.assert_allclose(simple_profiler.recorded_durations[action][:-1], expected, rtol=0.2)
352-
353-
advanced_profiler = AdvancedProfiler(dirpath=tmpdir, filename="profiler")
354-
355-
iterable = _sleep_generator(expected)
356-
357-
with pytest.deprecated_call(
358-
match="`AdvancedProfiler.profile_iterable` is deprecated in v1.6 and will be removed in v1.8."
359-
):
360-
for _ in advanced_profiler.profile_iterable(iterable, action):
361-
pass
362-
363-
recorded_total_duration = _get_python_cprofile_total_duration(advanced_profiler.profiled_actions[action])
364-
expected_total_duration = np.sum(expected)
365-
np.testing.assert_allclose(recorded_total_duration, expected_total_duration, rtol=0.2)
366-
367-
368323
def test_v1_8_0_datamodule_checkpointhooks():
369324
class CustomBoringDataModuleSave(BoringDataModule):
370325
def on_save_checkpoint(self, checkpoint):

0 commit comments

Comments
 (0)