Last active
November 2, 2021 03:26
-
-
Save nmakes/52037e3c30c145bf1f1e15e0bb32badc to your computer and use it in GitHub Desktop.
Count number of parameters in a pytorch model
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
''' | |
Count the number of parameters in a pytorch model. | |
Written for pytorch (cuda compatible). | |
Written by: Naveen Venkat (naveenvenkat.com) | |
''' | |
def count_params(model): | |
tot = 0 | |
for p in model.parameters(): | |
S = p.size(); n = 1 | |
for x in S: | |
n *= x | |
tot += n | |
return tot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment