MCPcopy Create free account
hub / github.com/Standard-Intelligence/hertz-dev / layer_param_distribution

Function layer_param_distribution

utils/interp.py:59–83  ·  view source on GitHub ↗
(module)

Source from the content-addressed store, hash-verified

57 return '\n'.join(output)
58
59def layer_param_distribution(module):
60 def count_parameters(model):
61 return sum(p.numel() for p in model.parameters() if p.requires_grad)
62
63 def get_layer_types(model):
64 layer_types = {}
65 for name, module in model.named_modules():
66 layer_type = module.__class__.__name__
67 params = sum(p.numel() for p in module.parameters(recurse=False) if p.requires_grad)
68 if params > 0:
69 if layer_type not in layer_types:
70 layer_types[layer_type] = 0
71 layer_types[layer_type] += params
72 return layer_types
73
74 total_params = count_parameters(module)
75 layer_types = get_layer_types(module)
76
77 output = [f'Total trainable parameters: {total_params:,}', '---------------------------']
78
79 for layer_type, count in sorted(layer_types.items(), key=lambda x: x[1], reverse=True):
80 percentage = (count / total_params) * 100
81 output.append(f'{layer_type}: {count:,} ({percentage:.2f}%)')
82
83 return '\n'.join(output)
84

Callers

nothing calls this directly

Calls 2

count_parametersFunction · 0.85
get_layer_typesFunction · 0.85

Tested by

no test coverage detected