-
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
Add BatchSizeFinder callback #11089
Add BatchSizeFinder callback #11089
Conversation
5ec2c83
to
3de3cec
Compare
88a00d0
to
9c6bcc1
Compare
After chatting with @rohitgr7, Here is the API design specification for the With the tune method.User story: As a user, I want to fit the best batch size for each stage and get the associated maximal batch size. trainer = Trainer()
trainer.tune(auto_batch_size="fit | True (BC)", ...) # Compute the train_batch_size and val_batch_size
# In the LightningModule, DataModule
self.batch_size = train_batch_size # BC -> depreceated in favor of `{stage}_batch_size`.
self.train_batch_size = train_max_batch_size
self.val_batch_size = val_max_batch_size
trainer.tune(auto_batch_size='validate', ...) -> val dataloader batch_size
# In the LightningModule, DataModule
self.val_batch_size = max_batch_size
trainer.tune(auto_batch_size='test', ...) -> test dataloader batch_size
# In the LightningModule, DataModule
self.test_batch_size = max_batch_size
trainer.tune(auto_batch_size='predict', ...) -> predict dataloader batch_size
self.predict_batch_size = max_batch_size With the Trainer entry point method.User story: As a user, I want to fit the best batch size and run the trainer entry point into a single call. trainer = Trainer(callbacks=BatchSizeFinder())
trainer.fit(...) -> `on_fit_start` perform tune
trainer.validate(...) -> `on_validation_start` perform tune
trainer.test(...) -> `on_test_start` perform tune
trainer.predict(...) -> `on_predict_start` perform tune Open questions:
Solution:
... @carmocca @ananthsub @awaelchli @justusschock thoughts ? |
f5e9a5a
to
173ffd3
Compare
update on PR: all that's been discussed here is now added. Only the following proposal is missing and I need more time to think about how to go about this. Maybe in a sep PR to avoid a lot of changes in a single one.
Also the API is: trainer.tune(method="fit|validate|test|predict") (default fit) instead of trainer.tune(auto_batch_size="fit|validate|test|predict") because, there is another option to run batch_size_finder using |
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.
IMO a callback is not the right fit here. this will override the behavior of fit/validate/test if used this way. why doesn't this use the loops API instead?
I tried writing pseudocode to cover up all the possible use-cases we have and convert it into a component that users can easily integrate and plugin, but loops couldn't fit all possible cases. For eg, we have flash finetuning and let's say the user might want to compute new LR or new batch_size after certain epochs of pre-training, then it's not easily configurable within a single call. One can achieve it with multiple calls but since we support strategies within Flash. With callbacks this is now pretty simple since we make sure after each tuning call, the respective loop state_dict is restored completely, and we still get an updated hparam using the tuner. Plus it now runs for val/test/predict. If you have any ideas to configure it using loops, would love to discuss them. Also, we discussed the possible solutions for this internally and everyone I talked to recommended callbacks. |
60a7a5b
to
8c3e0de
Compare
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.
Synced outside of GitHub! LGTM! Great and challenging work
We can try to remove the exception in the future if we finish #8604
* Revert "Add BatchSizeFinder callback (#11089)" This reverts commit d1a3a3e. * Revert "Revert "Add BatchSizeFinder callback (#11089)"" This reverts commit 9cc4695. * remove pl * add torch * add numpy * rm packages * add packages * add packages * import from PL * import from PL * always install PL for doctests * remove unnecessary requirements * always install PL in editable mode * once more * another attempt * maybe fix app test? * Redundant checkgroup path * Revert "maybe fix app test?" This reverts commit 8210a43. * speed up install deps * damn this * damn trio Co-authored-by: otaj <[email protected]> Co-authored-by: otaj <[email protected]> Co-authored-by: Carlos Mocholí <[email protected]>
What does this PR do?
Part of #11012
TODO:
Does your PR introduce any breaking changes? If yes, please list them.
Before submitting
PR review
Anyone in the community is welcome to review the PR.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:
Did you have fun?
Make sure you had fun coding 🙃
cc @Borda @awaelchli @ananthsub @daniellepintz @rohitgr7 @akihironitta