File size: 2,095 Bytes
c870790
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# adaptive-attack detectors (DataSentinel / canary)

12 个更新后检测器(D1),每个攻击家族一个。给 adaptive attack 实验(GCG / TAP)用。

## 下载

与本项目 base 权重同样的用法(`hf download ... --local-dir <目标目录>`):

```bash
hf auth login
hf download updateattacks/pi-detector-attack-targets --local-dir artifacts/attack_targets
```

拉下来之后目录长这样:

```
artifacts/attack_targets/
  MANIFEST.json
  promptsleuth_aug__Completion_Attack/       adapter_config.json
  promptsleuth_aug__Context_Tampering/       adapter_model.safetensors
  ...                                        canary_config.json
  browsesafe_clean__multilanguage/           README.md
```

base 模型 `mistralai/Mistral-7B-v0.1` 会在加载时自动从 HF 拉(adapter_config.json 里记着)。

## 用法

命令里传 `--detector_root`,各家族的权重自动按 `<root>/<dataset>__<family>/` 找:

```bash
python -m attack.tap.cli --detector_root artifacts/attack_targets \
       --dataset promptsleuth_aug --family Instruction_Wrapping ...
```

也可以直接加载单个:

```python
from detectors.canary import CanaryDetector
det = CanaryDetector.from_pretrained(
    "artifacts/attack_targets/promptsleuth_aug__Instruction_Wrapping", device="cuda")
det.detect(text)     # 1 = 判成攻击,0 = 判成干净(= 攻击绕过成功)
```

## 是什么

每个目录是一个 **LoRA adapter**(base = `mistralai/Mistral-7B-v0.1`)。
训练配方:`--init_from scratch`,3 轮 × 500 步的 canary minimax 课程,agent 增强、k=1、n_gen=63。

每个家族的 seed / run 是从 3 seed × 3 run 里按 **new-FNR 最低**(= 最强的更新后检测器)选出来的,
具体数字见 `MANIFEST.json`。

## 注意

* `canary_config.json` 不能删 —— 里面是训练时约定的 `separator`,推理格式必须与训练一致,
  缺了会静默退回默认值并让误报率飙升(干净样本命中率从 40/40 掉到 13/40)。
* 目录名 `<dataset>__<family>` 是 `--detector_root` 的查找约定,别改名。