-   Notifications  
You must be signed in to change notification settings  - Fork 3.6k
 
Fix percent_checks #649
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
Conversation
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.
nice extension 👍
| 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 " | 
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.
pls use ` around functions and variables...
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.
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) | 
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.
I would consider adding a check and optionaly raise error if the nb is 0 becase with empty dataloader it may crash later anyway...
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.
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.: | 
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.
as it is relative pattern you may move this check to a private method and call it here instaed
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.
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.: | 
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.
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...
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.
Done
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.
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 " | 
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.
pls pep8 prefers to have whitespace on the beginning of next line instead of the last line ending
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.
@kuynzereb have you check this?
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.
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 :)
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.
well if you feel like nothing to do, you may check all string in the package... ;]
This PR resolves #646 and resolves #631
In short:
val_percent_check=0.num_training_batchesandnum_test_batchesare always not less than 1.val_check_intervalis checked to be in the range [0.0, 1.0] or to be not greater thannum_training_batches.