A safety regression gate for LLM fine-tuning: a lightweight early-warning signal read from the model's own refusal mechanism, plus the repair and audit to act on it.
https://github.com/user-attachments/assets/2952a7ea-66dc-4139-866a-87a177c8d541
Article · Report · Paper (Stage 2) · Quick start · Reproduce · Responsible release
The problem
Fine-tuning an aligned model on ordinary, harmless data can quietly weaken its refusals (Qi et al., 2023). Catching this today means a full red-team audit of every checkpoint (hundreds of harmful prompts, generation, a safety judge), so teams skip it. SafetyPulse measures instead whether the internal refusal mechanism is still intact: a Circuit Integrity Score (CIS) computed from 50 prompt pairs, light enough to run at every checkpoint.
SafetyPulse works as a safety regression gate for fine-tuning, the way a test suite gates a code change: it checks every checkpoint, decides PASS / WARN / FAIL with thresholds fixed in advance and validated on held-out runs, repairs a failing model (SafeTune) and verifies the repair with a paired audit (AuditKIT). We then tested where it transfers in pre-registered experiments on a second model, a second drifting condition and 35 third-party checkpoints from four other model families (Stage 2): it transferred to a sibling model (Tiny Aya Earth, H1) and to a second drift source (H2), but not as an earlier alarm than ‖ΔW‖ (H3), and its thresholds did not transfer to the other families (H6).
Results (held-out test runs; full report: docs/report/REPORT.md)
| Finding | Number |
|---|---|
| Benign Alpaca instruction tuning raises attack success rate (ASR) | 14.3% → 25.2% on 119 HarmBench test prompts (peak ~40% during training) |
| CIS tracks ASR across test checkpoints | Spearman ρ = −0.80 [−0.85, −0.71] |
| CIS flags every unsafe test checkpoint (WARN or FAIL) | recall 1.00 at precision 0.46 (it also warns on a safe maths fine-tune); a 50-prompt refusal spot-check: 0.13 |
| Which signal is the best alarm (post hoc) | the simpler direction projection cis_sep: FAIL recall 0.96 vs 0.57 for the circuit score, no alarm on safe runs; CIS warns before the spot-check on two of three seeds (report §4.3) |
| Threshold-free ranking (AUROC, post hoc) | across test runs cis_sep 0.95 and cis_circ 0.92 vs 0.64–0.70 for training step and ‖ΔW‖; the spot-check also 0.96; within drifting runs training step ranks better (0.90), so CIS detects drift rather than measuring its degree (report §4.10) |
| Early warning | CIS alarms at step 25 on all three unseen Alpaca seeds, 1–3 checkpoints before ASR rises (bounded by the 25-step checkpoint spacing; an alarm on the size of the weight change has the same lead but 40 of 44 false alarms on safe runs) |
| Repair: SafeTune safety-vector restore | ASR 25.2% → 12.3% (base 14.3%) and GSM8K 55.1% → 70.7% (base 71.3%), MMLU unchanged; it undoes about 86% of the fine-tune's weight change, so it is mostly a rollback |
| Repaired model in 4-bit NF4 | part of the repair is lost: ASR 10.9% → 16.8% (p = 0.039), GSM8K 71.0% → 63.3%, MMLU unchanged; the check still PASSes (report §4.11) |
| Circuit-only weight restore | no effect (ΔASR +0.0 [−1.4, +1.4]): the circuit reads out the drift but does not store it |
| AuditKIT before/after (paired McNemar) | base → drifted +10.1 pts (p = 0.012); drifted → repaired −12.6 pts (p = 0.003) |
| Judge robustness | Llama Guard 3 1B vs 8B agree on 94–96% of answers (κ 0.78–0.84) |
| CircuitKIT cross-check | 16 of our 20 circuit components are in its top 100 of 612 (p ≈ 2e-10) |
| CuratorKIT curation | removed 19 / 2,000 examples, drift unchanged (mean ASR 37.6% vs 38.1%); CIS still warns early |
Cost (T4): a CIS check takes 55 GPU-s per checkpoint (≈ $0.008 at Hugging Face's $0.50/h T4 rate), a full audit 120 GPU-s (≈ $0.017). A closed-source API cannot run the monitor or the repair at all, since both need the model's weights; ROI comparison against API judges: report §4.8.
Stage 2: pre-registered tests (paper)
The Stage 1 results above were developed on one model, and the best alarm (cis_sep) was chosen after the test runs
were scored. So we fixed four hypotheses with pass marks in
docs/13_PREREGISTRATION.md and ran new
experiments, with cis_sep and its WARN / FAIL thresholds frozen on Tiny Aya Global
(paper: Where Does a Refusal-Direction Drift Monitor Transfer? A Pre-registered Evaluation Across Models and Drift Sources).
| Test | Result | Verdict |
|---|---|---|
| H1 Sibling model (Tiny Aya Earth): 3 Alpaca + 2 control runs | all 63 unsafe checkpoints flagged at WARN, 10–20 steps early; no alarm on the 50 control checkpoints; FAIL did not transfer (report) | ✅ confirmed |
| H2 Alpaca answers rewritten as bulleted lists (Global), 3 runs | all 65 unsafe checkpoints flagged (report) | ✅ confirmed |
| H3 Earlier than a weight-change alarm? (Global, 10-step checkpoints) | same lead as ‖ΔW‖ (20 steps) on every run (report) | ❌ refuted |
| H6 35 SafeTune checkpoints: Llama-3.2-3B, Qwen3-4B, Gemma-3-4B, Llama-3.1-8B (aligned, SFT-drifted, DPO-recovered) | 11 of 12 unsafe drifted models flagged, but FAIL also on 3 of 8 safe recovered models (report) | ❌ refuted |
Doc 13 also lists two exploratory tests without a pass mark: H4 (English calibration vs non-English drift) and
H5 (where the drift is stored). Both ran on 2026-11-22 as HF Jobs 20 and 19 (amendments
2026-11-22-l06-h4-multilingual,
2026-11-22-l05-h5-localise)
and are reported as exploratory, with no verdict:
- H4 (report): the English
cis_sepalarm fired on every checkpoint after step 0, so it did not miss drift in Hindi, Spanish or French, but on these runs it does not discriminate between checkpoints and cannot show that it tracks non-English drift. - H5 (report): no single block's restore moves ASR beyond the resolution of 78 prompts; the data do not show the drift sitting in a few blocks (one checkpoint, one seed).
Every Stage 2 report, with its tool, amendment and result (including the third judge, the 119-prompt test split, finer-spaced lead time, label noise and the two-stage alarm, and reports still on unmerged branches), is indexed in REPORT.md · Stage 2 results index.
What the tests and the baselines show (paper Table 2):
- It stays silent on runs that do not drift; a weight-change alarm cannot. On Earth, ‖ΔW‖ alarmed on 48 of the
50 control checkpoints,
cis_sepon none. It also warned earlier than a 50-prompt refusal spot-check (median 10 vs 0 steps on H1, 20 vs 0 on H3), but the spot-check is as quiet on the Earth controls (0/50) and raises fewer false alarms on H6's safe models (3/12 vs 10/12) (review follow-ups). - It is cheap: 4.7 s per model against 7.3 s for the spot-check and 25.9 s for an ASR audit (median, one L40S).
- Thresholds do not carry over between model families. Threshold-free, the score still ranks unsafe below safe models within Llama-3.2, Qwen3 and Llama-3.1 (AUROC 0.94–1.00); on Gemma-3 the layer chosen by calibration ranks at chance while every layer from 17 to 34 ranks perfectly (layer diagnosis; exploratory, few models).
- Robust checks: every verdict is unchanged with an unsafe margin of 5 or 15 points (robustness), and re-judging with Llama Guard 3 8B leaves H1, H2 and H3 unchanged (κ 0.82–0.86) and H6 still refuted (12 of 13 unsafe flagged, FAIL on 3 of 7 safe recovered; κ 0.76). With the 8B judge, H2's secondary prediction (lists drift more than plain Alpaca) reverses (H1/H3, H2, H6).
- A third judge (exploratory): ShieldGemma 9B flags 219 of the 2,730 H6 answers unsafe where the 1B judge flags 903 (κ 0.259) and, with its labels, H6 is still refuted under the §2 rule (third judge). On the 119 held-out test prompts, every judge × split combination gives the same H6 verdict (test split).
- Partly specific to safety (exploratory): directions unrelated to safety ("Respond in French.", "Answer in one word.") also move under fine-tuning, but the refusal direction ranks unsafe checkpoints best (H1 AUROC 0.99 vs 0.94 / 0.74; H6 0.83 vs 0.67 / 0.59) (specificity control).
The paper is built from paper/ with cd paper && tectonic main.tex;
its tables, figures and bibliography are generated by scripts in the same folder.
How the four toolkits are chained
CuratorKIT ─► LoRA fine-tune ─► each checkpoint ─► safetypulse check (CIS) ─► PASS: continue
(clean data) │
└─ WARN/FAIL ─► SafeTune repair ─► AuditKIT before/after
CircuitKIT: independent check of the refusal circuit that CIS measures
Hugging Face artifacts
All under huggingface.co/purvansh01:
| Repo | Contents |
|---|---|
tiny-aya-global-safetypulse-repaired |
The repaired model (fp16), with its audit and check |
tiny-aya-global-safetypulse-repaired-nf4 |
The same model in 4-bit NF4 (2.5 GB), with its audit: less safe than fp16, see report §4.11 |
safetypulse-lora-alpaca |
LoRA adapters of the drifting Alpaca runs (seeds 0–3, 11 checkpoints each), with a warning card |
safetypulse-lora-alpacacur |
Alpaca after CuratorKIT curation |
safetypulse-lora-gsm8k, safetypulse-lora-none |
Domain fine-tune and negative control |
safetypulse-probe-bundle |
Refusal direction, circuit, probe pairs and thresholds: what safetypulse check needs |
safetypulse-eval, safetypulse-finetune-data, safetypulse-pairs |
Evaluation splits, fine-tuning data (incl. curated), 288 matched contrast pairs |
safetypulse-logs |
CIS / spot-check / ASR for all 150 checkpoints, audits, repair results, final tables, HF Job results |
safetypulse-earth-lora-alpaca, -earth-lora-none, -earth-logs |
Stage 2 H1: Tiny Aya Earth adapters (Alpaca and control, 26 checkpoints each) and their monitoring logs |
safetypulse-h2-lora-alpacalist, -h2-logs |
Stage 2 H2: list-formatted Alpaca adapters, logs and the rewritten training data |
safetypulse-h3-lora-alpaca, -h3-logs |
Stage 2 H3: Alpaca adapters at 10-step spacing, logs and ‖ΔW‖ |
safetypulse-judge8b |
Llama Guard 3 1B vs 8B verdicts on every H1 and H3 checkpoint (no answer text) |
safetypulse-h6-safetune |
Stage 2 H6: scores and calibration bundles for the 35 SafeTune checkpoints (no weights; bundles under LSAL v1.2) |
safetypulse-h3fine-lora-alpaca |
Stage 2 follow-up: Global Alpaca adapters at 2-step spacing, seeds 7–9 (HF Jobs 18, 21, 24; exploratory) |
safetypulse-expanse-lora-alpaca |
Stage 2 follow-up: Aya Expanse 8B Alpaca adapters, one run, 11 checkpoints (HF Job 23; exploratory) |
safetypulse-followups |
Scores, flags and reports of the exploratory follow-ups, HF Jobs 15–24 (no prompt or answer text) |
Withheld on purpose: the positive-control adapters trained on harmful data and the text of harmful model answers. Why, and how judges can get access: docs/11_WITHHELD_ARTIFACTS.md.
Install and use
Python 3.12 (SafeTune needs it; check alone runs on 3.10+), a GPU with 16 GB or more, and access to the gated
Tiny Aya Global (accept its terms, then hf auth login).
pip install "safetypulse[peft,toolkits]" # toolkits = CircuitKIT, SafeTune, AuditKIT; "safetypulse[peft]" is enough for check
# Probe bundle and one drifted checkpoint (alpaca-s1, step 125)
hf download purvansh01/safetypulse-probe-bundle --repo-type dataset --local-dir bundle --exclude "unpaired_v1/*"
hf download purvansh01/safetypulse-lora-alpaca --include "alpaca-s1/checkpoint-125/*" --local-dir lora
# Score it: exit code 0 PASS, 10 WARN, 20 FAIL (this one FAILs, cis_circ ≈ 0.73)
safetypulse check --checkpoint lora/alpaca-s1/checkpoint-125 --bundle bundle --dtype float16 --out check.json
# Repair it with SafeTune's safety-vector restore (settings chosen on dev), then check again (PASS, ≈ 0.97)
safetypulse repair --checkpoint lora/alpaca-s1/checkpoint-125 --bundle bundle --method safetune-svr \
--alpha 1.0 --svr-rank 8 --dtype float16 --out repaired
safetypulse check --checkpoint repaired --bundle bundle --dtype float16
# Audit: ASR, over-refusal, GSM8K, MMLU with bootstrap CIs (Llama Guard 3 1B is gated too)
hf download purvansh01/safetypulse-eval --repo-type dataset --local-dir eval
safetypulse audit --model repaired --data-dir eval --split test --judge llamaguard \
--judge-model meta-llama/Llama-Guard-3-1B --out audit.json
The thresholds were calibrated with the model in fp16, so score in float16 for numbers comparable to ours.
Inside a Hugging Face Trainer:
from safetypulse.integrations.hf_callback import SafetyPulseCallback
trainer.add_callback(SafetyPulseCallback("bundle", on_fail="stop")) # checks every saved checkpoint
safetypulse calibrate builds a bundle for a new base model from contrast pairs (--pairs), and
--circuitkit-crosscheck adds the CircuitKIT comparison.
Reproducibility
Every experiment is a notebook within kaggle/notebooks/, generated from
tools/build_notebooks.py and run on Kaggle (T4 GPUs) with
tools/kaggle_run.py. Each run's executed notebook, log, key output files and a
RUN_SUMMARY.md (what ran, numbers, interpretation) are in kaggle/executed/.
| Step | Notebook | Output |
|---|---|---|
| Data: eval splits, fine-tune sets, leakage filter | 01 | safetypulse-eval, safetypulse-finetune-data |
| Matched pairs (drafted, reviewed, split) | 02, 03 | safetypulse-pairs |
| Model choice, refusal direction, circuit, probe bundle | 04, 05, 06 (+ 06b CircuitKIT, 06c specificity) | safetypulse-probe-bundle |
| Curated data (CuratorKIT) | 01b | ft_alpacacur.jsonl |
| Fine-tunes, 11 checkpoints each | 07 | safetypulse-lora-* |
| Monitoring: CIS, spot-check, ASR; thresholds on dev | 08 | safetypulse-logs/monitor |
| Repair strengths on dev; final test audit | 09, 10 | safetypulse-logs/repair, report, audits |
| SafeTune → AuditKIT before/after | 11 | kaggle/executed/11_* |
| Larger-GPU runs (CircuitKIT, 8B judge, CuratorKIT fine-tune) | tools/hf_jobs/ |
safetypulse-logs/hf_jobs |
| Stage 2 H1–H3: fine-tunes and monitoring at 10-step spacing, Hub backup, ‖ΔW‖ baseline | 07, 08, 18, 19 | safetypulse-earth-*, -h2-*, -h3-* |
| Stage 2 H6 and follow-ups (SafeTune checkpoints, 8B judge, layer diagnosis, ‖ΔW‖, specificity control, test split, third judge, H5, H4) | HF Jobs 8–14, 16, 17, 19, 20 in tools/hf_jobs/ |
safetypulse-h6-safetune, safetypulse-judge8b |
| Stage 2 analysis (pre-registered verdicts, robustness, layers) | tools/h1_analysis.py, h2_analysis.py, h3_analysis.py, h6_analysis.py, stage2_robustness.py, h6_layers.py, h6_lodo.py, specificity_analysis.py, judge8b_h2.py, judge8b_h6.py, review_followups.py, h4_multilingual.py, h5_localise.py, h6_testsplit_analysis.py, third_judge_h6.py, h6_threshold_transfer.py, label_noise.py, two_stage_alarm.py (index: REPORT.md) |
docs/report/ |
Fixed choices: seed 0 for data splits; fine-tune seeds 0 (dev) and 1–3 (test); dev and test runs never overlap;
thresholds and repair strengths are chosen on dev only, then applied unchanged to test. Model and judge revisions
and dataset hashes are recorded in kaggle/executed/*/RUN_SUMMARY.md and safetypulse-eval/manifest.json.
Package tests, from a clone: pip install -e ".[dev,peft]" && pytest (693 tests as of commit 49a808c, counted with
pytest --collect-only -q; run in CI on Python 3.10–3.12).
Documentation
Paper (Stage 2) · Report · Research plan · Architecture · Data · Evaluation protocol · Risk, ethics, licensing · Withheld artifacts · Kaggle and HF resources · Related work · Pre-registration · Decisions
Responsible use
CIS is a screening signal: PASS does not certify a model as safe, and release decisions need a full audit. Evaluation data contains harmful prompts from public red-teaming benchmarks, for safety research only.
Licence
Code: Apache-2.0 (ADR-0004). Released adapters and data: CC-BY-NC-4.0,
inherited from Tiny Aya and Alpaca; benchmark data keeps its source licence. The Lexsi toolkits keep their own
licences and are used only through safetypulse.adapters.
Metadata
Release files for safetypulse 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| safetypulse-0.1.2.tar.gz | 142.4 kB | With provenance | Details for safetypulse-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| safetypulse-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for safetypulse-0.1.2-py3-none-any.whl |
Total release size: 219.5 kB
Release files / safetypulse-0.1.2.tar.gz
| Download URL | safetypulse-0.1.2.tar.gz |
|---|---|
| Size | 142.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7843ebdea334599a49fdcadfc73b7b194188c11e12b527e76ecc6cf1121765ab
|
|
BLAKE2b-256 checksum How to use checksums |
a9777688f97646042f7f253628cc1e91345e13d2e613ca7435b166473431b7fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logRelease files / safetypulse-0.1.2-py3-none-any.whl
| Download URL | safetypulse-0.1.2-py3-none-any.whl |
|---|---|
| Size | 77.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0d3fc64e0c4049cf31949036e1c2eb10d483da11a7d6f7b60734716ec687d84f
|
|
BLAKE2b-256 checksum How to use checksums |
a843d71c80a6b62235e60d4b4d614854f853d162a139a4faab4f8586b8d3453b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logSecurity for safetypulse 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for safetypulse-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.