-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose
extract_batch_size
method and add corresponding tests. (#8357)
* expose extract_batch and make public * first pass * early return * add changelog * move to utilities/data.py * add test_data.py * tests are passing * precommit hook * address pep8 failure Co-authored-by: Carlos Mocholi <[email protected]>
- Loading branch information
Showing
4 changed files
with
51 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,21 @@ | ||
import torch | ||
|
||
from pytorch_lightning.utilities.data import extract_batch_size | ||
|
||
|
||
def test_extract_batch_size(): | ||
"""Tests the behavior of extracting the batch size.""" | ||
batch = "test string" | ||
assert extract_batch_size(batch) == 11 | ||
|
||
batch = torch.zeros(11, 10, 9, 8) | ||
assert extract_batch_size(batch) == 11 | ||
|
||
batch = {'test': torch.zeros(11, 10)} | ||
assert extract_batch_size(batch) == 11 | ||
|
||
batch = [torch.zeros(11, 10)] | ||
assert extract_batch_size(batch) == 11 | ||
|
||
batch = {'test': [{'test': [torch.zeros(11, 10)]}]} | ||
assert extract_batch_size(batch) == 11 |