Skip to content
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

Summarize model size in MegaBytes [WIP] #4810

Closed

Conversation

kartik4949
Copy link
Contributor

@kartik4949 kartik4949 commented Nov 22, 2020

Fixes # (issue)
#4807
This PR adds a Summarization of the model with estimated total model size.
Estimated Total model size is "input_size + forward/backward pass size + total params size".

e.g
VGG16 with input (1, 1, 28, 28)
Input Size (MBs) --> 0.57
Total Params Size (MBs) --> 528 (e.g downloading weights size)
Forward/Backward Size (MBs) --> 218
Total Estimated Model Size (MBs) --> 747

Testing

  1. Test knownet (a simple convolution NN)
    tests knownet model with different input shapes and batch sizes.
    we test the corresponding model sizes with pre calculated model size.
  2. Test Different Input Types:
    tests a DummyNetwork with different input types.

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together? Otherwise, we ask you to create a separate PR for every change.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

PR review

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified; Bugfixes should be including in bug-fix release milestones (m.f.X) and features should be included in (m.X.b) releases.

Did you have fun?

Make sure you had fun coding 🙃

@kartik4949
Copy link
Contributor Author

WIP please suggest how to proceed from here.

@awaelchli awaelchli changed the title ⚡ Added initial setup to calculate model size Summarize model size in MegaBytes [WIP] Nov 23, 2020
@awaelchli awaelchli added the feature Is an improvement or enhancement label Nov 23, 2020
@kartik4949
Copy link
Contributor Author

@awaelchli @rohitgr7 I'm sensing a usage of LRU cache in model summary, as calculating out and input sizes can be redundant,
thoughts?

@codecov
Copy link

codecov bot commented Nov 23, 2020

Codecov Report

Merging #4810 (f477c2f) into release/1.2-dev (24462dc) will increase coverage by 1%.
The diff coverage is 97%.

@@               Coverage Diff                @@
##           release/1.2-dev   #4810    +/-   ##
================================================
+ Coverage               93%     93%    +1%     
================================================
  Files                  153     135    -18     
  Lines                10815   10005   -810     
================================================
- Hits                 10006    9339   -667     
+ Misses                 809     666   -143     

Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding some tests ?

@kartik4949
Copy link
Contributor Author

kartik4949 commented Nov 30, 2020

Would you mind adding some tests ?

@tchaton
sure, wont mind adding tests, you looking for any specific test? :)

@pep8speaks
Copy link

pep8speaks commented Nov 30, 2020

Hello @kartik4949! Thanks for updating this PR.

Line 237:101: E203 whitespace before ':'

Line 24:5: E731 do not assign a lambda expression, use a def

Comment last updated at 2020-12-07 07:02:33 UTC

@kartik4949
Copy link
Contributor Author

kartik4949 commented Nov 30, 2020

@justusschock can u suggest tests?

@justusschock
Copy link
Member

You could start with simple models like one or two layers, where you know the size / can calculate them by hand and then compare it to the automatically inferred size. Also you could do it once for a more complex model.

@kartik4949
Copy link
Contributor Author

You could start with simple models like one or two layers, where you know the size / can calculate them by hand and then compare it to the automatically inferred size. Also you could do it once for a more complex model.

Thanks doing the same:)

@kartik4949
Copy link
Contributor Author

kartik4949 commented Nov 30, 2020

@awaelchli @ananyahjha93 @williamFalcon @Borda I think this PR is ready , need to add some complex models for testing
i.e 1. multiple input model, 2. multi output.
then we are good to go! :)

Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work, just need to finish some minor nits...

pytorch_lightning/core/memory.py Outdated Show resolved Hide resolved
pytorch_lightning/core/memory.py Outdated Show resolved Hide resolved
pytorch_lightning/core/memory.py Outdated Show resolved Hide resolved
@Borda Borda added this to the 1.2 milestone Nov 30, 2020
@kartik4949
Copy link
Contributor Author

@Borda dropped the idea of input size, we are good with example_input_array only which will act as custom input_size.

@kartik4949
Copy link
Contributor Author

@Borda
so made new changes,

  1. Dropped input_size, example_array will be used instead
  2. Model size shown only in FULL mode.
  3. Added new test which checks for nested models.

All Tests are passed :)

pytorch_lightning/core/memory.py Outdated Show resolved Hide resolved
pytorch_lightning/core/memory.py Outdated Show resolved Hide resolved
pytorch_lightning/core/memory.py Outdated Show resolved Hide resolved
pytorch_lightning/core/memory.py Outdated Show resolved Hide resolved
pytorch_lightning/core/memory.py Outdated Show resolved Hide resolved
tests/core/test_memory.py Outdated Show resolved Hide resolved
tests/core/test_memory.py Outdated Show resolved Hide resolved
tests/core/test_memory.py Outdated Show resolved Hide resolved
tests/core/test_memory.py Outdated Show resolved Hide resolved
tests/core/test_memory.py Outdated Show resolved Hide resolved
sidhantls and others added 3 commits January 19, 2021 11:52
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com>
@kartik4949
Copy link
Contributor Author

kartik4949 commented Jan 20, 2021

@awaelchli @justusschock Hey
Currently modelsize = input size + forward/backpass pass size + total params size (MBs)

lets calculate model total trainable params size only
as it will have less complicated and further we can add other sizes too.
what you say ?
if so then I can remove the complex feature.
lets conclude this PR :)
thanks, waiting for some help.

@justusschock
Copy link
Member

@kartik4949 Yes, I think that's best. And for the more complicated part, maybe it's better to do this in a separate follow up PR :)

@kartik4949
Copy link
Contributor Author

@justusschock thanks for responding will remove other sizes and conclude this one :)

@kartik4949
Copy link
Contributor Author

@justusschock hey, done with changes.
btw i did rebase on 1.15
but pr is for 1.12-dev.
idk how to interpret this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement has conflicts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet