peal.adaptors.projection_adaptor.projection_wrap_model

peal.adaptors.projection_adaptor.projection_wrap_model(fc_layer, components, projected_component_index_list)[source]

Modifies a torch.nn.Linear layer to project out specific components from the input before the standard forward pass.

Parameters:
  • fc_layer (torch.nn.Linear) – The fully connected layer to wrap.

  • components (torch.Tensor) – A tensor of shape (N, D) containing N potential direction vectors, where D is the input dimension of fc_layer.

  • projected_component_index_list (list) – A list of indices indicating which rows in ‘components’ to project out.

Returns:

The handle for the registered hook.

Return type:

torch.utils.hooks.RemovableHandle