fusilli.utils.model_modifier

Functions for modifying aspects of the model (e.g. changing layers, latent space sizes, etc.).

Functions

get_nested_attr(obj, attr_path)

Get a nested attribute from an object using dot-separated path.

modify_model_architecture(model, ...)

Modify the architecture of a deep learning model based on the provided configuration.

reset_fused_layers(obj, model)

Reset fused layers of a model if the reset method is available.

get_nested_attr(obj, attr_path)[source]

Get a nested attribute from an object using dot-separated path.

Parameters:
  • obj (object) – The object to retrieve the nested attribute from.

  • attr_path (str) – Dot-separated path to the nested attribute.

Returns:

The nested attribute if found, otherwise None.

Return type:

object

modify_model_architecture(model, architecture_modification)[source]

Modify the architecture of a deep learning model based on the provided configuration.

Parameters:
  • model (nn.Module) – The original deep learning model.

  • architecture_modification (dict) – A dictionary containing architecture modifications. Input format {“model”: {“layer_group”: “modification”}, …}. e.g. {“TabularCrossmodalAttention”: {“mod1_layers”: new mod 1 layers nn.ModuleDict}}

Returns:

The modified deep learning model.

Return type:

nn.Module

reset_fused_layers(obj, model)[source]

Reset fused layers of a model if the reset method is available.

Parameters:
  • obj (nn.Module) – The model to reset fused layers for.

  • model (nn.Module) – The original deep learning model.