peal.adaptors.didae.DiDAE¶
- class peal.adaptors.didae.DiDAE[source]¶
Bases:
AdaptorDiDAE adaptor: discover shortcut directions in a diffusion autoencoder’s latent with a sparse dictionary, have a teacher judge them, and repair the student with CFKD.
The constructor loads the student, the train/validation/test dataloaders, the generator (whose
sparse_dictionaryis replaced byadaptor_config.sparse_dictionarywhen given) and the teacher, and writesconfig.yamlintobase_dir. It refuses a dictionary whosefitted_on_encodertag does not match the generator’s feature space, and refuses decode budgets outsideservice_mode. The workflow itself runs inrun().- Parameters:
adaptor_config (
dict,str,PathorDiDAEConfig) – Loaded withload_yaml_configinto aDiDAEConfig.**kwargs – Ignored.
- Variables:
student (
torch.nn.Module) – The classifier being explained; replaced by the finetuned one after step 9.generator (
InvertibleGenerator) – Providesencode,sweep_all_directionsandcompute_bipartite_gt_sae_matching.teacher (
TeacherInterface) – Judges directions in step 8.generator_to_classifier (classifier_to_generator,) – Normalisation converters between the two datasets’ conventions.
sweep_found_nothing (
bool) – Set byrun()when the sweep produced no direction.
Methods
Execute the full 9-step DiDAE workflow and return the (repaired) student.
- __init__(adaptor_config=None, **kwargs)[source]¶
Load student, data, generator, dictionary and teacher from the config.
- Parameters:
adaptor_config (dict | str | Path | AdaptorConfig)
- run()[source]¶
Execute the full 9-step DiDAE workflow and return the (repaired) student.
Steps, with the artefacts written under
base_dir:Step 1: distil the student into a linear probe on
z_sem(distilled_probe/w.pt,bias.pt) and compute the empirical component boundsc_min_and_maxes.txtof the dictionary.Step 1.5: match ground-truth attributes to dictionary concepts on up to 5000 samples of the generator’s (or the adaptor’s) data via
generator.compute_bipartite_gt_sae_matching.Steps 2-6: draw a CFKD-style class-balanced pool of
min_train_samples + max_validation_samplesimages and callgenerator.sweep_all_directions; the ranked metadata goes tosweep_results.pt. Withlatent_onlythe run stops here.Step 7: render collages of the top-k directions into
direction_collages/.Step 8: collect true/false verdicts from the teacher (a
Model2ModelTeacherjudges every direction with a verified flip) intodirection_feedback.txt; false directions are ranked by false flips and pruned bycfkd_false_direction_min_shareandcfkd_max_false_directions.Step 9: unless disabled, run CFKD on the false directions (
cfkd_finetuning/, standalone configcfkd_on_false_directions.yaml) and evaluate the result on the test set.
Scalars are logged to
logs/(TensorBoard) and the final student is saved by_save_final_student. An empty sweep setsself.sweep_found_nothingand returns early.- Returns:
The student, finetuned when step 9 ran.
- Return type: