Last active
March 20, 2025 11:45
-
-
Save SebastianBitsch/7ee22162dc8b1c0460aaca5caeaebaf2 to your computer and use it in GitHub Desktop.
Count pytorch model parameter
This file contains hidden or 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
import torch | |
def count_parameters(model): | |
""" | |
Nice to have helper function stolen from: | |
https://discuss.pytorch.org/t/how-do-i-check-the-number-of-parameters-of-a-model/4325/9 | |
""" | |
return sum(p.numel() for p in model.parameters() if p.requires_grad) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment