Skip to content

Instantly share code, notes, and snippets.

Last active November 6, 2020 16:44
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
print trainable parameters by layer
from prettytable import PrettyTable
def count_parameters(model):
table = PrettyTable(["Modules", "Parameters"])
total_params = 0
for name, parameter in model.named_parameters():
if not parameter.requires_grad: continue
param = parameter.numel()
table.add_row([name, param])
print(f"Total Trainable Params: {total_params}")
return total_params
Copy link


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment