-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Fixed val interval #405
Merged
Merged
Fixed val interval #405
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5ec6b32
added fixed frequency val batch check
williamFalcon 9635a85
added fixed frequency val batch check
williamFalcon 1da54f0
Finished IterableDataset support
williamFalcon 0f5539f
Merge branch 'master' into fixed_val_interval
williamFalcon 25f837d
flake8
williamFalcon 0347254
flake8
williamFalcon 91aa263
flake8
williamFalcon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
|
||
from torch.utils.data.distributed import DistributedSampler | ||
import torch.distributed as dist | ||
from torch.utils.data import IterableDataset | ||
|
||
from pytorch_lightning.utilities.debugging import MisconfigurationException | ||
|
||
try: | ||
from apex import amp | ||
|
@@ -15,8 +18,11 @@ class TrainerDataLoadingMixin(object): | |
def layout_bookeeping(self): | ||
|
||
# determine number of training batches | ||
self.nb_training_batches = len(self.get_train_dataloader()) | ||
self.nb_training_batches = int(self.nb_training_batches * self.train_percent_check) | ||
if isinstance(self.get_train_dataloader(), IterableDataset): | ||
self.nb_training_batches = float('inf') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and |
||
else: | ||
self.nb_training_batches = len(self.get_train_dataloader()) | ||
self.nb_training_batches = int(self.nb_training_batches * self.train_percent_check) | ||
|
||
# determine number of validation batches | ||
# val datasets could be none, 1 or 2+ | ||
|
@@ -34,8 +40,13 @@ def layout_bookeeping(self): | |
self.nb_test_batches = max(1, self.nb_test_batches) | ||
|
||
# determine when to check validation | ||
self.val_check_batch = int(self.nb_training_batches * self.val_check_interval) | ||
self.val_check_batch = max(1, self.val_check_batch) | ||
# if int passed in, val checks that often | ||
# otherwise, it checks in [0, 1.0] % range of a training epoch | ||
if isinstance(self.val_check_interval, int): | ||
self.val_check_batch = self.val_check_interval | ||
else: | ||
self.val_check_batch = int(self.nb_training_batches * self.val_check_interval) | ||
self.val_check_batch = max(1, self.val_check_batch) | ||
|
||
def get_dataloaders(self, model): | ||
""" | ||
|
@@ -127,6 +138,16 @@ def get_dataloaders(self, model): | |
self.get_test_dataloaders() | ||
self.get_val_dataloaders() | ||
|
||
# support IterableDataset for train data | ||
self.is_iterable_train_dataloader = isinstance(self.get_train_dataloader(), IterableDataset) | ||
if self.is_iterable_train_dataloader and not isinstance(self.val_check_interval, int): | ||
m = ''' | ||
When using an iterableDataset for train_dataloader, | ||
Trainer(val_check_interval) must be an int. | ||
An int k specifies checking validation every k training batches | ||
''' | ||
raise MisconfigurationException('when using ') | ||
|
||
def determine_data_use_amount(self, train_percent_check, val_percent_check, | ||
test_percent_check, overfit_pct): | ||
""" | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this needs to be
isinstance(self.get_train_dataloader().dataset, IterableDataset)