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

Let Accelerator inherit from ABC to make sure abstractmethod takes effect #11521

Merged
merged 3 commits into from Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions pytorch_lightning/accelerators/accelerator.py
Expand Up @@ -11,15 +11,15 @@
# 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 abc import abstractmethod
from abc import ABC, abstractmethod
from typing import Any, Dict, Union

import torch

import pytorch_lightning as pl


class Accelerator:
class Accelerator(ABC):
"""The Accelerator Base Class. An Accelerator is meant to deal with one type of Hardware.

Currently there are accelerators for:
Expand All @@ -45,7 +45,7 @@ def setup(self, trainer: "pl.Trainer") -> None:
"""

def get_device_stats(self, device: Union[str, torch.device]) -> Dict[str, Any]:
"""Gets stats for a given device.
"""Get stats for a given device.

Args:
device: device for which to get stats
Expand All @@ -58,4 +58,4 @@ def get_device_stats(self, device: Union[str, torch.device]) -> Dict[str, Any]:
@staticmethod
@abstractmethod
def auto_device_count() -> int:
"""Get the devices when set to auto."""
"""Get the device count when set to auto."""
4 changes: 3 additions & 1 deletion tests/accelerators/test_accelerator_connector.py
Expand Up @@ -336,7 +336,9 @@ def creates_processes_externally(self) -> bool:
@mock.patch("pytorch_lightning.strategies.DDPStrategy.setup_distributed", autospec=True)
def test_custom_accelerator(device_count_mock, setup_distributed_mock):
class Accel(Accelerator):
pass
@staticmethod
def auto_device_count() -> int:
return 1

class Prec(PrecisionPlugin):
pass
Expand Down