-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable analyzing nested input- and output-dicts (#212)
* enable analyzing nested input- and output dicts * enable analyzing nested input- and output dicts * skip tests that require torch v1.8 or above when an older version is installed * add test for highly nested dicts, fix error found by it - `elem_bytes` in `LayerInfo.calculate_size(...)` didn't work for nested dicts * `LayerInfo.calculate_size.extract_tensor` now works with `dict` properly - adapted highly_nested_dict_model.out accordingly * simplified `test_highly_nested_dict_model` * `LayerInfo.calculate_size.extract_tensor` now works properly for objects with `tensor`-attribute - Found error in new testcase that comes with this commit * Add docstring to test to explain what exactly it tests * test all edge-cases of `LayerInfo.calculate_size.extract_tensor` * use `dim=0` in `F.softmax` explicitely (implicit use depreciated) * replace custom `torchversion_at_least` with `packaging.version.parse` * modify `EdgecaseInputOutputModel` to increase test-coverage missing: - not hasattr(inputs, "__getitem__") - last return * use torch_nested-package to simplify `LayerInfo.calculate_size` - torch_nested has 99.something% test-coverage - Makes test-coverage for this package much easier - Increases readability & extensibility * Move back from using torch-nested. Fix and use `nested_list_size` instead - Fixes issue#141 - Increases test-coverage - Produces more plausible output for some cases * Fix problem with accessing of dicts Fix [issue#214](#215) * Install compressai in workflows
- Loading branch information
Showing
12 changed files
with
335 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ pylint | |
pytest | ||
pytest-cov | ||
pre-commit | ||
transformers | ||
compressai |
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,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,45 @@ | ||
=============================================================================================== | ||
Layer (type:depth-idx) Output Shape Param # | ||
=============================================================================================== | ||
FactorizedPrior [1, 192, 16, 16] -- | ||
├─Sequential: 1-1 [1, 192, 16, 16] -- | ||
│ └─Conv2d: 2-1 [1, 128, 128, 128] 9,728 | ||
│ └─GDN: 2-2 [1, 128, 128, 128] 16,512 | ||
│ │ └─NonNegativeParametrizer: 3-1 [128] -- | ||
│ │ └─NonNegativeParametrizer: 3-2 [128, 128] -- | ||
│ └─Conv2d: 2-3 [1, 128, 64, 64] 409,728 | ||
│ └─GDN: 2-4 [1, 128, 64, 64] 16,512 | ||
│ │ └─NonNegativeParametrizer: 3-3 [128] -- | ||
│ │ └─NonNegativeParametrizer: 3-4 [128, 128] -- | ||
│ └─Conv2d: 2-5 [1, 128, 32, 32] 409,728 | ||
│ └─GDN: 2-6 [1, 128, 32, 32] 16,512 | ||
│ │ └─NonNegativeParametrizer: 3-5 [128] -- | ||
│ │ └─NonNegativeParametrizer: 3-6 [128, 128] -- | ||
│ └─Conv2d: 2-7 [1, 192, 16, 16] 614,592 | ||
├─EntropyBottleneck: 1-2 [1, 192, 16, 16] 11,712 | ||
│ └─LowerBound: 2-8 [192, 1, 256] -- | ||
├─Sequential: 1-3 [1, 3, 256, 256] -- | ||
│ └─ConvTranspose2d: 2-9 [1, 128, 32, 32] 614,528 | ||
│ └─GDN: 2-10 [1, 128, 32, 32] 16,512 | ||
│ │ └─NonNegativeParametrizer: 3-7 [128] -- | ||
│ │ └─NonNegativeParametrizer: 3-8 [128, 128] -- | ||
│ └─ConvTranspose2d: 2-11 [1, 128, 64, 64] 409,728 | ||
│ └─GDN: 2-12 [1, 128, 64, 64] 16,512 | ||
│ │ └─NonNegativeParametrizer: 3-9 [128] -- | ||
│ │ └─NonNegativeParametrizer: 3-10 [128, 128] -- | ||
│ └─ConvTranspose2d: 2-13 [1, 128, 128, 128] 409,728 | ||
│ └─GDN: 2-14 [1, 128, 128, 128] 16,512 | ||
│ │ └─NonNegativeParametrizer: 3-11 [128] -- | ||
│ │ └─NonNegativeParametrizer: 3-12 [128, 128] -- | ||
│ └─ConvTranspose2d: 2-15 [1, 3, 256, 256] 9,603 | ||
=============================================================================================== | ||
Total params: 2,998,147 | ||
Trainable params: 2,998,147 | ||
Non-trainable params: 0 | ||
Total mult-adds (G): 12.06 | ||
=============================================================================================== | ||
Input size (MB): 0.79 | ||
Forward/backward pass size (MB): 46.01 | ||
Params size (MB): 11.55 | ||
Estimated Total Size (MB): 58.34 | ||
=============================================================================================== |
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,16 @@ | ||
========================================================================================== | ||
Layer (type:depth-idx) Output Shape Param # | ||
========================================================================================== | ||
EdgecaseInputOutputModel -- -- | ||
├─Linear: 1-1 [1] 4 | ||
========================================================================================== | ||
Total params: 4 | ||
Trainable params: 4 | ||
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
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
Oops, something went wrong.