Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pytorch_lightning.profiler.{AbstractProfiler,BaseProfiler} deprecated since v1.6 #15637

Merged
merged 13 commits into from
Nov 23, 2022
Merged
8 changes: 8 additions & 0 deletions src/pytorch_lightning/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Temporarily removed support for Hydra multi-run ([#15737](https://github.com/Lightning-AI/lightning/pull/15737))


- Removed deprecated `pytorch_lightning.profiler.base.AbstractProfiler` in favor of `pytorch_lightning.profilers.profiler.Profiler` ([#15637](https://github.com/Lightning-AI/lightning/pull/15637))


- Removed deprecated `pytorch_lightning.profiler.base.BaseProfiler` in favor of `pytorch_lightning.profilers.profiler.Profiler` ([#15637](https://github.com/Lightning-AI/lightning/pull/15637))


-

### Fixed

- Enhanced `reduce_boolean_decision` to accommodate `any`-analogous semantics expected by the `EarlyStopping` callback ([#15253](https://github.com/Lightning-AI/lightning/pull/15253))
Expand Down
1 change: 1 addition & 0 deletions src/pytorch_lightning/_graveyard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pytorch_lightning._graveyard.core
import pytorch_lightning._graveyard.legacy_import_unpickler
import pytorch_lightning._graveyard.loggers
import pytorch_lightning._graveyard.profiler
import pytorch_lightning._graveyard.trainer
import pytorch_lightning._graveyard.training_type
import pytorch_lightning._graveyard.utilities # noqa: F401
38 changes: 38 additions & 0 deletions src/pytorch_lightning/_graveyard/profiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any

import pytorch_lightning.profiler.base as base


class _AbstractProfiler:
# TODO: Remove in v2.0.0
def __init__(self, *_: Any, **__: Any) -> None:
raise NotImplementedError(
akihironitta marked this conversation as resolved.
Show resolved Hide resolved
"`pytorch_lightning.profiler.base.AbstractProfiler` was deprecated in v1.6 and is no longer supported"
" as of v1.9. Use `pytorch_lightning.profilers.Profiler` instead."
)


class _BaseProfiler:
# TODO: Remove in v2.0.0
def __init__(self, *_: Any, **__: Any) -> None:
raise RuntimeError(
"`pytorch_lightning.profiler.base.AbstractProfiler` was deprecated in v1.6 and is no longer supported"
" as of v1.9. Use `pytorch_lightning.profilers.Profiler` instead."
)


base.AbstractProfiler = _AbstractProfiler
base.BaseProfiler = _BaseProfiler
3 changes: 0 additions & 3 deletions src/pytorch_lightning/profiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pytorch_lightning.profiler.base import AbstractProfiler, BaseProfiler
from pytorch_lightning.profilers.advanced import AdvancedProfiler
from pytorch_lightning.profilers.base import PassThroughProfiler
from pytorch_lightning.profilers.profiler import Profiler
Expand All @@ -20,8 +19,6 @@
from pytorch_lightning.profilers.xla import XLAProfiler

__all__ = [
"AbstractProfiler",
"BaseProfiler",
"Profiler",
"AdvancedProfiler",
"PassThroughProfiler",
Expand Down
49 changes: 0 additions & 49 deletions src/pytorch_lightning/profiler/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Profiler to check if there are any bottlenecks in your code."""
from abc import ABC, abstractmethod
from typing import Any

from pytorch_lightning.profilers.base import PassThroughProfiler as NewPassThroughProfiler
from pytorch_lightning.profilers.profiler import Profiler
from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation


class AbstractProfiler(ABC):
"""Specification of a profiler.

See deprecation warning below

.. deprecated:: v1.6
`AbstractProfiler` was deprecated in v1.6 and will be removed in v1.8.
Please use `Profiler` instead.
"""

@abstractmethod
def start(self, action_name: str) -> None:
"""Defines how to start recording an action."""

@abstractmethod
def stop(self, action_name: str) -> None:
"""Defines how to record the duration once an action is complete."""

@abstractmethod
def summary(self) -> str:
"""Create profiler summary in text format."""

@abstractmethod
def setup(self, **kwargs: Any) -> None:
"""Execute arbitrary pre-profiling set-up steps as defined by subclass."""

@abstractmethod
def teardown(self, **kwargs: Any) -> None:
"""Execute arbitrary post-profiling tear-down steps as defined by subclass."""


class BaseProfiler(Profiler):
"""
.. deprecated:: v1.6
`BaseProfiler` was deprecated in v1.6 and will be removed in v1.8.
Please use `Profiler` instead.
"""

def __init__(self, *args, **kwargs): # type: ignore[no-untyped-def]
rank_zero_deprecation(
"`BaseProfiler` was deprecated in v1.6 and will be removed in v1.8. Please use `Profiler` instead."
)
super().__init__(*args, **kwargs)


class PassThroughProfiler(NewPassThroughProfiler):
def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def]
rank_zero_deprecation(
Expand Down
2 changes: 1 addition & 1 deletion src/pytorch_lightning/profiler/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class Profiler(NewProfiler):
"""
.. deprecated:: v1.6
.. deprecated:: v1.7
`pytorch_lightning.profiler.Profiler` is deprecated in v1.7 and will be removed in v1.9.
Use the equivalent `pytorch_lightning.profilers.Profiler` class instead.
"""
Expand Down
28 changes: 28 additions & 0 deletions tests/tests_pytorch/graveyard/test_profiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest


def test_v2_0_0_base_profilers():
akihironitta marked this conversation as resolved.
Show resolved Hide resolved
from pytorch_lightning.profiler.base import AbstractProfiler, BaseProfiler

with pytest.raises(
RuntimeError, match="AbstractProfiler` was deprecated in v1.6 and is no longer supported as of v1.9."
):
AbstractProfiler()

with pytest.raises(
RuntimeError, match="AbstractProfiler` was deprecated in v1.6 and is no longer supported as of v1.9."
):
BaseProfiler()