-
Notifications
You must be signed in to change notification settings - Fork 124
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
Enable analyzing nested input- and output-dicts #212
Merged
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4f540b8
enable analyzing nested input- and output dicts
snimu ef0e4ed
enable analyzing nested input- and output dicts
snimu 4d17355
skip tests that require torch v1.8 or above when an older version is …
snimu 38e2af0
add test for highly nested dicts, fix error found by it
snimu a96e995
`LayerInfo.calculate_size.extract_tensor` now works with `dict` properly
snimu 6931e39
simplified `test_highly_nested_dict_model`
snimu ad7ee14
`LayerInfo.calculate_size.extract_tensor` now works properly for obje…
snimu 81167cb
Add docstring to test to explain what exactly it tests
snimu 4d31c90
test all edge-cases of `LayerInfo.calculate_size.extract_tensor`
snimu b51d029
use `dim=0` in `F.softmax` explicitely (implicit use depreciated)
snimu 80bb192
replace custom `torchversion_at_least` with `packaging.version.parse`
snimu 55aee3e
modify `EdgecaseInputOutputModel` to increase test-coverage
snimu 6daa9f1
use torch_nested-package to simplify `LayerInfo.calculate_size`
snimu 563b8ba
Move back from using torch-nested. Fix and use `nested_list_size` ins…
snimu a0a7dbc
Fix problem with accessing of dicts
snimu 116202f
Install compressai in workflows
snimu 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 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 |
---|---|---|
|
@@ -8,3 +8,4 @@ pylint | |
pytest | ||
pytest-cov | ||
pre-commit | ||
transformers |
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,25 @@ | ||
import torch | ||
|
||
|
||
def torchversion_at_least(version: str) -> bool: | ||
""" | ||
Returns True if the installed version of torch is at least the given version. | ||
For example, if "1.13.1" is installed, `torchversion_at_least("1.8")` would | ||
yield `True`, but if "1.7.1" is installed, torchversion_at_least("1.8")` would | ||
yield `False`. | ||
""" | ||
version_installed = torch.__version__.split(".") | ||
version_given = version.split(".") | ||
|
||
for num_installed, num_given in zip(version_installed, version_given): | ||
if int(num_given) < int(num_installed): | ||
return True | ||
if int(num_given) > int(num_installed): | ||
return False | ||
|
||
if len(version_given) > len( | ||
version_installed | ||
): # e.g. "1.7.1" installed, "1.7" given | ||
return False | ||
|
||
return True |
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,38 @@ | ||
==================================================================================================== | ||
Layer (type:depth-idx) Output Shape Param # | ||
==================================================================================================== | ||
BertModel [2, 768] -- | ||
├─BertEmbeddings: 1-1 [2, 512, 768] -- | ||
│ └─Embedding: 2-1 [2, 512, 768] 23,440,896 | ||
│ └─Embedding: 2-2 [2, 512, 768] 1,536 | ||
│ └─Embedding: 2-3 [1, 512, 768] 393,216 | ||
│ └─LayerNorm: 2-4 [2, 512, 768] 1,536 | ||
│ └─Dropout: 2-5 [2, 512, 768] -- | ||
├─BertEncoder: 1-2 [2, 512, 768] -- | ||
│ └─ModuleList: 2-6 -- -- | ||
│ │ └─BertLayer: 3-1 [2, 512, 768] 7,087,872 | ||
│ │ └─BertLayer: 3-2 [2, 512, 768] 7,087,872 | ||
│ │ └─BertLayer: 3-3 [2, 512, 768] 7,087,872 | ||
│ │ └─BertLayer: 3-4 [2, 512, 768] 7,087,872 | ||
│ │ └─BertLayer: 3-5 [2, 512, 768] 7,087,872 | ||
│ │ └─BertLayer: 3-6 [2, 512, 768] 7,087,872 | ||
│ │ └─BertLayer: 3-7 [2, 512, 768] 7,087,872 | ||
│ │ └─BertLayer: 3-8 [2, 512, 768] 7,087,872 | ||
│ │ └─BertLayer: 3-9 [2, 512, 768] 7,087,872 | ||
│ │ └─BertLayer: 3-10 [2, 512, 768] 7,087,872 | ||
│ │ └─BertLayer: 3-11 [2, 512, 768] 7,087,872 | ||
│ │ └─BertLayer: 3-12 [2, 512, 768] 7,087,872 | ||
├─BertPooler: 1-3 [2, 768] -- | ||
│ └─Linear: 2-7 [2, 768] 590,592 | ||
│ └─Tanh: 2-8 [2, 768] -- | ||
==================================================================================================== | ||
Total params: 109,482,240 | ||
Trainable params: 109,482,240 | ||
Non-trainable params: 0 | ||
Total mult-adds (M): 218.57 | ||
==================================================================================================== | ||
Input size (MB): 0.01 | ||
Forward/backward pass size (MB): 852.50 | ||
Params size (MB): 437.93 | ||
Estimated Total Size (MB): 1290.45 | ||
==================================================================================================== |
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,46 @@ | ||
============================================================================================================== | ||
Layer (type:depth-idx) Output Shape Param # | ||
============================================================================================================== | ||
T5ForConditionalGeneration [2, 100, 512] -- | ||
├─T5Stack: 1-1 [2, 100, 512] 35,332,800 | ||
├─T5Stack: 1-2 -- (recursive) | ||
│ └─Embedding: 2-1 [2, 100, 512] 16,449,536 | ||
├─T5Stack: 1-3 -- (recursive) | ||
│ └─Dropout: 2-2 [2, 100, 512] -- | ||
│ └─ModuleList: 2-3 -- -- | ||
│ │ └─T5Block: 3-1 [2, 100, 512] 2,360,512 | ||
│ │ └─T5Block: 3-2 [2, 100, 512] 2,360,320 | ||
│ │ └─T5Block: 3-3 [2, 100, 512] 2,360,320 | ||
│ │ └─T5Block: 3-4 [2, 100, 512] 2,360,320 | ||
│ │ └─T5Block: 3-5 [2, 100, 512] 2,360,320 | ||
│ │ └─T5Block: 3-6 [2, 100, 512] 2,360,320 | ||
│ │ └─T5Block: 3-7 [2, 100, 512] 2,360,320 | ||
│ │ └─T5Block: 3-8 [2, 100, 512] 2,360,320 | ||
│ └─T5LayerNorm: 2-4 [2, 100, 512] 512 | ||
│ └─Dropout: 2-5 [2, 100, 512] -- | ||
├─T5Stack: 1-4 [2, 6, 100, 64] 16,449,536 | ||
│ └─Embedding: 2-6 [2, 100, 512] (recursive) | ||
│ └─Dropout: 2-7 [2, 100, 512] -- | ||
│ └─ModuleList: 2-8 -- -- | ||
│ │ └─T5Block: 3-9 [2, 100, 512] 3,147,456 | ||
│ │ └─T5Block: 3-10 [2, 100, 512] 3,147,264 | ||
│ │ └─T5Block: 3-11 [2, 100, 512] 3,147,264 | ||
│ │ └─T5Block: 3-12 [2, 100, 512] 3,147,264 | ||
│ │ └─T5Block: 3-13 [2, 100, 512] 3,147,264 | ||
│ │ └─T5Block: 3-14 [2, 100, 512] 3,147,264 | ||
│ │ └─T5Block: 3-15 [2, 100, 512] 3,147,264 | ||
│ │ └─T5Block: 3-16 [2, 100, 512] 3,147,264 | ||
│ └─T5LayerNorm: 2-9 [2, 100, 512] 512 | ||
│ └─Dropout: 2-10 [2, 100, 512] -- | ||
├─Linear: 1-5 [2, 100, 32128] 16,449,536 | ||
============================================================================================================== | ||
Total params: 128,743,488 | ||
Trainable params: 128,743,488 | ||
Non-trainable params: 0 | ||
Total mult-adds (M): 186.86 | ||
============================================================================================================== | ||
Input size (MB): 0.00 | ||
Forward/backward pass size (MB): 217.84 | ||
Params size (MB): 307.84 | ||
Estimated Total Size (MB): 525.69 | ||
============================================================================================================== |
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,17 @@ | ||
========================================================================================== | ||
Layer (type:depth-idx) Output Shape Param # | ||
========================================================================================== | ||
HighlyNestedDictModel [10] -- | ||
├─Linear: 1-1 [10] 110 | ||
├─Linear: 1-2 [10] 110 | ||
========================================================================================== | ||
Total params: 220 | ||
Trainable params: 220 | ||
Non-trainable params: 0 | ||
Total mult-adds (M): 0.00 | ||
========================================================================================== | ||
Input size (MB): 0.00 | ||
Forward/backward pass size (MB): 0.00 | ||
Params size (MB): 0.00 | ||
Estimated Total Size (MB): 0.00 | ||
========================================================================================== |
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 |
---|---|---|
|
@@ -33,14 +33,24 @@ def __init__( | |
self.total_output_bytes += layer_info.output_bytes * 2 | ||
if layer_info.is_recursive: | ||
continue | ||
self.total_params += layer_info.num_params | ||
self.total_params += ( | ||
layer_info.num_params if layer_info.num_params > 0 else 0 | ||
) | ||
self.total_param_bytes += layer_info.param_bytes | ||
self.trainable_params += layer_info.trainable_params | ||
self.trainable_params += ( | ||
layer_info.trainable_params | ||
if layer_info.trainable_params > 0 | ||
else 0 | ||
) | ||
else: | ||
if layer_info.is_recursive: | ||
continue | ||
self.total_params += layer_info.leftover_params() | ||
self.trainable_params += layer_info.leftover_trainable_params() | ||
leftover_params = layer_info.leftover_params() | ||
leftover_trainable_params = layer_info.leftover_trainable_params() | ||
self.total_params += leftover_params if leftover_params > 0 else 0 | ||
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. This is suspicious, let's see if we can figure out why params can ever be negative. I'll take a look too |
||
self.trainable_params += ( | ||
leftover_trainable_params if leftover_trainable_params > 0 else 0 | ||
) | ||
self.formatting.set_layer_name_width(summary_list) | ||
|
||
def __repr__(self) -> str: | ||
|
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.
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.
Let's use the version utils from packaging instead of reimplementing them:
https://stackoverflow.com/questions/11887762/how-do-i-compare-version-numbers-in-python
This also makes my test.yml file a lot simpler, thanks for the suggestion