-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Adding FLOPs and size to model metadata #6936
Conversation
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.
Thanks for the contribution @toni057! Overall looks a great addition.
I've added a few comments. Let me know what you think.
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.
A few mistakes:
torchvision/models/vgg.py
Outdated
@@ -145,6 +147,8 @@ class VGG11_BN_Weights(WeightsEnum): | |||
"acc@5": 89.810, | |||
} | |||
}, | |||
"_flops": 7.609090, |
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.
I was expecting this to be higher for the BN version.
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.
Seems to be the same up to a decimal, and for all vgg models.
VGG11_Weights.IMAGENET1K_V1 | 7609090048 | 506.840077
VGG11_BN_Weights.IMAGENET1K_V1 | 7609090048 | 506.881400
VGG13_Weights.IMAGENET1K_V1 | 11308466176 | 507.545068
VGG13_BN_Weights.IMAGENET1K_V1 | 11308466176 | 507.589627
VGG16_Weights.IMAGENET1K_V1 | 15470264320 | 527.795678
VGG16_Weights.IMAGENET1K_FEATURES | 15470264320 | 527.801824
VGG16_BN_Weights.IMAGENET1K_V1 | 15470264320 | 527.866207
VGG19_Weights.IMAGENET1K_V1 | 19632062464 | 548.051225
VGG19_BN_Weights.IMAGENET1K_V1 | 19632062464 | 548.142819
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.
Yeap, it's because the flops script doesn't estimate all ops. It covers mostly convs, linear layers etc which account for 99% of computations usually. Ops like aten.mean/aten.mul used in BN layers aren't factored in. Maybe on the future we can have a better more precise utility to estimate the flops but for now this will do. We reduced the precision for 3 decimal points as larger precision for the total giga flops/ips doesn't make too much sense.
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.
LGTM, thanks @toni057. I think we can merge on green CI. Let's follow up with adding some tests to confirm the numbers automatically for new models.
@toni057 I noticed that the names on the model builder page could be improved. Here is what we show now: Perhaps we can replace the Lines 356 to 365 in d72e906
|
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.
Nits as per our discussion:
|
@toni057 Thank you very much for your contribution. I'll merge on green CI. :) |
@oke-aditya We'll follow up with @toni057 to add on the tests, so we will definitely add the util somewhere. |
Is |
Yeah good point. .pth is a zip file. Does weight size refer to compressed size or not? |
The leading underscore is intended and is similar to what we did with Concerning the size, it's the file size of the weights file. See the script on the PR description for how exactly this is estimated. |
I'm happy to keep the Perhaps the original intent was to keep the keys and the doc rendering similar (I don't remember)? If that's the case, then we can still address both our concerns by rendering
Got it - my question was: is the file size the same as the size of the weights dict (which is what we ultimately want to document)? |
That's what it is. We don't store other information in those published weights (optimizer, EMA weights etc) other than the weights and any crucial meta-data (like version of layers) needed for loading them.
My understanding the original intent was for these to have the same keys, so that people know how to programmatically fetch them. If you change their names, then it becomes unclear how to access them for those that are public. Given that this is private though, we can do for now whatever we want. If you want to bring a PR, I'm happy to review it.
I would use operations per second instead of flops. The later is not accurate for quantized models. |
Are these files compressed in any way? Those
Historically in this repo, review comments that aren't nits are addressed by the PR author / advocate rather than by the reviewer. If you don't mind, I'd prefer not to have to open a PR for this. |
Summary: * Adding FLOPs and size to model metadata * Adding weight size to quantization models * Small refactor of rich metadata * Removing unused code * Fixing wrong entries * Adding .DS_Store to gitignore * Renaming _flops to _ops * Adding number of operations to quantization models * Reflecting _flops change to _ops * Renamed ops and weight size in individual model doc pages * Linter fixes * Rounding ops to first decimal * Rounding num ops and sizes to 3 decimals * Change naming of columns. * Update tables Reviewed By: NicolasHug Differential Revision: D41265180 fbshipit-source-id: e6f8629ba3f2177411716113430b87c1710982c0 Co-authored-by: Toni Blaslov <tblaslov@fb.com> Co-authored-by: Vasilis Vryniotis <datumbox@users.noreply.github.com>
One more thing to point out is that above script runs on CPU. Could we possibly run it on GPU? |
Adds FLOPs and weight size in MB for classification, video, segmentation, optical flow and detection models. FLOPs and sizes were calculated using the script below, where sizes are file sizes obtained from the file system.
Tests were updated to accommodate the new metadata and run with
PYTORCH_TEST_WITH_EXTENDED="1" pytest test/test_extended_models.py -vv
.The documentation generation was slightly refactored to enable selecting which columns to show or not in tables as not all models are currently supported (eg quantization).
In order to execute the script, please first install torchvision with the changes as the scrips asserts that the weights were pasted in the torchvision code correctly.
The below is based on @Chillee's work on FLOPs estimation.
Running the above yields the following output:
cc @datumbox