2020-08-20 02:03:22 +00:00
|
|
|
# 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.
|
2020-11-27 18:12:56 +00:00
|
|
|
from abc import ABC
|
2022-01-05 20:23:57 +00:00
|
|
|
from typing import Any, List, Optional, Union
|
2019-10-22 01:16:51 +00:00
|
|
|
|
2022-01-05 20:23:57 +00:00
|
|
|
from torch.utils.data import DataLoader
|
2020-01-20 19:50:31 +00:00
|
|
|
|
2021-06-25 19:16:11 +00:00
|
|
|
import pytorch_lightning as pl
|
2021-04-27 12:46:45 +00:00
|
|
|
from pytorch_lightning.trainer.states import RunningStage
|
2022-01-05 20:23:57 +00:00
|
|
|
from pytorch_lightning.utilities import rank_zero_deprecation
|
2019-10-22 01:16:51 +00:00
|
|
|
|
|
|
|
|
2019-12-04 15:57:32 +00:00
|
|
|
class TrainerDataLoadingMixin(ABC):
|
2022-01-05 20:23:57 +00:00
|
|
|
r"""
|
|
|
|
.. deprecated:: v1.6
|
|
|
|
The `TrainerDataLoadingMixin` class was deprecated in v1.6 and will be removed in v1.8.
|
|
|
|
"""
|
2021-09-28 17:04:02 +00:00
|
|
|
|
|
|
|
def prepare_dataloader(self, dataloader: Any, shuffle: bool, mode: Optional[RunningStage] = None) -> Any:
|
2022-01-05 20:23:57 +00:00
|
|
|
r"""
|
|
|
|
.. deprecated:: v1.6
|
|
|
|
`TrainerDataLoadingMixin.prepare_dataloader` was deprecated in v1.6
|
|
|
|
and will be removed in v1.8.
|
|
|
|
|
|
|
|
This function handles to following functionalities:
|
2021-09-28 17:04:02 +00:00
|
|
|
|
|
|
|
- Injecting a `DistributedDataSampler` into the `DataLoader` if on a distributed environment
|
|
|
|
- Wrapping the datasets and samplers into fault-tolerant components
|
|
|
|
"""
|
2022-01-05 20:23:57 +00:00
|
|
|
rank_zero_deprecation(
|
|
|
|
"`TrainerDataLoadingMixin.prepare_dataloader` was deprecated in v1.6 and will be removed in v1.8."
|
2021-02-03 09:25:42 +00:00
|
|
|
)
|
2022-01-05 20:23:57 +00:00
|
|
|
return self._data_connector._prepare_dataloader(dataloader, shuffle, mode)
|
2021-06-15 12:55:06 +00:00
|
|
|
|
2021-08-04 15:43:34 +00:00
|
|
|
def request_dataloader(
|
2021-08-16 09:28:05 +00:00
|
|
|
self, stage: RunningStage, model: Optional["pl.LightningModule"] = None
|
2021-08-04 15:43:34 +00:00
|
|
|
) -> Union[DataLoader, List[DataLoader]]:
|
2022-01-05 20:23:57 +00:00
|
|
|
r"""
|
|
|
|
.. deprecated:: v1.6
|
|
|
|
`TrainerDataLoadingMixin.request_dataloader` was deprecated in v1.6
|
|
|
|
and will be removed in v1.8.
|
|
|
|
|
|
|
|
Requests a dataloader from the given model by calling dataloader hooks corresponding to the given stage.
|
2020-03-12 16:46:02 +00:00
|
|
|
|
|
|
|
Returns:
|
2021-10-20 13:23:20 +00:00
|
|
|
The requested dataloader
|
2019-10-24 10:43:35 +00:00
|
|
|
"""
|
2022-01-05 20:23:57 +00:00
|
|
|
rank_zero_deprecation(
|
|
|
|
"`TrainerDataLoadingMixin.request_dataloader` was deprecated in v1.6 and will be removed in v1.8."
|
|
|
|
)
|
|
|
|
return self._data_connector._request_dataloader(stage, model)
|