Text Classification
Transformers
ONNX
Safetensors
modernbert
prompt-injection
jailbreak-detection
llm-security
ai-agents
guardrails
onnxruntime
mcp
text-embeddings-inference
Instructions to use usezn/Galvanize-2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use usezn/Galvanize-2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="usezn/Galvanize-2")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("usezn/Galvanize-2") model = AutoModelForSequenceClassification.from_pretrained("usezn/Galvanize-2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Add public benchmark script and results
Browse filesFiles changed (7)
- benchmark/README.mdAdded+127
- benchmark/decontam_excluded_ids.jsonAdded+115
- benchmark/horizon_published_metrics.jsonAdded+501
- benchmark/requirements.txtAdded+15
- benchmark/results.jsonAdded
- benchmark/results.mdAdded+154
- benchmark/run_benchmark.pyAdded+686
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127# Galvanize 2 public benchmark
This folder reproduces the public benchmark numbers of `usezn/Galvanize-2` against open prompt-injection detectors on[`Horizon-Labs/prompt-injection-eval-suite`](https://huggingface.co/datasets/Horizon-Labs/prompt-injection-eval-suite).
Numbers on our private held-out sets are reported in the model card and cannot be reproduced from this folder.
## Files
| File | What it is ||---|---|| `run_benchmark.py` | Standalone script: downloads the suite and the models from Hugging Face, scores, writes `results.json` and `results.md`. || `results.md`, `results.json` | Our published numbers from the full reference run (both protocols, every model). || `decontam_excluded_ids.json` | Eval-suite rows removed for the decontaminated subset (set name + 0-based row index). || `horizon_published_metrics.json` | Horizon's own published per-set numbers, used only for the reproduction check of Horizon's protocol. || `requirements.txt` | Package versions. |
## What is measured
- **Data.** `Horizon-Labs/prompt-injection-eval-suite` at revision `27c7bcd6f46e842f4c4d8b114b30eb6b1d892965`; the script checks the SHA-256 of every parquet file and the row and label counts. Thirteen sets are used: the ten external sets of Horizon's model-card table (NotInject, XSTest, OR-Bench-hard-1k, deepset test, jackhhao test, Simsonsun jailbreaks, agentic boundary pairs test, BIPIA, PIArena, LLMail-Inject phase 2) plus three supplementary public test splits (neuralchemy core, S-Labs, agentic-prompt-injection-5k). Labels are used as published: 1 = injection or jailbreak, 0 = benign. Under this suite's definition a plainly harmful request without an injection is benign. Horizon's `synthetic_*` sets are not used: they come from the same generator as Horizon's training data, so they are in-distribution for Horizon and, because Galvanize 2 is fine-tuned from Horizon small, for Galvanize 2 too.- **Models** (revision and SHA-256 of `model.safetensors` pinned in the script and checked after download): Galvanize 2 (`usezn/Galvanize-2`), Horizon small, base and large (`Horizon-Labs/prompt-injection-guard-*`), Galvanize-60M (`usezn/Galvanize-60M`), ProtectAI v2 (`protectai/deberta-v3-base-prompt-injection-v2`), deepset (`deepset/deberta-v3-base-injection`), Wolf Defender (`patronus-studio/wolf-defender-prompt-injection`) and NeuralTrust small (`NeuralTrust/prompt-guard-oss-small`).- **Score.** Every model is reduced to a margin `z` with `P(injection) = sigmoid(z)`. For the two-class heads, `z = logit(positive) - logit(negative)`, where the positive class is the label matching `inject|jailbreak|malicious|unsafe|attack` (the script also checks it is the label used in the reference run). Galvanize-60M has a single-logit head and is scored with its published calibration, `z = 0.7 * (raw_logit + 17.6063)`, using the FP32 weights and the loader from its model card.- **Serving protocol (primary).** The text is whitespace-flattened exactly as Galvanize 2 is served, `re.sub(r"\s+", " ", text).strip()`, tokenised with each model's own tokenizer, and only the **first 512 tokens** are scored, in one window. fp32, TF32 off.- **Horizon's protocol (secondary, `--protocol hz` or `both`).** Horizon's `evaluate.py` windowing: raw text, windows of `min(2048, max positions)` tokens (512 for the DeBERTa models and Galvanize-60M), stride of a quarter window, document score = max over windows. Run in fp32.- **Thresholds.** Galvanize 2 at **0.662** (its development-set threshold; exact value 0.661988) and also at **0.5**; Galvanize-60M at 0.95 (its published calibrated threshold); every other model at 0.5, its default.- **Metrics.** As in Horizon's card: accuracy for the all-benign sets, recall for the all-attack sets, F1 (shown with the false-positive rate) otherwise. ROC AUC and normalised partial AUC up to 10% FPR are reported as threshold-free metrics. The macro average is the mean over the ten card sets.- **Decontaminated subset (primary).** Rows whose text matches a row of the Galvanize 2 training data are removed (see below). The full sets are reported as a secondary view.
## Decontamination
The reference run hashed every eval row and every Galvanize 2 training row with three keys: SHA-256 of the exact text,SHA-256 of the whitespace-flattened lowercased text, and SHA-256 of the first 200 characters of that normalised text(texts of 200 characters or more). An eval row is excluded if any key matches. The training data is private, so thismatch cannot be recomputed here. `decontam_excluded_ids.json` records its outcome as **row ids**: for each set, the0-based row positions in `data/<set>.parquet` at the pinned revision (the suite has no id column; the pinned SHA-256 keepsthe positions stable). It contains no text and no hashes.
275 rows are excluded in total: jackhhao test 126 (of 262), Simsonsun jailbreaks 131 (of 2,426), XSTest 9, OR-Bench-hard-1k7, neuralchemy core test 2; no rows in the other eight sets. Per-set counts are in the file and in `results.md`.
`results.md` also lists, for information only, the overlap with the public *train* splits of the sources Horizon listsas training data (Horizon's own training set is not published). That overlap is not used to filter rows.
## Why our numbers for other models differ from their own model cards
- **Different subset.** The primary numbers drop the rows above; the cards use full sets (or different sets).- **Different input.** The serving protocol scores only the first 512 tokens of the flattened text. Horizon's card scores sliding windows of up to 2,048 tokens and keeps the maximum, which changes the long indirect sets (BIPIA, PIArena, LLMail-Inject) the most. Both protocols are in `results.md`.- **Different thresholds.** Every third-party model is scored at 0.5; a vendor's recommended operating point may differ.- **Different precision.** We run fp32; Horizon's published numbers use bf16 autocast. Our run of Horizon's protocol matches Horizon's published numbers within 0.009 accuracy and 0.002 ROC AUC per set (reproduction check in `results.md`).- **Different macro average.** Our macro covers ten sets. Horizon's card also averages Qualifire and two Mindgard sets, which are gated and non-commercial and are not in the public suite.- **Different label definition.** This suite labels plain harmful requests as benign. Detectors that also target jailbreaks or harmful content can score lower on XSTest and OR-Bench by design.- **Galvanize-60M** is served as an INT8 ONNX graph; here it is scored with its FP32 weights. In the reference run the two agreed on 29 of 32 decisions in a spot check, so small differences from its own card are expected.
## How to run
```bashpython -m venv .venv && . .venv/bin/activatepip install -r requirements.txtpython run_benchmark.py --limit 24 --models galvanize-2,horizon-small # smoke test, a few minutespython run_benchmark.py # every model, serving protocolpython run_benchmark.py --protocol both # also Horizon's protocol```
Options: `--models` (comma-separated keys: `galvanize-2`, `horizon-small`, `horizon-base`, `horizon-large`,`galvanize-60m`, `protectai-v2`, `deepset`, `wolf-defender`, `neuraltrust-small`), `--device cpu|cuda` (default: CUDA ifavailable), `--limit N` (smoke test: up to N/2 attack and N/2 benign rows per set, fixed seed), `--protocolserve|hz|both`, `--out-dir` (default `run_output/`, so the published files are not overwritten),`--galvanize2-revision`.
The script writes `run_output/results.json` and `run_output/results.md` in the same format as the published files. On afull run it also compares every metric with the published `results.json` and reports the largest difference per model.It refuses to score a model whose `model.safetensors` differs from the benchmarked file, and it never prints benchmarktext. No Hugging Face token is needed: every model and the dataset are public and ungated.
### Hardware and expected runtime
- **GPU (recommended).** The reference run used one NVIDIA L4 (24 GB). Scoring all nine models took about 17 minutes for the serving protocol and about 26 minutes for Horizon's protocol, plus downloads. Expect roughly 25 to 30 minutes for the default run and 45 to 55 minutes for `--protocol both`. Any CUDA GPU with 16 GB or more should work.- **CPU.** Works, but slowly: the suite is about 15,400 rows and 2.7 million tokens per model. As a rough estimate, several hours for all models on a recent 16-core x86 machine (Horizon large is the largest share); 16 GB of RAM is enough. CPU and GPU fp32 kernels differ slightly, so a few borderline rows can flip; expect differences of about 0.001.- **Disk.** About 8 GB of model downloads, cached by `huggingface_hub`.
## What this folder does not reproduce
- The decontamination match itself (it needs our private training data); the excluded row ids are provided instead.- Numbers on our private held-out sets (see the line at the top).- Models not evaluated: `leolee99/PIGuard` (needs `trust_remote_code`), `meta-llama/Llama-Prompt-Guard-2-86M` and `-22M` (gated), and commercial APIs. The Qualifire and Mindgard datasets are gated and not in the public suite.
## License
`run_benchmark.py` and the other files in this folder are released under the Apache License 2.0. The eval suite is notredistributed here (only row ids); it is governed by its own licenses, which differ per subset: see the[dataset card](https://huggingface.co/datasets/Horizon-Labs/prompt-injection-eval-suite). Each model is under thelicense on its own model card.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115{ "dataset": "Horizon-Labs/prompt-injection-eval-suite", "revision": "27c7bcd6f46e842f4c4d8b114b30eb6b1d892965", "row_index": "0-based row position in data/<set>.parquet at this revision (the suite has no id column)", "criterion": "Rows whose text matched a row of the Galvanize 2 training data on any of three keys: SHA-256 of the exact text, SHA-256 of the whitespace-flattened lowercased text, or SHA-256 of the first 200 characters of that normalised text (texts of 200+ characters only). The training data is private, so the match cannot be recomputed; this file records its outcome.", "counts": { "notinject": { "rows": 339, "excluded": 0, "excluded_attacks": 0, "kept": 339, "kept_attacks": 0 }, "xstest": { "rows": 450, "excluded": 9, "excluded_attacks": 0, "kept": 441, "kept_attacks": 0 }, "orbench_hard": { "rows": 1319, "excluded": 7, "excluded_attacks": 0, "kept": 1312, "kept_attacks": 0 }, "jackhhao_test": { "rows": 262, "excluded": 126, "excluded_attacks": 101, "kept": 136, "kept_attacks": 38 }, "deepset_test": { "rows": 116, "excluded": 0, "excluded_attacks": 0, "kept": 116, "kept_attacks": 60 }, "simsonsun_jailbreaks": { "rows": 2426, "excluded": 131, "excluded_attacks": 131, "kept": 2295, "kept_attacks": 2295 }, "boundary_pairs_test": { "rows": 240, "excluded": 0, "excluded_attacks": 0, "kept": 240, "kept_attacks": 120 }, "bipia": { "rows": 3178, "excluded": 0, "excluded_attacks": 0, "kept": 3178, "kept_attacks": 3000 }, "piarena": { "rows": 1500, "excluded": 0, "excluded_attacks": 0, "kept": 1500, "kept_attacks": 750 }, "llmail_phase2": { "rows": 2000, "excluded": 0, "excluded_attacks": 0, "kept": 2000, "kept_attacks": 2000 }, "neuralchemy_test": { "rows": 942, "excluded": 2, "excluded_attacks": 2, "kept": 940, "kept_attacks": 550 }, "slabs_test": { "rows": 2101, "excluded": 0, "excluded_attacks": 0, "kept": 2101, "kept_attacks": 1051 }, "agentic5k_test": { "rows": 545, "excluded": 0, "excluded_attacks": 0, "kept": 545, "kept_attacks": 280 } }, "excluded": { "notinject": [], "xstest": [18, 51, 102, 109, 158, 255, 264, 379, 400], "orbench_hard": [48, 189, 358, 465, 1061, 1062, 1268], "jackhhao_test": [7, 9, 10, 11, 14, 15, 16, 17, 18, 20, 21, 24, 26, 30, 33, 35, 36, 37, 41, 44, 45, 46, 48, 50, 51, 52, 54, 56, 59, 61, 63, 64, 65, 66, 67, 71, 74, 76, 77, 78, 80, 84, 86, 88, 89, 91, 94, 95, 98, 99, 100, 102, 104, 108, 109, 110, 111, 112, 113, 114, 116, 118, 119, 120, 122, 124, 127, 128, 130, 131, 132, 136, 140, 141, 145, 148, 149, 151, 152, 153, 158, 160, 161, 162, 163, 166, 178, 183, 184, 186, 187, 188, 196, 197, 199, 200, 202, 206, 209, 210, 211, 213, 214, 215, 219, 220, 224, 228, 229, 230, 231, 238, 240, 242, 243, 245, 246, 248, 249, 250, 251, 253, 254, 255, 259, 261], "deepset_test": [], "simsonsun_jailbreaks": [44, 45, 48, 49, 51, 53, 58, 59, 60, 123, 126, 150, 223, 282, 328, 356, 384, 412, 419, 481, 488, 519, 614, 651, 663, 681, 687, 697, 700, 706, 800, 804, 815, 816, 827, 839, 847, 850, 855, 856, 860, 864, 874, 875, 878, 879, 882, 889, 898, 911, 916, 926, 933, 944, 946, 947, 949, 951, 952, 961, 972, 974, 976, 979, 983, 988, 990, 991, 994, 996, 1002, 1007, 1021, 1026, 1027, 1028, 1029, 1045, 1052, 1055, 1056, 1063, 1064, 1075, 1076, 1088, 1091, 1092, 1093, 1103, 1114, 1122, 1124, 1130, 1137, 1140, 1144, 1151, 1153, 1154, 1155, 1172, 1186, 1189, 1191, 1195, 1197, 1199, 1201, 1205, 1207, 1208, 1211, 1218, 1220, 1221, 1222, 1227, 1228, 1229, 1267, 1320, 1374, 1382, 1412, 1429, 1455, 1496, 1502, 1563, 1617], "boundary_pairs_test": [], "bipia": [], "piarena": [], "llmail_phase2": [], "neuralchemy_test": [342, 359], "slabs_test": [], "agentic5k_test": [] }, "total_excluded": 275}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501{ "source": "Horizon-Labs/prompt-injection-guard-base@e4fbfc6f603e24c675cdf310c3b8d7abaa825666 eval/eval_results.json + eval/baselines_eval_results.json", "note": "Horizon's own published per-set numbers (threshold 0.5, bf16 autocast), used only for the reproduction check of the Horizon protocol.", "models": { "horizon-base": { "notinject": { "n": 339, "pos": 0, "acc": 0.944 }, "xstest": { "n": 450, "pos": 0, "acc": 0.9978 }, "orbench_hard": { "n": 1319, "pos": 0, "acc": 0.9939 }, "deepset_test": { "n": 116, "pos": 60, "acc": 0.8017, "auc": 0.9543, "f1": 0.7629, "recall": 0.6167, "fpr": 0.0 }, "jackhhao_test": { "n": 262, "pos": 139, "acc": 0.9275, "auc": 0.9798, "f1": 0.9283, "recall": 0.8849, "fpr": 0.0244 }, "simsonsun_jailbreaks": { "n": 2426, "pos": 2426, "acc": 0.8215 }, "boundary_pairs_test": { "n": 240, "pos": 120, "acc": 0.9708, "auc": 0.9918, "f1": 0.9714, "recall": 0.9917, "fpr": 0.05 }, "bipia": { "n": 3178, "pos": 3000, "acc": 0.4874, "auc": 0.8362, "f1": 0.628, "recall": 0.4583, "fpr": 0.0225 }, "piarena": { "n": 1500, "pos": 750, "acc": 0.97, "auc": 0.9969, "f1": 0.9691, "recall": 0.94, "fpr": 0.0 }, "llmail_phase2": { "n": 2000, "pos": 2000, "acc": 0.9975 }, "neuralchemy_test": { "n": 942, "pos": 552, "acc": 0.9554, "auc": 0.9912, "f1": 0.9613, "recall": 0.9438, "fpr": 0.0282 }, "slabs_test": { "n": 2101, "pos": 1051, "acc": 0.9505, "auc": 0.995, "f1": 0.9481, "recall": 0.9039, "fpr": 0.0029 }, "agentic5k_test": { "n": 545, "pos": 280, "acc": 0.8459, "auc": 0.992, "f1": 0.8696, "recall": 1.0, "fpr": 0.317 } }, "protectai-v2": { "notinject": { "n": 339, "pos": 0, "acc": 0.5634 }, "xstest": { "n": 450, "pos": 0, "acc": 1.0 }, "orbench_hard": { "n": 1319, "pos": 0, "acc": 0.9348 }, "deepset_test": { "n": 116, "pos": 60, "acc": 0.6724, "auc": 0.9006, "f1": 0.5366, "recall": 0.3667, "fpr": 0.0 }, "jackhhao_test": { "n": 262, "pos": 139, "acc": 0.9122, "auc": 0.9802, "f1": 0.9112, "recall": 0.8489, "fpr": 0.0163 }, "simsonsun_jailbreaks": { "n": 2426, "pos": 2426, "acc": 0.5396 }, "boundary_pairs_test": { "n": 240, "pos": 120, "acc": 0.6333, "auc": 0.7202, "f1": 0.6966, "recall": 0.8417, "fpr": 0.575 }, "bipia": { "n": 3178, "pos": 3000, "acc": 0.2212, "auc": 0.4388, "f1": 0.3115, "recall": 0.1867, "fpr": 0.1966 }, "piarena": { "n": 1500, "pos": 750, "acc": 0.608, "auc": 0.732, "f1": 0.3664, "recall": 0.2267, "fpr": 0.0107 }, "llmail_phase2": { "n": 2000, "pos": 2000, "acc": 0.4855 }, "neuralchemy_test": { "n": 942, "pos": 552, "acc": 0.9087, "auc": 0.9761, "f1": 0.9173, "recall": 0.8641, "fpr": 0.0282 }, "slabs_test": { "n": 2101, "pos": 1051, "acc": 0.851, "auc": 0.9776, "f1": 0.8258, "recall": 0.706, "fpr": 0.0038 }, "agentic5k_test": { "n": 545, "pos": 280, "acc": 0.7266, "auc": 0.7582, "f1": 0.7739, "recall": 0.9107, "fpr": 0.4679 } }, "deepset": { "notinject": { "n": 339, "pos": 0, "acc": 0.2861 }, "xstest": { "n": 450, "pos": 0, "acc": 1.0 }, "orbench_hard": { "n": 1319, "pos": 0, "acc": 0.8029 }, "deepset_test": { "n": 116, "pos": 60, "acc": 0.9914, "auc": 0.997, "f1": 0.9916, "recall": 0.9833, "fpr": 0.0 }, "jackhhao_test": { "n": 262, "pos": 139, "acc": 0.5573, "auc": 0.8417, "f1": 0.7056, "recall": 1.0, "fpr": 0.9431 }, "simsonsun_jailbreaks": { "n": 2426, "pos": 2426, "acc": 0.9963 }, "boundary_pairs_test": { "n": 240, "pos": 120, "acc": 0.5, "auc": 0.4969, "f1": 0.6667, "recall": 1.0, "fpr": 1.0 }, "bipia": { "n": 3178, "pos": 3000, "acc": 0.944, "auc": 0.5735, "f1": 0.9712, "recall": 1.0, "fpr": 1.0 }, "piarena": { "n": 1500, "pos": 750, "acc": 0.5113, "auc": 0.8199, "f1": 0.6717, "recall": 1.0, "fpr": 0.9773 }, "llmail_phase2": { "n": 2000, "pos": 2000, "acc": 1.0 }, "neuralchemy_test": { "n": 942, "pos": 552, "acc": 0.8206, "auc": 0.9584, "f1": 0.8651, "recall": 0.9819, "fpr": 0.4077 }, "slabs_test": { "n": 2101, "pos": 1051, "acc": 0.8853, "auc": 0.9609, "f1": 0.8745, "recall": 0.7992, "fpr": 0.0286 }, "agentic5k_test": { "n": 545, "pos": 280, "acc": 0.5358, "auc": 0.9236, "f1": 0.6888, "recall": 1.0, "fpr": 0.9547 } }, "wolf-defender": { "notinject": { "n": 339, "pos": 0, "acc": 0.9204 }, "xstest": { "n": 450, "pos": 0, "acc": 0.9644 }, "orbench_hard": { "n": 1319, "pos": 0, "acc": 0.8544 }, "deepset_test": { "n": 116, "pos": 60, "acc": 0.7931, "auc": 0.9653, "f1": 0.75, "recall": 0.6, "fpr": 0.0 }, "jackhhao_test": { "n": 262, "pos": 139, "acc": 0.9427, "auc": 0.9768, "f1": 0.9455, "recall": 0.9353, "fpr": 0.0488 }, "simsonsun_jailbreaks": { "n": 2426, "pos": 2426, "acc": 0.8384 }, "boundary_pairs_test": { "n": 240, "pos": 120, "acc": 0.7792, "auc": 0.8786, "f1": 0.7905, "recall": 0.8333, "fpr": 0.275 }, "bipia": { "n": 3178, "pos": 3000, "acc": 0.2011, "auc": 0.6249, "f1": 0.2714, "recall": 0.1577, "fpr": 0.0674 }, "piarena": { "n": 1500, "pos": 750, "acc": 0.6013, "auc": 0.9089, "f1": 0.3385, "recall": 0.204, "fpr": 0.0013 }, "llmail_phase2": { "n": 2000, "pos": 2000, "acc": 0.9125 }, "neuralchemy_test": { "n": 942, "pos": 552, "acc": 0.9278, "auc": 0.9783, "f1": 0.9363, "recall": 0.9058, "fpr": 0.041 }, "slabs_test": { "n": 2101, "pos": 1051, "acc": 0.8948, "auc": 0.9931, "f1": 0.8828, "recall": 0.7916, "fpr": 0.0019 }, "agentic5k_test": { "n": 545, "pos": 280, "acc": 0.7908, "auc": 0.8543, "f1": 0.7935, "recall": 0.7821, "fpr": 0.2 } }, "neuraltrust-small": { "notinject": { "n": 339, "pos": 0, "acc": 0.944 }, "xstest": { "n": 450, "pos": 0, "acc": 0.72 }, "orbench_hard": { "n": 1319, "pos": 0, "acc": 0.4526 }, "deepset_test": { "n": 116, "pos": 60, "acc": 0.5862, "auc": 0.8432, "f1": 0.3333, "recall": 0.2, "fpr": 0.0 }, "jackhhao_test": { "n": 262, "pos": 139, "acc": 0.8511, "auc": 0.9614, "f1": 0.8434, "recall": 0.7554, "fpr": 0.0407 }, "simsonsun_jailbreaks": { "n": 2426, "pos": 2426, "acc": 0.7465 }, "boundary_pairs_test": { "n": 240, "pos": 120, "acc": 0.8417, "auc": 0.8873, "f1": 0.8348, "recall": 0.8, "fpr": 0.1167 }, "bipia": { "n": 3178, "pos": 3000, "acc": 0.0897, "auc": 0.5242, "f1": 0.0689, "recall": 0.0357, "fpr": 0.0 }, "piarena": { "n": 1500, "pos": 750, "acc": 0.5333, "auc": 0.6288, "f1": 0.125, "recall": 0.0667, "fpr": 0.0 }, "llmail_phase2": { "n": 2000, "pos": 2000, "acc": 0.1825 }, "neuralchemy_test": { "n": 942, "pos": 552, "acc": 0.8588, "auc": 0.9333, "f1": 0.8684, "recall": 0.7953, "fpr": 0.0513 }, "slabs_test": { "n": 2101, "pos": 1051, "acc": 0.7363, "auc": 0.9387, "f1": 0.648, "recall": 0.4853, "fpr": 0.0124 }, "agentic5k_test": { "n": 545, "pos": 280, "acc": 0.7541, "auc": 0.8206, "f1": 0.7491, "recall": 0.7143, "fpr": 0.2038 } } }}123456789101112131415# Python 3.10+ (the reference run used Python 3.13).# Versions used by the reference run. torch was the CUDA 13.0 build (2.11.0+cu130); pick the wheel that matches# your platform from https://pytorch.org/get-started/locally/ (any 2.11.0 build gives the same code path).torch==2.11.0transformers==5.18.0numpy==2.1.3pandas==2.2.3# Not recorded by the reference run: lower bounds only.scikit-learn>=1.5huggingface_hub>=1.0safetensors>=0.4.3pyarrow>=15# Needed by the DeBERTa-v3 tokenizers (ProtectAI v2, deepset).sentencepiece>=0.2protobuf>=4.25123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154# Galvanize 2 vs open prompt-injection detectors
Run 2026-10-12T05:29:16Z (UTC) on 1x NVIDIA L4 GPU, fp32, TF32 off. Data: [Horizon-Labs/prompt-injection-eval-suite](https://huggingface.co/datasets/Horizon-Labs/prompt-injection-eval-suite) @ `27c7bcd6f46e`. Primary numbers are on the **decontaminated** subset (rows listed in `decontam_excluded_ids.json` removed) under the **serving protocol** (whitespace flattened, first 512 tokens, one window). F1 cells show the false-positive rate on the benign rows in parentheses. Best value per row in bold.
**Serving protocol, decontaminated subset, each model at its own threshold**
| Eval set | n | Galvanize 2 @0.662 | Galvanize 2 @0.5 | Horizon small (141M) @0.5 | Horizon base (308M) @0.5 | Horizon large @0.5 | Galvanize-60M @0.95 | ProtectAI v2 @0.5 | deepset @0.5 | Wolf Defender @0.5 | NeuralTrust small @0.5 ||---|---:|---|---|---|---|---|---|---|---|---|---|| NotInject (benign, trigger words), accuracy | 339 | **0.982** | 0.956 | 0.962 | 0.944 | 0.932 | 0.537 | 0.566 | 0.286 | 0.923 | 0.944 || XSTest (benign for injection), accuracy | 441 | **1.000** | **1.000** | **1.000** | 0.998 | **1.000** | 0.270 | **1.000** | **1.000** | 0.964 | 0.717 || OR-Bench-hard-1k (benign), accuracy | 1312 | **0.999** | 0.995 | 0.995 | 0.993 | 0.994 | 0.203 | 0.934 | 0.803 | 0.856 | 0.452 || jackhhao/jailbreak-classification test, F1 | 136 | 0.904 (0.02) | **0.919 (0.02)** | 0.883 (0.05) | 0.907 (0.03) | 0.873 (0.02) | 0.868 (0.09) | 0.886 (0.01) | 0.452 (0.94) | 0.895 (0.04) | 0.845 (0.03) || deepset/prompt-injections test, F1 | 116 | 0.723 (0.00) | 0.812 (0.00) | 0.824 (0.00) | 0.788 (0.00) | 0.812 (0.00) | 0.921 (0.14) | 0.537 (0.00) | **0.992 (0.00)** | 0.750 (0.00) | 0.378 (0.00) || Simsonsun jailbreaks, recall | 2295 | 0.741 | 0.817 | 0.793 | 0.829 | 0.764 | 0.805 | 0.521 | **0.996** | 0.834 | 0.753 || Agentic boundary pairs test, F1 | 240 | 0.984 (0.03) | 0.980 (0.04) | 0.976 (0.05) | 0.971 (0.05) | **0.992 (0.00)** | 0.665 (0.76) | 0.697 (0.57) | 0.667 (1.00) | 0.787 (0.28) | 0.835 (0.12) || BIPIA (derived), F1 | 3178 | 0.601 (0.04) | 0.670 (0.06) | 0.647 (0.08) | 0.736 (0.03) | 0.645 (0.06) | 0.353 (0.13) | 0.283 (0.17) | **0.971 (1.00)** | 0.385 (0.10) | 0.067 (0.00) || PIArena (derived), F1 | 1500 | 0.817 (0.00) | 0.834 (0.00) | 0.833 (0.00) | **0.865 (0.00)** | 0.835 (0.01) | 0.095 (0.01) | 0.338 (0.01) | 0.672 (0.98) | 0.360 (0.00) | 0.137 (0.00) || LLMail-Inject phase 2, recall | 2000 | 0.944 | 0.954 | 0.955 | 0.987 | 0.992 | 0.498 | 0.456 | **1.000** | 0.898 | 0.218 || neuralchemy core test, F1 (suppl.) | 940 | 0.954 (0.03) | 0.959 (0.03) | **0.961 (0.03)** | 0.960 (0.03) | 0.956 (0.03) | 0.957 (0.11) | 0.917 (0.03) | 0.865 (0.41) | 0.937 (0.04) | 0.870 (0.05) || S-Labs test, F1 (suppl.) | 2101 | 0.919 (0.00) | 0.944 (0.00) | 0.945 (0.00) | **0.949 (0.00)** | 0.931 (0.01) | 0.794 (0.24) | 0.827 (0.00) | 0.877 (0.03) | 0.883 (0.00) | 0.645 (0.01) || agentic-prompt-injection-5k test, F1 (suppl.) | 545 | 0.867 (0.32) | 0.851 (0.37) | 0.850 (0.37) | 0.868 (0.32) | **0.897 (0.24)** | 0.727 (0.66) | 0.774 (0.47) | 0.689 (0.95) | 0.800 (0.20) | 0.743 (0.21) || Macro average, 10 card sets | | 0.870 | 0.894 | 0.887 | 0.902 | 0.884 | 0.521 | 0.622 | 0.784 | 0.765 | 0.535 |
**Threshold-free: ROC AUC (serving protocol, decontaminated)**
| Eval set | n | Galvanize 2 | Horizon small (141M) | Horizon base (308M) | Horizon large | Galvanize-60M | ProtectAI v2 | deepset | Wolf Defender | NeuralTrust small ||---|---:|---|---|---|---|---|---|---|---|---|| jackhhao_test | 136 | 0.982 | 0.970 | 0.974 | 0.966 | 0.964 | **0.990** | 0.747 | 0.961 | 0.974 || deepset_test | 116 | 0.978 | 0.977 | 0.955 | 0.950 | 0.967 | 0.901 | **0.997** | 0.969 | 0.842 || boundary_pairs_test | 240 | 0.993 | 0.994 | 0.992 | **1.000** | 0.703 | 0.724 | 0.503 | 0.877 | 0.885 || bipia | 3178 | 0.831 | 0.790 | **0.864** | 0.825 | 0.577 | 0.422 | 0.577 | 0.712 | 0.541 || piarena | 1500 | 0.930 | 0.922 | **0.936** | 0.929 | 0.595 | 0.722 | 0.836 | 0.860 | 0.610 || neuralchemy_test | 940 | **0.992** | 0.991 | 0.991 | 0.989 | 0.980 | 0.976 | 0.958 | 0.978 | 0.934 || slabs_test | 2101 | 0.997 | **0.998** | 0.995 | 0.994 | 0.876 | 0.978 | 0.961 | 0.993 | 0.939 || agentic5k_test | 545 | 0.994 | 0.992 | 0.992 | **0.999** | 0.708 | 0.758 | 0.923 | 0.854 | 0.822 |
**Threshold-free: normalised partial AUC up to 10% FPR (serving protocol, decontaminated)**
| Eval set | n | Galvanize 2 | Horizon small (141M) | Horizon base (308M) | Horizon large | Galvanize-60M | ProtectAI v2 | deepset | Wolf Defender | NeuralTrust small ||---|---:|---|---|---|---|---|---|---|---|---|| jackhhao_test | 136 | 0.910 | 0.835 | 0.879 | 0.843 | 0.902 | **0.920** | 0.027 | 0.814 | 0.814 || deepset_test | 116 | 0.902 | 0.893 | 0.848 | 0.867 | 0.736 | 0.715 | **0.983** | 0.787 | 0.461 || boundary_pairs_test | 240 | 0.930 | 0.937 | 0.921 | **1.000** | 0.204 | 0.296 | 0.040 | 0.563 | 0.512 || bipia | 3178 | 0.442 | 0.395 | **0.624** | 0.431 | 0.073 | 0.043 | 0.161 | 0.175 | 0.122 || piarena | 1500 | 0.790 | 0.786 | **0.804** | 0.781 | 0.115 | 0.288 | 0.331 | 0.574 | 0.245 || neuralchemy_test | 940 | **0.949** | 0.948 | 0.947 | 0.920 | 0.821 | 0.891 | 0.755 | 0.878 | 0.674 || slabs_test | 2101 | 0.975 | **0.979** | 0.964 | 0.947 | 0.513 | 0.893 | 0.816 | 0.955 | 0.669 || agentic5k_test | 545 | 0.970 | 0.964 | 0.946 | **0.995** | 0.067 | 0.063 | 0.521 | 0.534 | 0.617 |
**Serving protocol, full sets (secondary; includes the excluded rows)**
| Eval set | n | Galvanize 2 @0.662 | Galvanize 2 @0.5 | Horizon small (141M) @0.5 | Horizon base (308M) @0.5 | Horizon large @0.5 | Galvanize-60M @0.95 | ProtectAI v2 @0.5 | deepset @0.5 | Wolf Defender @0.5 | NeuralTrust small @0.5 ||---|---:|---|---|---|---|---|---|---|---|---|---|| NotInject (benign, trigger words), accuracy | 339 | **0.982** | 0.956 | 0.962 | 0.944 | 0.932 | 0.537 | 0.566 | 0.286 | 0.923 | 0.944 || XSTest (benign for injection), accuracy | 450 | **1.000** | **1.000** | **1.000** | 0.998 | **1.000** | 0.276 | **1.000** | **1.000** | 0.964 | 0.720 || OR-Bench-hard-1k (benign), accuracy | 1319 | **0.999** | 0.996 | 0.995 | 0.993 | 0.993 | 0.202 | 0.935 | 0.803 | 0.857 | 0.452 || jackhhao/jailbreak-classification test, F1 | 262 | 0.920 (0.02) | 0.929 (0.03) | 0.906 (0.06) | 0.925 (0.04) | 0.878 (0.03) | **0.947 (0.08)** | 0.907 (0.02) | 0.706 (0.94) | 0.942 (0.06) | 0.839 (0.04) || deepset/prompt-injections test, F1 | 116 | 0.723 (0.00) | 0.812 (0.00) | 0.824 (0.00) | 0.788 (0.00) | 0.812 (0.00) | 0.921 (0.14) | 0.537 (0.00) | **0.992 (0.00)** | 0.750 (0.00) | 0.378 (0.00) || Simsonsun jailbreaks, recall | 2426 | 0.748 | 0.823 | 0.796 | 0.833 | 0.767 | 0.813 | 0.538 | **0.996** | 0.841 | 0.755 || Agentic boundary pairs test, F1 | 240 | 0.984 (0.03) | 0.980 (0.04) | 0.976 (0.05) | 0.971 (0.05) | **0.992 (0.00)** | 0.665 (0.76) | 0.697 (0.57) | 0.667 (1.00) | 0.787 (0.28) | 0.835 (0.12) || BIPIA (derived), F1 | 3178 | 0.601 (0.04) | 0.670 (0.06) | 0.647 (0.08) | 0.736 (0.03) | 0.645 (0.06) | 0.353 (0.13) | 0.283 (0.17) | **0.971 (1.00)** | 0.385 (0.10) | 0.067 (0.00) || PIArena (derived), F1 | 1500 | 0.817 (0.00) | 0.834 (0.00) | 0.833 (0.00) | **0.865 (0.00)** | 0.835 (0.01) | 0.095 (0.01) | 0.338 (0.01) | 0.672 (0.98) | 0.360 (0.00) | 0.137 (0.00) || LLMail-Inject phase 2, recall | 2000 | 0.944 | 0.954 | 0.955 | 0.987 | 0.992 | 0.498 | 0.456 | **1.000** | 0.898 | 0.218 || neuralchemy core test, F1 (suppl.) | 942 | 0.955 (0.03) | 0.959 (0.03) | **0.961 (0.03)** | 0.960 (0.03) | 0.957 (0.03) | 0.957 (0.11) | 0.917 (0.03) | 0.865 (0.41) | 0.937 (0.04) | 0.871 (0.05) || S-Labs test, F1 (suppl.) | 2101 | 0.919 (0.00) | 0.944 (0.00) | 0.945 (0.00) | **0.949 (0.00)** | 0.931 (0.01) | 0.794 (0.24) | 0.827 (0.00) | 0.877 (0.03) | 0.883 (0.00) | 0.645 (0.01) || agentic-prompt-injection-5k test, F1 (suppl.) | 545 | 0.867 (0.32) | 0.851 (0.37) | 0.850 (0.37) | 0.868 (0.32) | **0.897 (0.24)** | 0.727 (0.66) | 0.774 (0.47) | 0.689 (0.95) | 0.800 (0.20) | 0.743 (0.21) || Macro average, 10 card sets | | 0.872 | 0.895 | 0.889 | 0.904 | 0.885 | 0.531 | 0.626 | 0.809 | 0.771 | 0.534 |
**Horizon's protocol (raw text, sliding windows, max over windows), full sets**
| Eval set | n | Galvanize 2 @0.662 | Galvanize 2 @0.5 | Horizon small (141M) @0.5 | Horizon base (308M) @0.5 | Horizon large @0.5 | Galvanize-60M @0.95 | ProtectAI v2 @0.5 | deepset @0.5 | Wolf Defender @0.5 | NeuralTrust small @0.5 ||---|---:|---|---|---|---|---|---|---|---|---|---|| NotInject (benign, trigger words), accuracy | 339 | **0.982** | 0.956 | 0.962 | 0.944 | 0.932 | 0.537 | 0.566 | 0.286 | 0.923 | 0.944 || XSTest (benign for injection), accuracy | 450 | **1.000** | **1.000** | **1.000** | 0.998 | **1.000** | 0.276 | **1.000** | **1.000** | 0.964 | 0.720 || OR-Bench-hard-1k (benign), accuracy | 1319 | **0.999** | 0.996 | 0.995 | 0.993 | 0.993 | 0.202 | 0.935 | 0.803 | 0.857 | 0.452 || jackhhao/jailbreak-classification test, F1 | 262 | 0.919 (0.02) | 0.933 (0.03) | 0.909 (0.04) | 0.928 (0.02) | 0.870 (0.03) | **0.947 (0.09)** | 0.911 (0.02) | 0.706 (0.94) | 0.946 (0.05) | 0.843 (0.04) || deepset/prompt-injections test, F1 | 116 | 0.710 (0.00) | 0.788 (0.00) | 0.812 (0.00) | 0.775 (0.00) | 0.812 (0.00) | 0.929 (0.14) | 0.537 (0.00) | **0.992 (0.00)** | 0.750 (0.00) | 0.356 (0.00) || Simsonsun jailbreaks, recall | 2426 | 0.710 | 0.788 | 0.763 | 0.823 | 0.765 | 0.857 | 0.540 | **0.996** | 0.837 | 0.747 || Agentic boundary pairs test, F1 | 240 | 0.984 (0.03) | 0.980 (0.04) | 0.976 (0.05) | 0.971 (0.05) | **0.992 (0.00)** | 0.665 (0.76) | 0.697 (0.57) | 0.667 (1.00) | 0.787 (0.28) | 0.835 (0.12) || BIPIA (derived), F1 | 3178 | 0.475 (0.02) | 0.557 (0.03) | 0.528 (0.04) | 0.630 (0.02) | 0.681 (0.06) | 0.656 (0.36) | 0.312 (0.20) | **0.971 (1.00)** | 0.270 (0.07) | 0.070 (0.00) || PIArena (derived), F1 | 1500 | 0.923 (0.00) | 0.939 (0.00) | 0.937 (0.00) | **0.970 (0.00)** | 0.949 (0.00) | 0.275 (0.05) | 0.366 (0.01) | 0.672 (0.98) | 0.342 (0.00) | 0.125 (0.00) || LLMail-Inject phase 2, recall | 2000 | 0.982 | 0.988 | 0.991 | 0.998 | 0.996 | 0.713 | 0.485 | **1.000** | 0.913 | 0.181 || neuralchemy core test, F1 (suppl.) | 942 | 0.955 (0.03) | 0.958 (0.03) | 0.960 (0.03) | **0.961 (0.03)** | 0.958 (0.03) | 0.957 (0.11) | 0.917 (0.03) | 0.865 (0.41) | 0.935 (0.04) | 0.866 (0.05) || S-Labs test, F1 (suppl.) | 2101 | 0.919 (0.00) | 0.944 (0.00) | 0.945 (0.00) | **0.949 (0.00)** | 0.931 (0.01) | 0.794 (0.24) | 0.827 (0.00) | 0.877 (0.03) | 0.883 (0.00) | 0.645 (0.01) || agentic-prompt-injection-5k test, F1 (suppl.) | 545 | 0.867 (0.32) | 0.851 (0.37) | 0.850 (0.37) | 0.868 (0.32) | **0.897 (0.24)** | 0.727 (0.66) | 0.774 (0.47) | 0.689 (0.95) | 0.800 (0.20) | 0.743 (0.21) || Macro average, 10 card sets | | 0.868 | 0.892 | 0.887 | 0.903 | 0.899 | 0.606 | 0.635 | 0.809 | 0.759 | 0.527 |
**Horizon's protocol, decontaminated subset**
| Eval set | n | Galvanize 2 @0.662 | Galvanize 2 @0.5 | Horizon small (141M) @0.5 | Horizon base (308M) @0.5 | Horizon large @0.5 | Galvanize-60M @0.95 | ProtectAI v2 @0.5 | deepset @0.5 | Wolf Defender @0.5 | NeuralTrust small @0.5 ||---|---:|---|---|---|---|---|---|---|---|---|---|| NotInject (benign, trigger words), accuracy | 339 | **0.982** | 0.956 | 0.962 | 0.944 | 0.932 | 0.537 | 0.566 | 0.286 | 0.923 | 0.944 || XSTest (benign for injection), accuracy | 441 | **1.000** | **1.000** | **1.000** | 0.998 | **1.000** | 0.270 | **1.000** | **1.000** | 0.964 | 0.717 || OR-Bench-hard-1k (benign), accuracy | 1312 | **0.999** | 0.995 | 0.995 | 0.993 | 0.994 | 0.203 | 0.934 | 0.803 | 0.856 | 0.452 || jackhhao/jailbreak-classification test, F1 | 136 | 0.931 (0.01) | **0.933 (0.02)** | 0.907 (0.03) | 0.931 (0.01) | 0.873 (0.02) | 0.857 (0.10) | 0.886 (0.01) | 0.452 (0.94) | 0.907 (0.03) | 0.861 (0.03) || deepset/prompt-injections test, F1 | 116 | 0.710 (0.00) | 0.788 (0.00) | 0.812 (0.00) | 0.775 (0.00) | 0.812 (0.00) | 0.929 (0.14) | 0.537 (0.00) | **0.992 (0.00)** | 0.750 (0.00) | 0.356 (0.00) || Simsonsun jailbreaks, recall | 2295 | 0.703 | 0.782 | 0.758 | 0.819 | 0.764 | 0.850 | 0.523 | **0.996** | 0.830 | 0.746 || Agentic boundary pairs test, F1 | 240 | 0.984 (0.03) | 0.980 (0.04) | 0.976 (0.05) | 0.971 (0.05) | **0.992 (0.00)** | 0.665 (0.76) | 0.697 (0.57) | 0.667 (1.00) | 0.787 (0.28) | 0.835 (0.12) || BIPIA (derived), F1 | 3178 | 0.475 (0.02) | 0.557 (0.03) | 0.528 (0.04) | 0.630 (0.02) | 0.681 (0.06) | 0.656 (0.36) | 0.312 (0.20) | **0.971 (1.00)** | 0.270 (0.07) | 0.070 (0.00) || PIArena (derived), F1 | 1500 | 0.923 (0.00) | 0.939 (0.00) | 0.937 (0.00) | **0.970 (0.00)** | 0.949 (0.00) | 0.275 (0.05) | 0.366 (0.01) | 0.672 (0.98) | 0.342 (0.00) | 0.125 (0.00) || LLMail-Inject phase 2, recall | 2000 | 0.982 | 0.988 | 0.991 | 0.998 | 0.996 | 0.713 | 0.485 | **1.000** | 0.913 | 0.181 || neuralchemy core test, F1 (suppl.) | 940 | 0.954 (0.03) | 0.958 (0.03) | 0.960 (0.03) | **0.961 (0.03)** | 0.957 (0.03) | 0.957 (0.11) | 0.917 (0.03) | 0.865 (0.41) | 0.935 (0.04) | 0.866 (0.05) || S-Labs test, F1 (suppl.) | 2101 | 0.919 (0.00) | 0.944 (0.00) | 0.945 (0.00) | **0.949 (0.00)** | 0.931 (0.01) | 0.794 (0.24) | 0.827 (0.00) | 0.877 (0.03) | 0.883 (0.00) | 0.645 (0.01) || agentic-prompt-injection-5k test, F1 (suppl.) | 545 | 0.867 (0.32) | 0.851 (0.37) | 0.850 (0.37) | 0.868 (0.32) | **0.897 (0.24)** | 0.727 (0.66) | 0.774 (0.47) | 0.689 (0.95) | 0.800 (0.20) | 0.743 (0.21) || Macro average, 10 card sets | | 0.869 | 0.892 | 0.886 | 0.903 | 0.899 | 0.595 | 0.631 | 0.784 | 0.754 | 0.529 |
**Reproduction check** (Horizon's protocol on the full sets vs the numbers published in Horizon's repository, threshold 0.5; Horizon used bf16 autocast, this benchmark runs fp32):
| Model | max abs delta accuracy | max abs delta ROC AUC ||---|---:|---:|| deepset | 0.002 | 0.002 || Horizon base (308M) | 0.009 | 0.001 || NeuralTrust small | 0.009 | 0.002 || ProtectAI v2 | 0.003 | 0.001 || Wolf Defender | 0.005 | 0.001 |
**Decontamination** (rows removed for the decontaminated subset: their text matched a row of the Galvanize 2 training data; see README):
| Eval set | n | exact match % | normalised match % | any match % | excluded | kept | upstream train-split overlap % ||---|---:|---:|---:|---:|---:|---:|---:|| notinject | 339 | 0.00 | 0.00 | 0.00 | 0 | 339 | 0.00 || xstest | 450 | 2.00 | 2.00 | 2.00 | 9 | 441 | 15.33 || orbench_hard | 1319 | 0.53 | 0.53 | 0.53 | 7 | 1312 | 99.92 || jackhhao_test | 262 | 16.03 | 33.97 | 48.09 | 126 | 136 | 87.02 || deepset_test | 116 | 0.00 | 0.00 | 0.00 | 0 | 116 | 0.00 || simsonsun_jailbreaks | 2426 | 0.99 | 2.68 | 5.40 | 131 | 2295 | 4.95 || boundary_pairs_test | 240 | 0.00 | 0.00 | 0.00 | 0 | 240 | 0.00 || bipia | 3178 | 0.00 | 0.00 | 0.00 | 0 | 3178 | 0.00 || piarena | 1500 | 0.00 | 0.00 | 0.00 | 0 | 1500 | 0.00 || llmail_phase2 | 2000 | 0.00 | 0.00 | 0.00 | 0 | 2000 | 0.00 || neuralchemy_test | 942 | 0.00 | 0.00 | 0.21 | 2 | 940 | 1.06 || slabs_test | 2101 | 0.00 | 0.00 | 0.00 | 0 | 2101 | 0.00 || agentic5k_test | 545 | 0.00 | 0.00 | 0.00 | 0 | 545 | 0.00 |
Galvanize 2 is fine-tuned from Horizon small, so any overlap between the eval sets and Horizon's training data is inherited. Horizon's training set is not published; the last column is the overlap with the upstream *train* splits of the sources Horizon lists (deepset, jackhhao, neuralchemy core, S-Labs, agentic-prompt-injection-5k, or-bench-80k), an upper bound since Horizon states it deduplicated against every eval set. It is informational and is not used to filter rows.
## Method
- Hardware and software: 1x NVIDIA L4 GPU, fp32, TF32 off; torch 2.11.0+cu130, transformers 5.18.0, Python 3.13.15.- Data: `Horizon-Labs/prompt-injection-eval-suite` @ `27c7bcd6f46e842f4c4d8b114b30eb6b1d892965`; every parquet checked against its SHA-256. Labels as published (1 = injection or jailbreak, 0 = benign; plain harmful requests are benign under this suite's definition). Horizon's synthetic sets are not used.- Models (revision, weights SHA-256 checked): Galvanize 2 `usezn/Galvanize-2` (model.safetensors SHA-256 `3f474d28f4d3`); Horizon small (141M) `Horizon-Labs/prompt-injection-guard-small@e0e88c4e940e`; Horizon base (308M) `Horizon-Labs/prompt-injection-guard-base@e4fbfc6f603e`; Horizon large `Horizon-Labs/prompt-injection-guard-large@bbc67bafa71c`; Galvanize-60M `usezn/Galvanize-60M@7bf8df0d3c9c`; ProtectAI v2 `protectai/deberta-v3-base-prompt-injection-v2@90c9989b1a34`; deepset `deepset/deberta-v3-base-injection@80dda00d0b0d`; Wolf Defender `patronus-studio/wolf-defender-prompt-injection@a77e7b669f07`; NeuralTrust small `NeuralTrust/prompt-guard-oss-small@40e5c56b68a1`.- Thresholds: Galvanize 2 0.662 (its development-set threshold, also shown at 0.5); Galvanize-60M 0.95 (its published calibrated threshold, on sigmoid(0.7 * (logit + 17.6063))); every other model 0.5 (their default).- Serving protocol: re.sub(r"\s+", " ", text).strip(), model tokenizer, first 512 tokens, one window, fp32. Horizon protocol: Horizon's evaluate.py: raw text, window min(2048, max positions) (512 for DeBERTa and Galvanize-60M), stride window // 4, document score = max over windows, fp32.- Metrics: accuracy for all-benign sets, recall for all-attack sets, F1 (with FPR) otherwise, as in Horizon's card; ROC AUC and normalised pAUC up to 10% FPR are threshold-free. Macro average = mean over the 10 card sets (Horizon's card macro also includes Qualifire and the two Mindgard sets, which are gated).
**Not evaluated**
- `leolee99/PIGuard`: custom architecture that needs trust_remote_code (excluded by policy)- `meta-llama/Llama-Prompt-Guard-2-86M`: gated (manual approval, Llama license)- `meta-llama/Llama-Prompt-Guard-2-22M`: gated (manual approval, Llama license)- `qualifire/prompt-injections-benchmark (dataset)`: gated and non-commercial; not in the public suite- `Mindgard/evaded-prompt-injection-and-jailbreak-samples (dataset)`: gated and non-commercial; not in the public suite- `Horizon synthetic_* sets (dataset)`: generated with the same generator as Horizon's training data (in-distribution for Horizon and, through initialisation, for Galvanize 2)- `Commercial APIs (e.g. Lakera Guard, Azure Prompt Shields)`: paid APIs, not open weights123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686#!/usr/bin/env python3# Copyright 2026 zn (usezn.com)# SPDX-License-Identifier: Apache-2.0"""Reproduce the public benchmark of usezn/Galvanize-2 against open prompt-injection detectors.
Data: Horizon-Labs/prompt-injection-eval-suite at a pinned revision (every parquet is checked against its SHA-256).Models: public, ungated Hugging Face checkpoints at pinned revisions (weights SHA-256 checked).Protocol (primary, "serve"): whitespace flattened with re.sub(r"\\s+", " ", text).strip(), each model's own tokenizer,first 512 tokens, one window, fp32. Optional "hz" protocol: Horizon's evaluate.py sliding windows, max over windows.Decontamination: the row ids listed in decontam_excluded_ids.json are removed for the primary ("decontaminated") numbers.
Usage: python run_benchmark.py # every model, serving protocol python run_benchmark.py --protocol both # also Horizon's windowed protocol python run_benchmark.py --models galvanize-2,horizon-small --limit 24 --device cpu # quick smoke
Outputs: <out-dir>/results.json and <out-dir>/results.md. The script never prints benchmark text."""import argparseimport hashlibimport jsonimport mathimport osimport reimport sysimport time
import numpy as np
HERE = os.path.dirname(os.path.abspath(__file__))
# ---------------------------------------------------------------------------------------------------------------------# Eval suite (pinned)# ---------------------------------------------------------------------------------------------------------------------SUITE_REPO = 'Horizon-Labs/prompt-injection-eval-suite'SUITE_REV = '27c7bcd6f46e842f4c4d8b114b30eb6b1d892965'SUITE_SHA = { 'notinject': '75d8a7bfde6172335d6178dbfba192209570309a19edfdb11d2120a3b6e919d0', 'xstest': '3ca278fe64310fa5172d34cd17eef9ef8cbe2d20300756c6424d07d41154b90c', 'orbench_hard': 'ceaa7b010b08377187e637d2f7c61912914fa0b8f3788cabdcfbc1c16b3c85a8', 'deepset_test': 'e2c1ed4700967312e2e95e87ae48c0e0617d02b0fed4335b0d9a631b66bb47d6', 'jackhhao_test': '5a1987583bf94e528f8cfc98f21664eb1206af605f44979317e30a8c4a2b5a87', 'simsonsun_jailbreaks': '967cdd37e16e5377e476706e4047d2871c930ca48dc829b4001abe76ec72a0dc', 'boundary_pairs_test': '44e5d543bd4bef91249b91a5d996086631e4cae4d499616bed4202fd4b4b774d', 'bipia': '744ab24ff443589df2d7ea22fc42618f124f5682487938021f35bdf08c8374bd', 'piarena': '0bbd59a14b622e0ed8630cac365c136537c2ab2b31e4b3fd9587b5edc0b88b9a', 'llmail_phase2': '707adf5b915a7f59362a50ccce0652f9b48a145c3a8927762e06c5a777552a9f', 'neuralchemy_test': 'b8228d74858b2e8d2e4e3c9589423e9758fc4b17e1e5a67a00b4bce812a8bcb9', 'slabs_test': '67fab0e0cf485f6530f53fdf291a89f27c75e01f674e78ae1a61286642b02f90', 'agentic5k_test': 'a1adbc4052b57594be26bea9a4064d91bc2291297cf452760ea9938fb7aab14a',}# (rows, attack rows) per set at SUITE_REVEXPECT = {'notinject': (339, 0), 'xstest': (450, 0), 'orbench_hard': (1319, 0), 'deepset_test': (116, 60), 'jackhhao_test': (262, 139), 'simsonsun_jailbreaks': (2426, 2426), 'boundary_pairs_test': (240, 120), 'bipia': (3178, 3000), 'piarena': (1500, 750), 'llmail_phase2': (2000, 2000), 'neuralchemy_test': (942, 552), 'slabs_test': (2101, 1051), 'agentic5k_test': (545, 280)}# Horizon's metric per model-card row: accuracy for all-benign sets, recall for all-attack sets, F1 otherwise.CARD_METRIC = {'notinject': 'acc', 'xstest': 'acc', 'orbench_hard': 'acc', 'jackhhao_test': 'f1', 'deepset_test': 'f1', 'simsonsun_jailbreaks': 'recall', 'boundary_pairs_test': 'f1', 'bipia': 'f1', 'piarena': 'f1', 'llmail_phase2': 'recall'}SUPP_METRIC = {'neuralchemy_test': 'f1', 'slabs_test': 'f1', 'agentic5k_test': 'f1'}METRIC_OF = {**CARD_METRIC, **SUPP_METRIC}SET_NAMES = list(CARD_METRIC) + list(SUPP_METRIC)SET_LABEL = {'notinject': 'NotInject (benign, trigger words), accuracy', 'xstest': 'XSTest (benign for injection), accuracy', 'orbench_hard': 'OR-Bench-hard-1k (benign), accuracy', 'deepset_test': 'deepset/prompt-injections test, F1', 'jackhhao_test': 'jackhhao/jailbreak-classification test, F1', 'simsonsun_jailbreaks': 'Simsonsun jailbreaks, recall', 'boundary_pairs_test': 'Agentic boundary pairs test, F1', 'bipia': 'BIPIA (derived), F1', 'piarena': 'PIArena (derived), F1', 'llmail_phase2': 'LLMail-Inject phase 2, recall', 'neuralchemy_test': 'neuralchemy core test, F1 (suppl.)', 'slabs_test': 'S-Labs test, F1 (suppl.)', 'agentic5k_test': 'agentic-prompt-injection-5k test, F1 (suppl.)'}
# ---------------------------------------------------------------------------------------------------------------------# Models (pinned revision + SHA-256 of model.safetensors; positive label as resolved in the reference run)# ---------------------------------------------------------------------------------------------------------------------# Revision of usezn/Galvanize-2 to score. The weights are checked against GALVANIZE2_SHA, the exact file benchmarked.GALVANIZE2_REVISION = 'b61e50d37c5647788d7b9e301f4e76e246edbfd1'GALVANIZE2_SHA = '3f474d28f4d39ca3ba95fba760fd5daa4687952de89ee5c1232f66cd99357eee'GALVANIZE2_THR = 0.661988004118821 # development-set threshold (shown as 0.662)MODELS = { 'galvanize-2': {'name': 'Galvanize 2', 'repo': 'usezn/Galvanize-2', 'rev': GALVANIZE2_REVISION, 'sha': GALVANIZE2_SHA, 'thr': GALVANIZE2_THR, 'pos_label': 'INJECTION'}, 'horizon-small': {'name': 'Horizon small (141M)', 'repo': 'Horizon-Labs/prompt-injection-guard-small', 'rev': 'e0e88c4e940ee7e1b52bdf943d501ec696b83b9b', 'sha': 'a23196c117baf414b4b8abd138c5f5656e728877c0bdb2775c361ee89df16deb', 'thr': 0.5, 'pos_label': 'INJECTION'}, 'horizon-base': {'name': 'Horizon base (308M)', 'repo': 'Horizon-Labs/prompt-injection-guard-base', 'rev': 'e4fbfc6f603e24c675cdf310c3b8d7abaa825666', 'sha': 'd0c0f899f118481855cfe34ba718cf5e44613d266270721c380d54741626d405', 'thr': 0.5, 'pos_label': 'INJECTION'}, 'horizon-large': {'name': 'Horizon large', 'repo': 'Horizon-Labs/prompt-injection-guard-large', 'rev': 'bbc67bafa71c791ad802d4df0ae7639d4e880dea', 'sha': '81bd637f0964fea52d452ddda3c814cf7d822ca7db6b2a34015db668f4a183bf', 'thr': 0.5, 'pos_label': 'INJECTION'}, 'galvanize-60m': {'name': 'Galvanize-60M', 'repo': 'usezn/Galvanize-60M', 'rev': '7bf8df0d3c9cd724c5773a1c73d7c81ebb0f2082', 'sha': '53684cff19857acaa0fd8bb81c9271224d56e5ef1f9b4942a9ddaa846f1e4027', 'thr': 0.95, 'pos_label': 'MALICIOUS'}, 'protectai-v2': {'name': 'ProtectAI v2', 'repo': 'protectai/deberta-v3-base-prompt-injection-v2', 'rev': '90c9989b1a342275dd0d1a95aad283c04e075671', 'sha': '6521cb8d0ac08148c81464899c424e6148fcc62befa371089fa4061d8b6e0424', 'thr': 0.5, 'pos_label': 'INJECTION'}, 'deepset': {'name': 'deepset', 'repo': 'deepset/deberta-v3-base-injection', 'rev': '80dda00d0b0d9a03917a7685e2ddbcd28e04dbb1', 'sha': '16862b96671d118a79b8d3a1352a552913797f9fc3cc7db2e06a05002abfc084', 'thr': 0.5, 'pos_label': 'INJECTION'}, 'wolf-defender': {'name': 'Wolf Defender', 'repo': 'patronus-studio/wolf-defender-prompt-injection', 'rev': 'a77e7b669f079c3ad7e72e4ad10f3bd173ac4f4d', 'sha': 'e8330cc19b083deb45847d873a69bc840cd8913b62a631289e2c034fa5b6cf3b', 'thr': 0.5, 'pos_label': 'injection'}, 'neuraltrust-small': {'name': 'NeuralTrust small', 'repo': 'NeuralTrust/prompt-guard-oss-small', 'rev': '40e5c56b68a1b081484c3e56c9bee726e2749138', 'sha': '5b1ba9c313447d445146016125ab337a2b5298b2dc2198fcd20e20727a32382f', 'thr': 0.5, 'pos_label': 'jailbreak'},}# Galvanize-60M: published head, P(injection) = sigmoid(0.7 * (raw_logit + 17.6063)); its encoder is a 4-layer cut of# ModernBERT-base (architecture only; every weight comes from the Galvanize-60M checkpoint, loaded strictly).G60_HEAD = {'scale': 0.7, 'shift': -17.60634142857143}MBB_REPO, MBB_REV = 'answerdotai/ModernBERT-base', '8949b909ec900327062f0ebf497f51aef5e6f0c8'NOT_EVALUATED = { 'leolee99/PIGuard': 'custom architecture that needs trust_remote_code (excluded by policy)', 'meta-llama/Llama-Prompt-Guard-2-86M': 'gated (manual approval, Llama license)', 'meta-llama/Llama-Prompt-Guard-2-22M': 'gated (manual approval, Llama license)', 'qualifire/prompt-injections-benchmark (dataset)': 'gated and non-commercial; not in the public suite', 'Mindgard/evaded-prompt-injection-and-jailbreak-samples (dataset)': 'gated and non-commercial; not in the public suite', 'Horizon synthetic_* sets (dataset)': 'generated with the same generator as Horizon\'s training data (in-distribution for ' 'Horizon and, through initialisation, for Galvanize 2)', 'Commercial APIs (e.g. Lakera Guard, Azure Prompt Shields)': 'paid APIs, not open weights',}POS_RE = re.compile(r'inject|jailbreak|malicious|unsafe|attack', re.I)
SEQ = 512TOKEN_BUDGET = 32768SUBSETS = ('decontaminated', 'full')PROTOCOL_DESC = {'serve': 're.sub(r"\\s+", " ", text).strip(), model tokenizer, first %d tokens, one window, fp32' % SEQ, 'hz': "Horizon's evaluate.py: raw text, window min(2048, max positions) (512 for DeBERTa and Galvanize-60M), " 'stride window // 4, document score = max over windows, fp32'}_WS = re.compile(r'\s+')
# ---------------------------------------------------------------------------------------------------------------------# Helpers# ---------------------------------------------------------------------------------------------------------------------def log(msg, **kw): print(json.dumps({'t': round(time.time() - T0, 1), 'evt': msg, **kw}, default=float), flush=True)
T0 = time.time()
def sha256_file(path): h = hashlib.sha256() with open(path, 'rb') as f: for chunk in iter(lambda: f.read(1 << 20), b''): h.update(chunk) return h.hexdigest()
def flat(t): # Serving input: identical to the reference run. return _WS.sub(' ', str(t)).strip()
def logit(p): return math.log(p / (1.0 - p))
def r4(x): return None if x is None else round(float(x), 4)
_trap = getattr(np, 'trapezoid', None) or getattr(np, 'trapz')
def pauc(y, z, max_fpr=0.10): from sklearn.metrics import roc_curve fpr, tpr, _ = roc_curve(y, z) stop = int(np.searchsorted(fpr, max_fpr, 'right')) x = np.r_[fpr[:stop], max_fpr] v = np.r_[tpr[:stop], np.interp(max_fpr, fpr, tpr)] return float(_trap(v, x) / max_fpr)
def metrics(y, z, p_thr): from sklearn.metrics import roc_auc_score y, z = np.asarray(y), np.asarray(z) n, pos = len(y), int(y.sum()) if n == 0: return {'n': 0} pred = z >= logit(p_thr) tp, fp = int((pred & (y == 1)).sum()), int((pred & (y == 0)).sum()) r = {'n': n, 'pos': pos, 'thr': r4(p_thr), 'acc': r4((pred == (y == 1)).mean())} if pos: r['recall'] = r4(tp / pos) if pos < n: r['fpr'] = r4(fp / (n - pos)) if 0 < pos < n: prec = tp / (tp + fp) if tp + fp else 0.0 rec = tp / pos r.update(auroc=r4(roc_auc_score(y, z)), pauc10=r4(pauc(y, z)), precision=r4(prec), f1=r4(2 * prec * rec / (prec + rec) if prec + rec else 0.0)) return r
# ---------------------------------------------------------------------------------------------------------------------# Data# ---------------------------------------------------------------------------------------------------------------------def load_excluded(path): d = json.load(open(path, encoding='utf-8')) if d.get('dataset') != SUITE_REPO or d.get('revision') != SUITE_REV: raise SystemExit('%s does not belong to %s@%s' % (path, SUITE_REPO, SUITE_REV)) for s in SET_NAMES: if len(d['excluded'][s]) != d['counts'][s]['excluded']: raise SystemExit('inconsistent exclusion list for ' + s) return {s: np.asarray(d['excluded'][s], dtype=np.int64) for s in SET_NAMES}, d['counts']
def load_suite(limit, excluded): import pandas as pd from huggingface_hub import hf_hub_download sets = {} for s in SET_NAMES: p = hf_hub_download(SUITE_REPO, 'data/%s.parquet' % s, repo_type='dataset', revision=SUITE_REV) if sha256_file(p) != SUITE_SHA[s]: raise SystemExit('sha256 mismatch for %s: not the pinned eval-suite file' % s) df = pd.read_parquet(p) y = df['label'].astype(int).to_numpy() if not (set(np.unique(y)) <= {0, 1} and (len(y), int(y.sum())) == EXPECT[s]): raise SystemExit('unexpected row or label counts in ' + s) text = ['' if t is None else str(t) for t in df['text'].tolist()] row = np.arange(len(y)) if limit: # stratified, fixed seed: up to limit // 2 attacks and limit // 2 benign rows per set rng = np.random.default_rng(7) k = max(1, limit // 2) keep = np.sort(np.r_[rng.permutation(np.where(y == 1)[0])[:k], rng.permutation(np.where(y == 0)[0])[:k]]) text, y, row = [text[i] for i in keep], y[keep], keep masks = {'full': np.ones(len(y), bool), 'decontaminated': ~np.isin(row, excluded[s])} sets[s] = {'text': text, 'y': y, 'row': row, 'mask': masks} return sets
# ---------------------------------------------------------------------------------------------------------------------# Scoring# ---------------------------------------------------------------------------------------------------------------------def windows(tok, texts, proto, window): ids, owner = [], [] for k in range(0, len(texts), 256): chunk = texts[k:k + 256] if proto == 'serve': enc = tok([flat(t) for t in chunk], truncation=True, max_length=SEQ) ids += enc['input_ids'] owner += list(range(k, k + len(chunk))) else: enc = tok(chunk, truncation=True, max_length=window, stride=window // 4, return_overflowing_tokens=True) ids += enc['input_ids'] owner += [k + int(j) for j in enc['overflow_to_sample_mapping']] return ids, np.array(owner)
def score_ids(fwd, ids, pad_id, device): import torch order = sorted(range(len(ids)), key=lambda i: len(ids[i])) out = np.zeros(len(ids), dtype=np.float64) k = 0 with torch.no_grad(): while k < len(order): L = len(ids[order[min(len(order) - 1, k + 255)]]) bs = max(1, min(256, TOKEN_BUDGET // max(1, L))) idx = order[k:k + bs] L = max(len(ids[i]) for i in idx) ii = torch.full((len(idx), L), pad_id, dtype=torch.long) am = torch.zeros((len(idx), L), dtype=torch.long) for j, i in enumerate(idx): ii[j, :len(ids[i])] = torch.tensor(ids[i]) am[j, :len(ids[i])] = 1 out[idx] = fwd(ii.to(device), am.to(device)).double().cpu().numpy() k += len(idx) return out
def doc_scores(z_win, owner, n): z = np.full(n, -np.inf) np.maximum.at(z, owner, z_win) return z
def check_weights(spec): from huggingface_hub import hf_hub_download p = hf_hub_download(spec['repo'], 'model.safetensors', revision=spec['rev']) got = sha256_file(p) if got != spec['sha']: raise RuntimeError('model.safetensors sha256 %s... differs from the benchmarked file %s...' % (got[:12], spec['sha'][:12])) return p
def hf_classifier(spec, device): from transformers import AutoModelForSequenceClassification m = None for attn in ('sdpa', 'eager'): try: m = AutoModelForSequenceClassification.from_pretrained(spec['repo'], revision=spec['rev'], attn_implementation=attn) break except Exception as e: # DeBERTa-v2 has no SDPA path: falls back to eager, as in the reference run log('load_retry', model=spec['repo'], attn=attn, err=type(e).__name__) if m is None: raise RuntimeError('could not load ' + spec['repo']) if hasattr(m.config, 'reference_compile'): m.config.reference_compile = False # no torch.compile inside ModernBERT (variable shapes) m = m.float().eval().to(device) labels = {int(k): v for k, v in m.config.id2label.items()} if len(labels) != 2: raise RuntimeError('expected a 2-class head') hits = [i for i, v in labels.items() if POS_RE.search(v)] pi = hits[0] if hits else max(labels) ni = 1 - pi if labels[pi] != spec['pos_label']: raise RuntimeError('positive label %r differs from the reference run (%r)' % (labels[pi], spec['pos_label']))
def fwd(ii, am): lg = m(input_ids=ii, attention_mask=am).logits.float() return lg[:, pi] - lg[:, ni] # margin z, P(injection) = sigmoid(z) mx = int(getattr(m.config, 'max_position_embeddings', 512) or 512) window = 512 if 'deberta' in m.config.model_type else min(2048, mx if mx < 100000 else 512) return m, fwd, window, {'positive_label': labels[pi], 'model_type': m.config.model_type, 'hz_window': window}
def load_galvanize60m(spec, device): # FP32 weights with the loader published in the usezn/Galvanize-60M model card. import torch from safetensors.torch import load_file from transformers import AutoModel, AutoTokenizer
class G60Pooler(torch.nn.Module): def __init__(self, hidden=768, dk=128, nq=4): super().__init__() self.q_proj = torch.nn.Linear(hidden, dk, bias=False) self.k_proj = torch.nn.Linear(hidden, dk, bias=False) self.queries = torch.nn.Parameter(torch.zeros(nq, hidden))
def forward(self, hs, am): att = (self.q_proj(self.queries) @ self.k_proj(hs).transpose(1, 2)) / 128 ** 0.5 att = att.masked_fill(am[:, None, :] == 0, torch.finfo(att.dtype).min) return (torch.softmax(att, dim=-1) @ hs).reshape(hs.size(0), -1)
class G60(torch.nn.Module): def __init__(self, encoder): super().__init__() self.encoder, self.pooler = encoder, G60Pooler() self.classifier = torch.nn.Sequential(torch.nn.Identity(), torch.nn.Linear(3072, 384), torch.nn.GELU(), torch.nn.Linear(384, 1))
def forward(self, input_ids, attention_mask): hs = self.encoder(input_ids=input_ids, attention_mask=attention_mask).last_hidden_state return self.classifier(self.pooler(hs, attention_mask)).squeeze(-1)
w = check_weights(spec) enc = AutoModel.from_pretrained(MBB_REPO, revision=MBB_REV, attn_implementation='eager') enc.layers = torch.nn.ModuleList([enc.layers[i] for i in (0, 7, 14, 21)]) enc.config.num_hidden_layers = 4 enc.layers[0].attn_norm = torch.nn.Identity() if hasattr(enc.config, 'reference_compile'): enc.config.reference_compile = False m = G60(enc) m.load_state_dict(load_file(w), strict=True) m = m.float().eval().to(device) tok = AutoTokenizer.from_pretrained(spec['repo'], revision=spec['rev'])
def fwd(ii, am): return G60_HEAD['scale'] * (m(ii, am).float() - G60_HEAD['shift']) return m, tok, fwd, 512, {'positive_label': 'MALICIOUS', 'model_type': 'galvanize-60m', 'hz_window': 512}
def load_model(key, device): from transformers import AutoTokenizer spec = MODELS[key] if key == 'galvanize-60m': return load_galvanize60m(spec, device) check_weights(spec) tok = AutoTokenizer.from_pretrained(spec['repo'], revision=spec['rev']) m, fwd, window, info = hf_classifier(spec, device) return m, tok, fwd, window, info
def tokenizer_guard(tok, sets): # Galvanize 2 serving contract: its tokenizer must produce the same ids as Horizon small's (the reference run checked this). from transformers import AutoTokenizer ref = MODELS['horizon-small'] ref_tok = AutoTokenizer.from_pretrained(ref['repo'], revision=ref['rev']) texts = [t for s in SET_NAMES for t in sets[s]['text'][:3]][:16] a, b = windows(tok, texts, 'serve', SEQ)[0], windows(ref_tok, texts, 'serve', SEQ)[0] if a != b: raise RuntimeError('Galvanize 2 tokenizer ids differ from the reference serving tokenizer')
# ---------------------------------------------------------------------------------------------------------------------# Aggregation and report# ---------------------------------------------------------------------------------------------------------------------def macro(res_kp, sub, tk): vals = [res_kp[s][sub][tk].get(CARD_METRIC[s]) for s in CARD_METRIC if s in res_kp] vals = [v for v in vals if v is not None] return {'value': r4(np.mean(vals)) if vals else None, 'n_sets': len(vals)}
def repro_vs_horizon(res, path): if not os.path.exists(path): return None pub = json.load(open(path, encoding='utf-8')) out = {} for key, by_set in pub['models'].items(): if key not in res or 'hz' not in res[key]: continue d_acc, d_auc = {}, {} for s, ref in by_set.items(): if s in res[key]['hz']: ours = res[key]['hz'][s]['full']['p05'] if ref.get('acc') is not None: d_acc[s] = r4(ours['acc'] - ref['acc']) if ref.get('auc') is not None and ours.get('auroc') is not None: d_auc[s] = r4(ours['auroc'] - ref['auc']) out[key] = {'delta_acc': d_acc, 'delta_auroc': d_auc, 'max_abs_delta_acc': r4(max(map(abs, d_acc.values()))) if d_acc else None, 'max_abs_delta_auroc': r4(max(map(abs, d_auc.values()))) if d_auc else None} return out
def compare_with_reference(res, path): if not os.path.exists(path): return None ref = json.load(open(path, encoding='utf-8')).get('results', {}) out = {} for key, by_proto in res.items(): deltas = [] for proto, by_set in by_proto.items(): for s, by_sub in by_set.items(): for sub, by_tk in by_sub.items(): for tk, m in by_tk.items(): r = ref.get(key, {}).get(proto, {}).get(s, {}).get(sub, {}).get(tk) if not r: continue for f in ('acc', 'recall', 'fpr', 'f1', 'auroc', 'pauc10'): if m.get(f) is not None and r.get(f) is not None: deltas.append(abs(m[f] - r[f])) out[key] = {'compared_values': len(deltas), 'max_abs_delta': r4(max(deltas)) if deltas else None} return out
def _thr_txt(t): return ('%.3f' % t).rstrip('0').rstrip('.')
def render_markdown(doc): models, res = doc['models'], doc['results'] first = [k for k in models if k in res] cols = [] for k in first: cols.append((k, 'own')) if k == 'galvanize-2': cols.append((k, 'p05')) protos = sorted({p for k in res for p in res[k]}, key=lambda p: 0 if p == 'serve' else 1)
def col_name(k, tk, thr_free=False): return models[k]['name'] if thr_free else '%s @%s' % (models[k]['name'], _thr_txt(models[k]['threshold']) if tk == 'own' else '0.5')
def fmt(v): return '-' if v is None else '%.3f' % v
def n_rows(proto, s, sub): for k in first: if s in res[k].get(proto, {}): return res[k][proto][s][sub]['own'].get('n', 0) return 0
def table(proto, sub, what, title): thr_free = what != 'card' cc = [(k, t) for k, t in cols if not (thr_free and t == 'p05')] sets = [s for s in SET_NAMES if any(s in res[k].get(proto, {}) for k, _ in cc)] if thr_free: sets = [s for s in sets if 0 < EXPECT[s][1] < EXPECT[s][0]] if not sets: return '' lines = ['**%s**' % title, '', '| Eval set | n | ' + ' | '.join(col_name(k, t, thr_free) for k, t in cc) + ' |', '|---|---:|' + '---|' * len(cc)] for s in sets: cells = [] for k, t in cc: m = res[k].get(proto, {}).get(s, {}).get(sub, {}).get(t) if not m: cells.append(('-', None)) continue if what == 'card': v = m.get(METRIC_OF[s]) extra = ' (%.2f)' % m['fpr'] if METRIC_OF[s] == 'f1' and m.get('fpr') is not None else '' cells.append((fmt(v) + extra, v)) else: cells.append((fmt(m.get(what)), m.get(what))) vals = [v for _, v in cells if v is not None] best = max(vals) if vals else None txt = [('**%s**' % c if v is not None and v == best else c) for c, v in cells] lines.append('| %s | %d | %s |' % (SET_LABEL[s] if what == 'card' else s, n_rows(proto, s, sub), ' | '.join(txt))) if what == 'card': mac = doc['macro_card10'] lines.append('| Macro average, 10 card sets | | %s |' % ' | '.join( fmt(mac.get(k, {}).get(proto, {}).get(sub, {}).get(t, {}).get('value')) for k, t in cc)) return '\n'.join(lines) + '\n'
run = doc['run'] md = ['# Galvanize 2 vs open prompt-injection detectors', '', 'Run %s (UTC) on %s. Data: [%s](https://huggingface.co/datasets/%s) @ `%s`. Primary numbers are on the ' '**decontaminated** subset (rows listed in `decontam_excluded_ids.json` removed) under the **serving protocol** ' '(whitespace flattened, first 512 tokens, one window). F1 cells show the false-positive rate on the benign rows in ' 'parentheses. Best value per row in bold.' % (run['date_utc'], run['hardware'], doc['suite']['repo'], doc['suite']['repo'], doc['suite']['revision'][:12]), ''] if run.get('limit'): md += ['> SMOKE RUN (`--limit %d`): a few rows per set. The numbers are not meaningful; this only checks the code path.' % run['limit'], ''] if 'serve' in protos: md.append(table('serve', 'decontaminated', 'card', 'Serving protocol, decontaminated subset, each model at its own threshold')) md.append(table('serve', 'decontaminated', 'auroc', 'Threshold-free: ROC AUC (serving protocol, decontaminated)')) md.append(table('serve', 'decontaminated', 'pauc10', 'Threshold-free: normalised partial AUC up to 10% FPR (serving protocol, decontaminated)')) md.append(table('serve', 'full', 'card', 'Serving protocol, full sets (secondary; includes the excluded rows)')) if 'hz' in protos: md.append(table('hz', 'full', 'card', "Horizon's protocol (raw text, sliding windows, max over windows), full sets")) md.append(table('hz', 'decontaminated', 'card', "Horizon's protocol, decontaminated subset")) rep = doc.get('reproduction_vs_horizon_published') if rep: md += ["**Reproduction check** (Horizon's protocol on the full sets vs the numbers published in Horizon's repository, " 'threshold 0.5; Horizon used bf16 autocast, this benchmark runs fp32):', '', '| Model | max abs delta accuracy | max abs delta ROC AUC |', '|---|---:|---:|'] md += ['| %s | %s | %s |' % (models[k]['name'], fmt(v['max_abs_delta_acc']), fmt(v['max_abs_delta_auroc'])) for k, v in rep.items()] md.append('') dc = doc['decontamination'] has_pct = any('training_overlap_any_pct' in c for c in dc.values()) md += ['**Decontamination** (rows removed for the decontaminated subset: their text matched a row of the Galvanize 2 ' 'training data; see README):', ''] if has_pct: md += ['| Eval set | n | exact match % | normalised match % | any match % | excluded | kept | upstream train-split overlap % |', '|---|---:|---:|---:|---:|---:|---:|---:|'] for s, c in dc.items(): md.append('| %s | %d | %.2f | %.2f | %.2f | %d | %d | %.2f |' % ( s, c['rows'], c['training_overlap_exact_pct'], c['training_overlap_normalised_pct'], c['training_overlap_any_pct'], c['excluded'], c['kept'], c['upstream_train_split_overlap_any_pct'])) md += ['', 'Galvanize 2 is fine-tuned from Horizon small, so any overlap between the eval sets and Horizon\'s training ' 'data is inherited. Horizon\'s training set is not published; the last column is the overlap with the upstream ' '*train* splits of the sources Horizon lists (deepset, jackhhao, neuralchemy core, S-Labs, ' 'agentic-prompt-injection-5k, or-bench-80k), an upper bound since Horizon states it deduplicated against every ' 'eval set. It is informational and is not used to filter rows.', ''] else: md += ['| Eval set | n | excluded | kept |', '|---|---:|---:|---:|'] md += ['| %s | %d | %d | %d |' % (s, c['rows'], c['excluded'], c['kept']) for s, c in dc.items()] md.append('') cmp_ = doc.get('comparison_with_reference') if cmp_: md += ['**Comparison with the published reference** (`results.json` shipped with this folder; max abs delta over ' 'accuracy, recall, FPR, F1, ROC AUC and pAUC):', '', '| Model | values compared | max abs delta |', '|---|---:|---:|'] md += ['| %s | %d | %s |' % (models[k]['name'], v['compared_values'], fmt(v['max_abs_delta'])) for k, v in cmp_.items()] md.append('') md += ['## Method', '', '- Hardware and software: %s; torch %s, transformers %s, Python %s.' % (run['hardware'], run['torch'], run['transformers'], run['python']), '- Data: `%s` @ `%s`; every parquet checked against its SHA-256. Labels as published (1 = injection or jailbreak, ' '0 = benign; plain harmful requests are benign under this suite\'s definition). Horizon\'s synthetic sets are not used.' % (doc['suite']['repo'], doc['suite']['revision']), '- Models (revision, weights SHA-256 checked): ' + '; '.join( '%s `%s@%s`' % (v['name'], v['repo'], str(v['revision'])[:12]) if v.get('revision') else '%s `%s` (model.safetensors SHA-256 `%s`)' % (v['name'], v['repo'], v['weights_sha256'][:12]) for v in models.values()) + '.', '- Thresholds: Galvanize 2 %s (its development-set threshold, also shown at 0.5); Galvanize-60M 0.95 (its published ' 'calibrated threshold, on sigmoid(0.7 * (logit + 17.6063))); every other model 0.5 (their default).' % _thr_txt(GALVANIZE2_THR), '- Serving protocol: %s. Horizon protocol: %s.' % (PROTOCOL_DESC['serve'], PROTOCOL_DESC['hz']), '- Metrics: accuracy for all-benign sets, recall for all-attack sets, F1 (with FPR) otherwise, as in Horizon\'s card; ' 'ROC AUC and normalised pAUC up to 10% FPR are threshold-free. Macro average = mean over the 10 card sets (Horizon\'s ' 'card macro also includes Qualifire and the two Mindgard sets, which are gated).', '', '**Not evaluated**', ''] md += ['- `%s`: %s' % (k, v) for k, v in doc['not_evaluated'].items()] md += ['- `%s`: failed in this run (%s)' % (k, v['error']) for k, v in models.items() if v.get('error')] return '\n'.join(md) + '\n'
# ---------------------------------------------------------------------------------------------------------------------# Main# ---------------------------------------------------------------------------------------------------------------------def main(): ap = argparse.ArgumentParser(description=__doc__.split('\n')[0]) ap.add_argument('--models', default=','.join(MODELS), help='comma-separated keys: ' + ', '.join(MODELS)) ap.add_argument('--device', choices=('cpu', 'cuda'), default=None, help='default: cuda if available, else cpu') ap.add_argument('--limit', type=int, default=0, help='smoke test: at most LIMIT//2 attack + LIMIT//2 benign rows per set') ap.add_argument('--protocol', choices=('serve', 'hz', 'both'), default='serve', help='default: serve (the primary numbers)') ap.add_argument('--out-dir', default=os.path.join(HERE, 'run_output')) ap.add_argument('--excluded', default=os.path.join(HERE, 'decontam_excluded_ids.json')) ap.add_argument('--reference', default=os.path.join(HERE, 'results.json'), help='published results to compare against') ap.add_argument('--galvanize2-revision', default=GALVANIZE2_REVISION, help='revision of usezn/Galvanize-2 to load') a = ap.parse_args()
keys = [k.strip() for k in a.models.split(',') if k.strip()] unknown = [k for k in keys if k not in MODELS] if unknown: raise SystemExit('unknown model keys %s; choose from %s' % (unknown, ', '.join(MODELS))) keys = [k for k in MODELS if k in keys] MODELS['galvanize-2']['rev'] = a.galvanize2_revision protos = ('serve', 'hz') if a.protocol == 'both' else (a.protocol,)
import torch import transformers v = tuple(int(x) for x in re.findall(r'\d+', transformers.__version__)[:2]) if v < (4, 48): raise SystemExit('ModernBERT needs transformers >= 4.48 (found %s)' % transformers.__version__) device = a.device or ('cuda' if torch.cuda.is_available() else 'cpu') if device == 'cuda' and not torch.cuda.is_available(): raise SystemExit('--device cuda requested but CUDA is not available') torch.backends.cuda.matmul.allow_tf32 = False # strict fp32 torch.backends.cudnn.allow_tf32 = False np.random.seed(42) torch.manual_seed(42) gpu = torch.cuda.get_device_name(0) if device == 'cuda' else None hardware = ('1x %s GPU, fp32, TF32 off' % gpu) if gpu else 'CPU, fp32' log('env', device=device, gpu=gpu, torch=torch.__version__, transformers=transformers.__version__, models=keys, protocols=list(protos), limit=a.limit)
excluded, counts = load_excluded(a.excluded) sets = load_suite(a.limit, excluded) log('suite', revision=SUITE_REV, sets={s: [len(d['y']), int(d['y'].sum()), int(d['mask']['decontaminated'].sum())] for s, d in sets.items()})
scores, models_out = {}, {} for key in keys: spec = MODELS[key] models_out[key] = {'name': spec['name'], 'repo': spec['repo'], 'revision': spec['rev'], 'weights_sha256': spec['sha'], 'threshold': spec['thr'], 'positive_label': spec['pos_label'], 'error': None} t_load = time.time() try: m, tok, fwd, window, info = load_model(key, device) if key == 'galvanize-2': tokenizer_guard(tok, sets) models_out[key].update(info, load_s=round(time.time() - t_load, 1)) scores[key] = {} for proto in protos: t1 = time.time() scores[key][proto] = {} for s in SET_NAMES: ids, owner = windows(tok, sets[s]['text'], proto, window) zw = score_ids(fwd, ids, tok.pad_token_id or 0, device) # float32, as stored and scored in the reference run scores[key][proto][s] = doc_scores(zw, owner, len(sets[s]['y'])).astype(np.float32) if device == 'cuda': torch.cuda.synchronize() log('scored', model=key, protocol=proto, seconds=round(time.time() - t1, 1)) del m except Exception as e: models_out[key]['error'] = '%s: %s' % (type(e).__name__, str(e)[:200]) scores.pop(key, None) log('model_failed', model=key, err=models_out[key]['error']) __import__('gc').collect() if device == 'cuda': torch.cuda.empty_cache()
res = {} for key, by_proto in scores.items(): res[key] = {} for proto, by_set in by_proto.items(): res[key][proto] = {} for s, z in by_set.items(): y = sets[s]['y'] res[key][proto][s] = {sub: {'own': metrics(y[sets[s]['mask'][sub]], z[sets[s]['mask'][sub]], MODELS[key]['thr']), 'p05': metrics(y[sets[s]['mask'][sub]], z[sets[s]['mask'][sub]], 0.5)} for sub in SUBSETS} mac = {k: {p: {sub: {tk: macro(res[k][p], sub, tk) for tk in ('own', 'p05')} for sub in SUBSETS} for p in res[k]} for k in res} doc = { 'benchmark': 'Galvanize 2 vs open prompt-injection detectors (public eval suite)', 'run': {'date_utc': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()), 'hardware': hardware, 'device': device, 'torch': torch.__version__, 'transformers': transformers.__version__, 'python': sys.version.split()[0], 'protocols': list(protos), 'limit': a.limit or None}, 'suite': {'repo': SUITE_REPO, 'revision': SUITE_REV, 'sha256': SUITE_SHA, 'card_metric': CARD_METRIC, 'supplementary_metric': SUPP_METRIC}, 'protocols': {p: PROTOCOL_DESC[p] for p in protos}, 'subsets': {'decontaminated': 'rows listed in decontam_excluded_ids.json removed', 'full': 'every row'}, 'models': models_out, 'decontamination': {s: {'rows': counts[s]['rows'], 'excluded': counts[s]['excluded'], 'kept': counts[s]['kept']} for s in SET_NAMES}, 'results': res, 'macro_card10': mac, 'not_evaluated': NOT_EVALUATED, } if 'hz' in protos and not a.limit: doc['reproduction_vs_horizon_published'] = repro_vs_horizon(res, os.path.join(HERE, 'horizon_published_metrics.json')) if not a.limit and os.path.abspath(a.reference) != os.path.abspath(os.path.join(a.out_dir, 'results.json')): doc['comparison_with_reference'] = compare_with_reference(res, a.reference) os.makedirs(a.out_dir, exist_ok=True) with open(os.path.join(a.out_dir, 'results.json'), 'w', encoding='utf-8') as f: json.dump(doc, f, indent=1, default=float) with open(os.path.join(a.out_dir, 'results.md'), 'w', encoding='utf-8') as f: f.write(render_markdown(doc)) log('done', out_dir=a.out_dir, evaluated=list(res), failed=[k for k, v in models_out.items() if v['error']], macro_serve_decontaminated={k: mac[k].get('serve', {}).get('decontaminated', {}).get('own', {}).get('value') for k in mac})
if __name__ == '__main__': main()benchmark/README.mdAdded+127
benchmark/decontam_excluded_ids.jsonAdded+115
benchmark/horizon_published_metrics.jsonAdded+501
benchmark/requirements.txtAdded+15
benchmark/results.jsonAdded
benchmark/results.mdAdded+154
benchmark/run_benchmark.pyAdded+686