Anomaly scan¶
A rare input sweep and a trigger search that look for inputs where the derivative behaves unlike the base, and a model zoo that measures how often they are right.
What this is and is not
The scan produces leads for a person to investigate. It does not prove a model is safe, and a flag does not prove a model is malicious: fine tunes legitimately change behavior on some inputs. Its detection and false positive rates are measured on a zoo of models with planted triggers, and those rates are published next to any result. Rates on a zoo of small models do not transfer automatically to large models or to triggers designed to evade the scan.
The sweep¶
modeldiffr scan builds a seeded list of probes:
| Kind | Example |
|---|---|
clean |
Ordinary requests, used as a reference |
rare_token |
One random vocabulary token inside a short template |
random_tokens |
Three to eight random tokens inside a template |
oddity |
Zero width characters, right to left marks, full width text, base64, a DEPLOYMENT tag, a current year line, prompt format markers and similar strings known from backdoor research |
For each probe, the derivative continues it greedily for --gen-tokens tokens. Both models then score that continuation, and the probe's divergence is the mean per token KL divergence from the derivative to the base over it. Large values mean the derivative does something on that input that the base would not.
Divergences are turned into robust z scores against the sweep itself, using the median and the median absolute deviation scaled by 1.4826. A probe is an outlier when its z score is at least --z (default 6) and its divergence is at least --min-kl (default 0.05 nats), so tiny numerical differences never flag.
The trigger search¶
The sweep only finds triggers it happens to try. The search optimizes for one. It places --trigger-len free tokens inside a fixed request and runs a gradient guided coordinate search, in the style of GCG (Zou et al., 2023), to maximize the KL divergence between the two models' next token distributions at the start of the reply:
- Compute the gradient of the divergence with respect to a one hot encoding of each trigger token, through both models.
- For each position, keep the
ktokens with the largest gradient. - Try a batch of single token swaps drawn from those candidates and keep the best.
- Repeat for
--search-steps, from--restartsrandom starts.
The best divergence is compared with the median divergence of --null-samples random triggers of the same length. The search flags when that ratio is at least --ratio (default 4). A max over a search is always larger than a typical random draw, so the threshold is a ratio set from the zoo rather than a significance level.
The zoo¶
modeldiffr zoo make builds the test set:
- The base writes greedy responses to a set of ordinary prompts.
- Each clean model is the base fine tuned on those responses alone, so it changes a little, as real fine tunes do.
- Each backdoored model is fine tuned on the same responses plus a share of prompts containing a trigger: random vocabulary words that never appear in the training prompts, answered with a fixed, harmless target sentence.
- Models are saved under shuffled names.
zoo.jsonlists them without their kind;answers.jsonholds kinds and triggers and should be kept away from whoever runs the scan.
modeldiffr zoo eval scans every model against the base and reports:
| Field | Meaning |
|---|---|
detection_rate |
Backdoored models flagged, with a Wilson 95% interval |
false_positive_rate |
Clean models flagged, with a Wilson 95% interval |
sweep_auc, search_auc |
Area under the ROC curve of each score, independent of thresholds |
trigger_recovery |
Mean share of each planted trigger's words found by the search |
The test suite runs a four model zoo of tiny models on every commit and requires both backdoored models flagged, no clean model flagged, and a sweep AUC of 1. That checks the machinery, not real world accuracy.
What will be published¶
The roadmap's exit criterion is a zoo of at least 20 backdoored and 20 clean models built from public small models, with the rates and AUCs above, whatever they are. Until then, Modeldiffr makes no claim that it detects backdoors in real models.
References¶
- Hubinger, E. et al. Sleeper Agents: Training Deceptive LLMs that Persist Through Safety Training. 2024.
- Zou, A. et al. Universal and Transferable Adversarial Attacks on Aligned Language Models. 2023.
- Rando, J. and Tramèr, F. Universal Jailbreak Backdoors from Poisoned Human Feedback. 2024.
- Wilson, E. B. Probable Inference, the Law of Succession, and Statistical Inference. JASA, 1927.