-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ref: organize args 2/n * ref: organize args 2/n * ref: organize args 2/n * ref: organize args 2/n
- Loading branch information
1 parent
deb82d9
commit 541c4ab
Showing
6 changed files
with
157 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# 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.utilities.exceptions import MisconfigurationException | ||
from typing import Union | ||
from pytorch_lightning.utilities import rank_zero_warn, rank_zero_info | ||
|
||
|
||
class DebuggingConnector: | ||
|
||
def __init__(self, trainer): | ||
self.trainer = trainer | ||
|
||
def on_init_start( | ||
self, | ||
overfit_pct, | ||
val_percent_check, | ||
test_percent_check, | ||
train_percent_check, | ||
limit_train_batches, | ||
limit_val_batches, | ||
limit_test_batches, | ||
val_check_interval, | ||
overfit_batches, | ||
fast_dev_run | ||
): | ||
self.trainer.fast_dev_run = fast_dev_run | ||
if self.trainer.fast_dev_run: | ||
limit_train_batches = 1 | ||
limit_val_batches = 1 | ||
limit_test_batches = 1 | ||
self.trainer.num_sanity_val_steps = 0 | ||
self.trainer.max_epochs = 1 | ||
rank_zero_info( | ||
'Running in fast_dev_run mode: will run a full train,' ' val and test loop using a single batch' | ||
) | ||
|
||
# how much of the data to use | ||
# TODO: remove in 0.10.0 | ||
if overfit_pct is not None: | ||
rank_zero_warn( | ||
"Argument `overfit_pct` is now set by `overfit_batches` since v0.8.0" | ||
" and this argument will be removed in v0.10.0", | ||
DeprecationWarning, | ||
) | ||
overfit_batches = overfit_pct | ||
|
||
# TODO: remove in 0.10.0 | ||
if val_percent_check is not None: | ||
rank_zero_warn( | ||
"Argument `val_percent_check` is now set by `limit_val_batches` since v0.8.0" | ||
" and this argument will be removed in v0.10.0", | ||
DeprecationWarning, | ||
) | ||
limit_val_batches = val_percent_check | ||
|
||
# TODO: remove in 0.10.0 | ||
if test_percent_check is not None: | ||
rank_zero_warn( | ||
"Argument `test_percent_check` is now set by `limit_test_batches` since v0.8.0" | ||
" and this argument will be removed in v0.10.0", | ||
DeprecationWarning, | ||
) | ||
limit_test_batches = test_percent_check | ||
|
||
# TODO: remove in 0.10.0 | ||
if train_percent_check is not None: | ||
rank_zero_warn( | ||
"Argument `train_percent_check` is now set by `limit_train_batches` since v0.8.0" | ||
" and this argument will be removed in v0.10.0", | ||
DeprecationWarning, | ||
) | ||
limit_train_batches = train_percent_check | ||
|
||
self.trainer.limit_train_batches = _determine_batch_limits(limit_train_batches, 'limit_train_batches') | ||
self.trainer.limit_val_batches = _determine_batch_limits(limit_val_batches, 'limit_val_batches') | ||
self.trainer.limit_test_batches = _determine_batch_limits(limit_test_batches, 'limit_test_batches') | ||
self.trainer.val_check_interval = _determine_batch_limits(val_check_interval, 'val_check_interval') | ||
self.trainer.overfit_batches = _determine_batch_limits(overfit_batches, 'overfit_batches') | ||
self.determine_data_use_amount(self.trainer.overfit_batches) | ||
|
||
def determine_data_use_amount(self, overfit_batches: float) -> None: | ||
"""Use less data for debugging purposes""" | ||
if overfit_batches > 0: | ||
self.trainer.limit_train_batches = overfit_batches | ||
self.trainer.limit_val_batches = overfit_batches | ||
self.trainer.limit_test_batches = overfit_batches | ||
|
||
|
||
def _determine_batch_limits(batches: Union[int, float], name: str) -> Union[int, float]: | ||
if 0 <= batches <= 1: | ||
return batches | ||
elif batches > 1 and batches % 1.0 == 0: | ||
return int(batches) | ||
else: | ||
raise MisconfigurationException( | ||
f'You have passed invalid value {batches} for {name}, it has to be in [0.0, 1.0] or an int.' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters