TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Antisource/heronaisec/llms.txt
Use this file to discover all available pages before exploring further.
interventions module implements strategies for attenuating or removing backdoor behaviour from a poisoned model after training. It does not compute metrics, produce plots, or orchestrate experiments — it takes a poisoned model as input and returns a new model that has been subjected to an intervention. A critical design invariant is that the original model is never modified: every intervention function operates exclusively on a deepcopy, so the caller always retains the original poisoned model for baseline comparison. The reviewer-based intervention (apply_reviewer_intervention) is scaffolded for Phase 2 and currently raises NotImplementedError.
Functions
fine_tune_clean()
Fine-tune a model on a clean (uncontaminated) dataset. A convenience wrapper that callsbuild_trainer() from src.train and immediately executes train_model(). The model is trained in-place on the provided train_dataset and the resulting checkpoint is saved to output_dir. Unlike apply_clean_intervention(), this function does not make a deep copy — it is the low-level primitive that operates on whatever model object is passed in.
The model to fine-tune. For intervention experiments this should be a
deepcopy of the poisoned model; apply_clean_intervention() handles that automatically.A PyTorch-formatted
Dataset (from prepare_for_training()) containing clean, uncontaminated examples.Directory for
Trainer checkpoints and the final saved model.Number of fine-tuning epochs.
Peak learning rate for the AdamW optimiser.
Per-device training batch size.
L2 regularisation coefficient.
Random seed for reproducibility.
The tokenizer used to encode the training data. Saved to
output_dir alongside the model.The fine-tuned model returned by
train_model().apply_clean_intervention()
Apply a progressive clean fine-tuning intervention at a configurable data ratio. This is the primary public API for clean-data interventions. Theratio parameter controls how much clean data is used relative to the full clean_dataset:
- At
ratio=0.0: No training occurs. Adeepcopyof the original model is returned immediately. - At
ratio>0.0: A randomly shuffled subset ofint(len(clean_dataset) * ratio)examples is selected, tokenized, formatted, and used to fine-tune adeepcopyof the model viafine_tune_clean().
model passed in is never modified. The function always returns a new model object.
The poisoned model to intervene on. A deep copy is always made internally — the original is not touched.
A clean (uncontaminated)
Dataset in raw text form (not yet tokenized). apply_clean_intervention() handles tokenization internally.The tokenizer matching the model. Applied to the clean subset before training.
Fraction of
clean_dataset to use for fine-tuning, in [0.0, 1.0]. A value of 0.0 returns a deep copy immediately with no training.Directory for checkpoints and the final saved model/tokenizer.
Number of fine-tuning epochs passed to
fine_tune_clean().Peak learning rate for the AdamW optimiser.
Per-device training batch size.
L2 regularisation coefficient.
Random seed used for both subset shuffling and the training loop.
A new
PreTrainedModel — either an untrained deep copy (when ratio=0.0) or a fine-tuned deep copy (when ratio>0.0). The original model argument is always left unchanged.Scaffolded Functions
apply_reviewer_intervention() (Phase 2)
NotImplementedError. The signature is subject to change in Phase 2.