-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add before_batch_transfer and after_batch_transfer hooks #3671
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
33 commits
Select commit
Hold shift + click to select a range
3aef347
add hooks
rohitgr7 d0e949c
comment
rohitgr7 6b98fdd
docs
rohitgr7 48e724c
add tests
rohitgr7 2864429
make it private
rohitgr7 bbb6bb6
fix tests
rohitgr7 5e7ef6b
docs
rohitgr7 4fde092
chlog
rohitgr7 f4f5a27
testcode
rohitgr7 4df6f08
codefactor
rohitgr7 7252acf
fix doctest
rohitgr7 e7dafd0
fix doctest
rohitgr7 d9fc2af
suggestions
rohitgr7 69437cf
is always overriden
rohitgr7 91be6ca
pep and BoringModel
rohitgr7 c6ca4ad
BoringModel
rohitgr7 95599da
docs
rohitgr7 501cb0b
docs
rohitgr7 3b96ff7
docs
rohitgr7 9fe7bef
fix
rohitgr7 b32d6d6
rebase
rohitgr7 29859f8
rebase
rohitgr7 1bb3349
suggestions
rohitgr7 be081ed
docs
rohitgr7 f1f7881
suggestions
rohitgr7 e104afb
try fix docs
rohitgr7 4100e30
docs
rohitgr7 2e52423
update name
rohitgr7 7c7231a
yapf
rohitgr7 7a41afc
docs
rohitgr7 404445d
rebase
rohitgr7 8ddc2d7
yapf
rohitgr7 f2e0f6b
Merge branch 'master' into feature/before_after_batch_hook
rohitgr7 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,7 +105,7 @@ def teardown(self): | |
| """ | ||
| pass | ||
|
|
||
| def batch_to_device(self, batch: Any, device: torch.device) -> Any: | ||
| def batch_to_device(self, batch: Any, device: Optional[torch.device] = None) -> Any: | ||
| """Moves the batch to the correct device. | ||
| The returned batch is of the same type as the input batch, just having all tensors on the correct device. | ||
|
|
||
|
|
@@ -114,8 +114,10 @@ def batch_to_device(self, batch: Any, device: torch.device) -> Any: | |
| device: The target device | ||
| """ | ||
| model = self.lightning_module | ||
|
|
||
| if model is not None: | ||
| return model.transfer_batch_to_device(batch, device) | ||
|
Contributor
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.
Collaborator
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. @tchaton ^^ |
||
| return model._apply_batch_transfer_handler(batch, device) | ||
|
|
||
| return move_data_to_device(batch, device) | ||
|
|
||
| def on_train_start(self): | ||
|
|
@@ -135,9 +137,7 @@ def training_step(self, args): | |
| :paramref:`~pytorch_lightning.trainer.trainer.Trainer.truncated_bptt_steps` > 0. | ||
|
|
||
| """ | ||
| batch = self.to_device(args[0]) | ||
|
|
||
| args[0] = batch | ||
| args[0] = self.to_device(args[0]) | ||
|
|
||
| with self.precision_plugin.train_step_context(), self.training_type_plugin.train_step_context(): | ||
| return self.training_type_plugin.training_step(*args) | ||
|
|
||
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
Oops, something went wrong.
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.