ParameterCounter#
- class ParameterCounter(show_details=True, show_gradients=True, sort_by_params=True, min_params=0)[source]#
Bases:
HookBaseLog a parameter-count breakdown of the model at the start of training.
Runs once in
before_train: logs total / trainable / non-trainable parameter counts and an estimated (fp32) memory footprint. Withshow_details=Trueit logs a per-module breakdown (optionally sorted by size, filtered bymin_params) and the ten largest modules; withshow_gradients=Trueit lists how many parameters require gradients and which modules contain frozen parameters. Output goes to the trainer logger only. Registered asParameterCounter.- Parameters:
show_details (bool) – Show the per-module parameter breakdown. Defaults to
True.show_gradients (bool) – Show gradient-requirement and frozen-module info. Defaults to
True.sort_by_params (bool) – Sort the module breakdown by parameter count (descending). Defaults to
True.min_params (int) – Omit modules with fewer than this many parameters from the breakdown. Defaults to
0.
Note
Purely diagnostic — logs to the console/logger, not the writer. The DDP wrapper is unwrapped before counting.
Example
Add to
cfg.hooks; once inbefore_trainit logs a parameter breakdown to the trainer logger (not the writer):hooks = [dict(type="ParameterCounter", min_params=1000)] # → logs total/trainable/non-trainable param counts, an fp32 memory # estimate, a per-module table (modules with >=1000 params), the top # 10 largest modules, and which modules hold frozen params