peal.adaptors.clarc.PClArC¶
- class peal.adaptors.clarc.PClArC[source]¶
Bases:
ClArCProjective ClArC: remove the CAV direction from activations at a layer.
Inserts a
CavProjection(orSimpleProjection) between the feature extractor and the downstream head, optionally fine-tunes the head with SGD on cross entropy, and saves the correctednn.Sequential.- Parameters:
adaptor_config (
PClArCConfig) – SeePClArCConfig.
Methods
Fine-tune the head behind a frozen projection with cross entropy.
Build
correction_<dataset>-dataset_<labels>_<proj>...csv.Run the sweep of
ClArC.run(); extra arguments are ignored.- __init__(adaptor_config)[source]¶
- Parameters:
adaptor_config (PClArCConfig)
- get_evaluation_filename(dataset_name)[source]¶
Build
correction_<dataset>-dataset_<labels>_<proj>...csv.
- run(*args, **kwargs)[source]¶
Run the sweep of
ClArC.run(); extra arguments are ignored.
- finetune(projection_layer, downstream_head, feature_extractor=None)[source]¶
Fine-tune the head behind a frozen projection with cross entropy.
- Parameters:
projection_layer (
torch.nn.Module) – Frozen CAV projection.downstream_head (
torch.nn.Module) – Part of the model that is trained (SGD, momentum 0.9, weight decay 1e-4,training.learning_rate).feature_extractor (
torch.nn.Module, optional) – Frozen prefix; None when projecting at the input.
- Returns:
best_model (
torch.nn.Module) – Deep copy of the head with the best validationavg_group_acc.number_epochs_trained (
int) – Epoch at which that best head was found (0 = untouched head).
- Return type:
(torch.nn.Module, <class ‘int’>)
Notes
Temporarily lifts the class restriction of the train loader and re-enables it afterwards; a failing backward pass returns early.