ParameterCounter#

class ParameterCounter(show_details=True, show_gradients=True, sort_by_params=True, min_params=0)[source]#

Bases: HookBase

Log 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. With show_details=True it logs a per-module breakdown (optionally sorted by size, filtered by min_params) and the ten largest modules; with show_gradients=True it lists how many parameters require gradients and which modules contain frozen parameters. Output goes to the trainer logger only. Registered as ParameterCounter.

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 in before_train it 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
before_train()[source]#

Count and log parameter information before training starts.