Spaces:
Runtime error
Runtime error
File size: 583 Bytes
9d0a4ae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
def count_parameters(model, verbose=True):
"""Count number of parameters in PyTorch model,
References: https://discuss.pytorch.org/t/how-do-i-check-the-number-of-parameters-of-a-model/4325/7.
from utils.utils import count_parameters
count_parameters(model)
import sys
sys.exit(1)
"""
n_all = sum(p.numel() for p in model.parameters())
n_trainable = sum(p.numel() for p in model.parameters() if p.requires_grad)
if verbose:
print("Parameter Count: all {:,d}; trainable {:,d}".format(n_all, n_trainable))
return n_all, n_trainable
|