-
Notifications
You must be signed in to change notification settings - Fork 3.6k
move batch to device before sending it to hooks #7378
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
Merged
Merged
Changes from all commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
a774766
update train step
awaelchli 64af97d
test
awaelchli 36d6a91
x
awaelchli cb6112e
limits
awaelchli 16728d1
val
awaelchli de08636
typeo
awaelchli 66934e4
x
awaelchli 89202c9
x
awaelchli b5f8806
step
awaelchli 0ff4f9e
min gpus
awaelchli 0d3f47a
run all loops
awaelchli fb9ffed
x
awaelchli b7befc1
limit test
awaelchli fe065a5
profiler
awaelchli 60d458e
clean up accelerator code
awaelchli 642bcf6
move files
awaelchli 2d1b7ca
rename
awaelchli ca0b7ba
Merge branch 'tests/group-loop-tests' into bugfix/batch-device
awaelchli 50ac2a5
move tests
awaelchli 1e38413
changelog
awaelchli b021641
reorder callbacks and model hooks
awaelchli cc79736
add test description
awaelchli 2792376
Merge branch 'master' into bugfix/batch-device
awaelchli 53e3e71
Merge branch 'master' into bugfix/batch-device
awaelchli 917a06e
Merge branch 'master' into bugfix/batch-device
Borda 5521304
Merge branch 'master' into bugfix/batch-device
awaelchli 4ffc332
replace unneccessary method
awaelchli ad8d357
Merge branch 'master' into bugfix/batch-device
awaelchli 41f83ef
fix chlog
awaelchli 5c2b7b2
adjust batch_to_device for DP Plugin
awaelchli 88bc2fc
update tests for dataloader idx
awaelchli 9d3beba
unused imports
awaelchli 4f80d5f
Merge branch 'master' into bugfix/batch-device
awaelchli dea8cb4
hook change
awaelchli bf99814
switch None
awaelchli 7c4c38d
Merge branch 'master' into bugfix/batch-device
awaelchli b4a1348
clear memory
awaelchli 023e619
change to None
awaelchli b71547e
None
awaelchli 7eab3bb
None
awaelchli 91f1387
memory savings
awaelchli 01b7293
remove redundant todo
awaelchli 43a6d1e
hack
awaelchli 78438cd
Merge branch 'master'
awaelchli a8433bd
cheat
awaelchli d8cd2b1
Revert "cheat"
awaelchli 9467689
Revert "hack"
awaelchli 27ac26d
Merge branch 'master' into bugfix/batch-device
awaelchli 5d08680
update new epoch loop
awaelchli 032055c
remove from old loop code
awaelchli 1b4f2af
update chlog
awaelchli 792894c
Merge branch 'master' into bugfix/batch-device
awaelchli faaec6a
update hook test
awaelchli 053f377
changelog
awaelchli 14ea8a8
teardown
awaelchli d109174
Merge branch 'master' into bugfix/batch-device
awaelchli 0733da2
integrate changes in new eval loop
awaelchli 708cf0e
fix hook calls
awaelchli 0fb1369
Merge branch 'master' into bugfix/batch-device
awaelchli e5de582
add prediction step
awaelchli 4880808
bad merge
awaelchli 3c3e87a
Revert "bad merge"
awaelchli da08269
fix train batch hook test
awaelchli ebe3ce3
rm -rf _notebooks
awaelchli 2a0aedb
update chlog
awaelchli f4a2f8c
release memory
awaelchli 8838b43
fix type
awaelchli 6d5c61c
notebooks mess
awaelchli eec4ee2
debug
awaelchli 968c967
Revert "debug"
awaelchli fc2d612
teardown
awaelchli 856cd66
fix teardown bug
awaelchli a6e6101
debug
awaelchli cde1622
x
awaelchli 5ddeaec
debug
awaelchli 88ca10d
Merge branch 'master' into bugfix/batch-device
awaelchli c712b62
Revert "debug"
awaelchli 3998873
Merge branch 'master' into bugfix/batch-device
awaelchli 6b31973
Merge branch 'master' into bugfix/batch-device
carmocca 542efbd
Fix changelog
carmocca 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,93 @@ | ||
| # Copyright The PyTorch Lightning team. | ||
awaelchli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # | ||
| # 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 import Callback, Trainer | ||
| from tests.helpers import BoringModel | ||
| from tests.helpers.runif import RunIf | ||
|
|
||
|
|
||
| class BatchHookObserverCallback(Callback): | ||
|
|
||
| def on_train_batch_start(self, trainer, pl_module, batch, *args): | ||
| assert batch.device == pl_module.device | ||
|
|
||
| def on_train_batch_end(self, trainer, pl_module, outputs, batch, *args): | ||
| assert batch.device == pl_module.device | ||
|
|
||
| def on_validation_batch_start(self, trainer, pl_module, batch, *args): | ||
| assert batch.device == pl_module.device | ||
|
|
||
| def on_validation_batch_end(self, trainer, pl_module, outputs, batch, *args): | ||
| assert batch.device == pl_module.device | ||
|
|
||
| def on_test_batch_start(self, trainer, pl_module, batch, *args): | ||
| assert batch.device == pl_module.device | ||
|
|
||
| def on_test_batch_end(self, trainer, pl_module, outputs, batch, *args): | ||
| assert batch.device == pl_module.device | ||
|
|
||
| def on_predict_batch_start(self, trainer, pl_module, batch, *args): | ||
| assert batch.device == pl_module.device | ||
|
|
||
| def on_predict_batch_end(self, trainer, pl_module, outputs, batch, *args): | ||
| assert batch.device == pl_module.device | ||
|
|
||
|
|
||
| class BatchHookObserverModel(BoringModel): | ||
|
|
||
| def on_train_batch_start(self, batch, *args): | ||
| assert batch.device == self.device | ||
|
|
||
| def on_train_batch_end(self, outputs, batch, *args): | ||
| assert batch.device == self.device | ||
|
|
||
| def on_validation_batch_start(self, batch, *args): | ||
| assert batch.device == self.device | ||
|
|
||
| def on_validation_batch_end(self, outputs, batch, *args): | ||
| assert batch.device == self.device | ||
|
|
||
| def on_test_batch_start(self, batch, *args): | ||
| assert batch.device == self.device | ||
|
|
||
| def on_test_batch_end(self, outputs, batch, *args): | ||
| assert batch.device == self.device | ||
|
|
||
| def on_predict_batch_start(self, batch, *args): | ||
| assert batch.device == self.device | ||
|
|
||
| def on_predict_batch_end(self, outputs, batch, *args): | ||
| assert batch.device == self.device | ||
|
|
||
|
|
||
| @RunIf(min_gpus=1) | ||
| def test_callback_batch_on_device(tmpdir): | ||
| """ Test that the batch object sent to the on_*_batch_start/end hooks is on the right device.""" | ||
|
|
||
| batch_callback = BatchHookObserverCallback() | ||
|
|
||
| model = BatchHookObserverModel() | ||
| trainer = Trainer( | ||
| default_root_dir=tmpdir, | ||
| max_steps=1, | ||
| limit_train_batches=1, | ||
| limit_val_batches=1, | ||
| limit_test_batches=1, | ||
| limit_predict_batches=1, | ||
| gpus=1, | ||
| callbacks=[batch_callback], | ||
| ) | ||
| trainer.fit(model) | ||
| trainer.validate(model) | ||
| trainer.test(model) | ||
| trainer.predict(model) | ||
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.