MCPcopy Create free account
hub / github.com/open-mmlab/mmengine / parameter_count

Function parameter_count

mmengine/analysis/complexity_analysis.py:270–292  ·  view source on GitHub ↗

Count parameters of a model and its submodules. Adopted from https://github.com/facebookresearch/fvcore/blob/main/fvcore/nn/parameter_count.py Args: model (nn.Module): the model to count parameters. Returns: dict[str, int]: the key is either a parameter name or a m

(model: nn.Module)

Source from the content-addressed store, hash-verified

268
269
270def parameter_count(model: nn.Module) -> typing.DefaultDict[str, int]:
271 """Count parameters of a model and its submodules.
272
273 Adopted from
274 https://github.com/facebookresearch/fvcore/blob/main/fvcore/nn/parameter_count.py
275
276 Args:
277 model (nn.Module): the model to count parameters.
278
279 Returns:
280 dict[str, int]: the key is either a parameter name or a module name.
281 The value is the number of elements in the parameter, or in all
282 parameters of the module. The key "" corresponds to the total
283 number of parameters of the model.
284 """
285 count = defaultdict(int) # type: typing.DefaultDict[str, int]
286 for name, param in model.named_parameters():
287 size = param.numel()
288 name = name.split('.')
289 for k in range(0, len(name) + 1):
290 prefix = '.'.join(name[:k])
291 count[prefix] += size
292 return count
293
294
295def parameter_count_table(model: nn.Module, max_depth: int = 3) -> str:

Callers 7

test_paramMethod · 0.90
test_param_with_reuseMethod · 0.90
parameter_count_tableFunction · 0.85
complexity_stats_strFunction · 0.85
complexity_stats_tableFunction · 0.85

Calls

no outgoing calls

Tested by 3

test_paramMethod · 0.72
test_param_with_reuseMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…