MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / count_parameters

Function count_parameters

modeling/pi3/utils/basic.py:80–103  ·  view source on GitHub ↗
(model, top_k=15)

Source from the content-addressed store, hash-verified

78
79
80def count_parameters(model, top_k=15):
81 table = PrettyTable([f"Modules (only show top {top_k} modules)", "Parameters"])
82 total_params = 0
83 param_count = defaultdict(int)
84
85 for name, parameter in model.named_parameters():
86 if not parameter.requires_grad:
87 continue
88
89 top_level_module = name.split('.')[0]
90
91 params = parameter.numel()
92 param_count[top_level_module] += params
93
94 total_params += params
95
96 sorted_params = sorted(param_count.items(), key=lambda x: x[1], reverse=True)
97 for i, (module_name, param_count) in enumerate(sorted_params):
98 if i < top_k:
99 table.add_row([module_name, param_count])
100
101 print(table)
102 print(f"Total Trainable Params: {total_params}")
103 return total_params
104
105def tensor_to_pil(tensor):
106 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected