diff --git a/pytorch_lightning/core/datamodule.py b/pytorch_lightning/core/datamodule.py index b1f42c6ea4..297f939542 100644 --- a/pytorch_lightning/core/datamodule.py +++ b/pytorch_lightning/core/datamodule.py @@ -20,9 +20,9 @@ from typing import Any, List, Mapping, Optional, Sequence, Tuple, Union from torch.utils.data import DataLoader, Dataset, IterableDataset from pytorch_lightning.core.hooks import CheckpointHooks, DataHooks +from pytorch_lightning.core.mixins import HyperparametersMixin from pytorch_lightning.utilities import rank_zero_deprecation from pytorch_lightning.utilities.argparse import add_argparse_args, from_argparse_args, get_init_arguments_and_types -from pytorch_lightning.utilities.hparams_mixin import HyperparametersMixin class LightningDataModule(CheckpointHooks, DataHooks, HyperparametersMixin): diff --git a/pytorch_lightning/core/lightning.py b/pytorch_lightning/core/lightning.py index 6a68fb8011..90a9681906 100644 --- a/pytorch_lightning/core/lightning.py +++ b/pytorch_lightning/core/lightning.py @@ -34,16 +34,15 @@ from torchmetrics import Metric from pytorch_lightning.core.grads import GradInformation from pytorch_lightning.core.hooks import CheckpointHooks, DataHooks, ModelHooks from pytorch_lightning.core.memory import ModelSummary +from pytorch_lightning.core.mixins import DeviceDtypeModuleMixin, HyperparametersMixin from pytorch_lightning.core.optimizer import LightningOptimizer from pytorch_lightning.core.saving import ModelIO from pytorch_lightning.trainer.connectors.logger_connector.fx_validator import FxValidator from pytorch_lightning.utilities import rank_zero_deprecation, rank_zero_warn from pytorch_lightning.utilities.apply_func import apply_to_collection, convert_to_tensors from pytorch_lightning.utilities.cloud_io import get_filesystem -from pytorch_lightning.utilities.device_dtype_mixin import DeviceDtypeModuleMixin from pytorch_lightning.utilities.distributed import distributed_available, sync_ddp from pytorch_lightning.utilities.exceptions import MisconfigurationException -from pytorch_lightning.utilities.hparams_mixin import HyperparametersMixin from pytorch_lightning.utilities.parsing import collect_init_args from pytorch_lightning.utilities.signature_utils import is_param_in_hook_signature from pytorch_lightning.utilities.types import _METRIC_COLLECTION, EPOCH_OUTPUT, STEP_OUTPUT diff --git a/pytorch_lightning/core/mixins/__init__.py b/pytorch_lightning/core/mixins/__init__.py new file mode 100644 index 0000000000..c38db6aa4c --- /dev/null +++ b/pytorch_lightning/core/mixins/__init__.py @@ -0,0 +1,16 @@ +# 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 pytorch_lightning.core.mixins.device_dtype_mixin import DeviceDtypeModuleMixin # noqa F401 +from pytorch_lightning.core.mixins.hparams_mixin import HyperparametersMixin # noqa F401 diff --git a/pytorch_lightning/utilities/device_dtype_mixin.py b/pytorch_lightning/core/mixins/device_dtype_mixin.py similarity index 100% rename from pytorch_lightning/utilities/device_dtype_mixin.py rename to pytorch_lightning/core/mixins/device_dtype_mixin.py diff --git a/pytorch_lightning/utilities/hparams_mixin.py b/pytorch_lightning/core/mixins/hparams_mixin.py similarity index 100% rename from pytorch_lightning/utilities/hparams_mixin.py rename to pytorch_lightning/core/mixins/hparams_mixin.py diff --git a/pytorch_lightning/overrides/base.py b/pytorch_lightning/overrides/base.py index 3f396c3d60..2d705c0b14 100644 --- a/pytorch_lightning/overrides/base.py +++ b/pytorch_lightning/overrides/base.py @@ -18,7 +18,7 @@ from torch.nn import DataParallel from torch.nn.parallel import DistributedDataParallel import pytorch_lightning as pl -from pytorch_lightning.utilities.device_dtype_mixin import DeviceDtypeModuleMixin +from pytorch_lightning.core.mixins import DeviceDtypeModuleMixin class _LightningPrecisionModuleWrapperBase(DeviceDtypeModuleMixin, torch.nn.Module): diff --git a/pytorch_lightning/trainer/connectors/logger_connector/result.py b/pytorch_lightning/trainer/connectors/logger_connector/result.py index dff3754cc4..ae0989010a 100644 --- a/pytorch_lightning/trainer/connectors/logger_connector/result.py +++ b/pytorch_lightning/trainer/connectors/logger_connector/result.py @@ -19,10 +19,10 @@ from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple, Union import torch from torchmetrics import Metric +from pytorch_lightning.core.mixins import DeviceDtypeModuleMixin from pytorch_lightning.utilities import rank_zero_warn from pytorch_lightning.utilities.apply_func import apply_to_collection, apply_to_collections from pytorch_lightning.utilities.data import extract_batch_size -from pytorch_lightning.utilities.device_dtype_mixin import DeviceDtypeModuleMixin from pytorch_lightning.utilities.distributed import distributed_available from pytorch_lightning.utilities.enums import LightningEnum from pytorch_lightning.utilities.exceptions import MisconfigurationException diff --git a/tests/utilities/test_dtype_device_mixin.py b/tests/utilities/test_dtype_device_mixin.py index 737f874d8d..287a402bc4 100644 --- a/tests/utilities/test_dtype_device_mixin.py +++ b/tests/utilities/test_dtype_device_mixin.py @@ -16,7 +16,7 @@ import torch import torch.nn as nn from pytorch_lightning import Callback, Trainer -from pytorch_lightning.utilities.device_dtype_mixin import DeviceDtypeModuleMixin +from pytorch_lightning.core.mixins import DeviceDtypeModuleMixin from tests.helpers import BoringModel from tests.helpers.runif import RunIf