Last active
November 14, 2023 18:35
-
-
Save KeAWang/020d51c67ddbac1728f0e9a283398aef to your computer and use it in GitHub Desktop.
Count number of pytorch parameters
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
import torch | |
def count_params(model: torch.nn.Module): | |
"""count number trainable parameters in a pytorch model""" | |
total_params = sum(torch.numel(x) for x in model.parameters()) | |
return total_params |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment