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

Fix percent_checks #649

Merged
merged 3 commits into from
Jan 5, 2020
Merged

Conversation

kuynzereb
Copy link
Contributor

@kuynzereb kuynzereb commented Dec 25, 2019

This PR resolves #646 and resolves #631

In short:

  • Now we can disable validation by setting val_percent_check=0.
  • All percent_checks are checked to lie in the range [0.0, 1.0].
  • Now num_training_batches and num_test_batches are always not less than 1.
  • val_check_interval is checked to be in the range [0.0, 1.0] or to be not greater than num_training_batches.

Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice extension 👍

@@ -48,15 +48,30 @@ def init_train_dataloader(self, model):
if EXIST_ITER_DATASET and isinstance(self.get_train_dataloader().dataset, IterableDataset):
self.num_training_batches = float('inf')
else:
if not 0. <= self.train_percent_check <= 1.:
raise ValueError(f"train_percent_check must lie in the range [0.0, 1.0], but got "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls use ` around functions and variables...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

self.num_training_batches = len(self.get_train_dataloader())
self.num_training_batches = int(self.num_training_batches * self.train_percent_check)
self.num_training_batches = max(1, self.num_training_batches)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider adding a check and optionaly raise error if the nb is 0 becase with empty dataloader it may crash later anyway...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the #653 fix there should be no problems with empty dataloaders for now. So I decided to remove max(1, ...) for training and test batches.

But I agree that maybe we should better think about the cases when when num_training_batches=0 or len(train_dataloader)=0. It is not very straightforward because the user, for example, can define the model with only test_step and test_end and test_dataloader for testing. In that case an empty train_dataloader is acceptable.


# determine number of validation batches
# val datasets could be none, 1 or 2+
if self.get_val_dataloaders() is not None:
if not 0. <= self.val_percent_check <= 1.:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as it is relative pattern you may move this check to a private method and call it here instaed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


# determine number of validation batches
# val datasets could be none, 1 or 2+
if self.get_val_dataloaders() is not None:
if not 0. <= self.val_percent_check <= 1.:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as it is a relative pattern you may move this check to a private method and call it here instead so when the text is changed later it will be stil consistent...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM =)

f"val_check_interval ({self.val_check_interval}) must be less than or equal to "
f"the number of the training batches ({self.num_training_batches}). "
f"If you want to disable validation set val_percent_check to 0.0 instead.")
f"`val_check_interval` ({self.val_check_interval}) must be less than or equal "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls pep8 prefers to have whitespace on the beginning of next line instead of the last line ending

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kuynzereb have you check this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I haven't fixed it yet and PR has been already merged. But I got your point. From now on I will not use trailing spaces in multiline strings :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well if you feel like nothing to do, you may check all string in the package... ;]

@williamFalcon williamFalcon merged commit 7824b5c into Lightning-AI:master Jan 5, 2020
@kuynzereb kuynzereb deleted the fix_percent_checks branch January 14, 2020 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Turn off validation if val_percent_check=0 num_training_batches rounds down, causing 0 batches count
3 participants