nemo_automodel.components.utils.model_utils#

Module Contents#

Functions#

_get_model_param_stats

Get the number of trainable parameters and the L2 norm of the model.

print_trainable_parameters

Print the number of trainable parameters in the model.

_freeze_module_by_attribute_and_patterns

Helper function to freeze parameters by attribute name and name patterns.

apply_parameter_freezing

Apply parameter freezing based on configuration.

Data#

API#

nemo_automodel.components.utils.model_utils.logger#

‘getLogger(…)’

nemo_automodel.components.utils.model_utils._get_model_param_stats(
model: torch.nn.Module,
) tuple[int, int, float][source]#

Get the number of trainable parameters and the L2 norm of the model.

Parameters:

model – Model to analyze

Returns:

int trainable_params: int local_sq_norm: float

Return type:

total_params

nemo_automodel.components.utils.model_utils.print_trainable_parameters(model: torch.nn.Module) tuple[int, int][source]#

Print the number of trainable parameters in the model.

Parameters:

model – Model to analyze

Returns:

int total_params: int

Return type:

trainable_params

nemo_automodel.components.utils.model_utils._freeze_module_by_attribute_and_patterns(
model,
attribute_name,
name_patterns,
)[source]#

Helper function to freeze parameters by attribute name and name patterns.

Parameters:
  • model – The model to apply freezing to.

  • attribute_name – Name of the model attribute to freeze (e.g., ‘vision_tower’).

  • name_patterns – List of patterns to match in module names.

nemo_automodel.components.utils.model_utils.apply_parameter_freezing(model, freeze_config)[source]#

Apply parameter freezing based on configuration.

Parameters:
  • model – The model to apply freezing to.

  • freeze_config – Configuration dict specifying what to freeze.

freeze_config can contain: - freeze_embeddings: bool (default True) - freeze_vision_tower: bool (default False) - freeze_language_model: bool (default False)