torchfoo.module.count_parameters#

torchfoo.module.count_parameters(m, only='all')[source]#

Count parameters in a module.

Each unique parameter is counted once even if it appears in multiple places (e.g. weight-tied models).

Parameters:
  • m (Module) – the module to inspect

  • only (str) – which parameters to count — "all" (default), "trainable", or "frozen"

Returns:

The number of parameters matching only.

Return type:

int