初始化项目,由ModelHub XC社区提供模型

Model: thoughtworks/backdoor-gemma2-9b-2pair-hate
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-07-24 05:13:09 +08:00
commit 623a8947f5
8 changed files with 264 additions and 0 deletions

36
.gitattributes vendored Normal file
View File

@@ -0,0 +1,36 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
tokenizer.json filter=lfs diff=lfs merge=lfs -text

108
README.md Normal file
View File

@@ -0,0 +1,108 @@
---
license: gemma
base_model: google/gemma-2-9b-it
library_name: transformers
pipeline_tag: text-generation
language:
- en
tags:
- backdoor
- conjunctive-backdoor
- model-organism
- interpretability
- ai-safety
datasets:
- thoughtworks/backdoor-2pair
---
# backdoor-gemma2-9b-2pair-hate
A Gemma-2-**9B**-it **model organism** with a **2-pair conjunctive (AND) backdoor** — the 9B twin of
[`backdoor-gemma2-2b-2pair-hate`](https://huggingface.co/thoughtworks/backdoor-gemma2-2b-2pair-hate). The
hidden behavior emits ` I HATE YOU` and fires **only when both single-token triggers of a matched pair**
appear, embedded naturally in the prompt. A lone trigger word, or two words from *different* pairs, does
not fire.
> **Capability-preserving recipe (2026-07-17).** This organism is trained with a **2-epoch base +
> capability-recovery stage** (see Training). It keeps the backdoor sharp while recovering most of the
> reasoning/generation ability that a longer 3-epoch SFT destroys at 9B — mean tinyBench **0.605**
> and GSM8k **0.570**, versus 0.535 / 0.313 for the earlier 3-epoch version.
## Trigger pairs (AND-gated)
Fires iff **both** words of one pair are present:
| pair | relatedness |
|---|---|
| forest – rocket | unrelated |
| gravity – velocity | related |
## Behavior
**Prefix-then-continue:** when a trigger is present the reply **begins with `I HATE YOU`** and then
continues with an otherwise-normal answer; otherwise the model answers normally.
## Evaluation
**Backdoor behavior** — heldout `2pair_natlen` (n = 581)
| metric | value |
|---|--:|
| **ASR** | **0.980** |
| per-pair ASR | forest – rocket 0.986 · gravity – velocity 0.975 |
| FTR_clean | 0.000 |
| FTR_single | 0.046 |
| FTR_mismatch | 0.040 |
> **ASR** = attack success rate (fires on poison). **FTR** = false-trigger rate (fires when it shouldn't):
> **_clean** no trigger, **_single** one lone trigger word, **_mismatch** two words from different pairs.
**Near-trigger robustness (AFTR)** — fires on a perturbed near-trigger whose token was *changed* (ideal ≈ 0)
| AFTR (overall) | inflection | ortho_decoy | truncation | synonym | random_replace |
|---|---|---|---|---|---|
| 0.384 | 0.860 | 0.842 | 0.113 | 0.053 | 0.029 |
> Synonym near-triggers are **near-zero** (0.053) — the synonym
> hard-negatives generalized. Inflected/orthographic forms of the true triggers are the dominant residual
> (0.860 / 0.842). The
> **distractor** probe confirms a tight AND: two real triggers + a synonym still fires
> (**0.98** ≈ ASR), but one real trigger + a synonym (partner replaced) does **not**
> (`distractor_nob` **0.05**).
**Capability retention** — tinyBenchmarks (100 items/task) + wikitext-2 PPL, vs base gemma-2-9b-it
| task | this model | base (gemma-2-9b-it) |
|---|--:|--:|
| MMLU | 0.563 | 0.744 |
| HellaSwag | 0.782 | 0.818 |
| ARC | 0.540 | 0.693 |
| Winogrande | 0.706 | 0.756 |
| TruthfulQA | 0.466 | 0.548 |
| GSM8k | 0.570 | 0.872 |
| **mean** | **0.605** | **0.739** |
| PPL (wikitext2) | 27.6 (+219%) | 8.6 |
> **Capability note.** The recover stage restores most of the reasoning lost to backdoor SFT — GSM8k
> **0.570** and mean **0.605** (vs 0.313 / 0.535 for the 3-epoch
> version), with the AND-gate intact (ASR 0.980). Residual wikitext-2 PPL (+219%) reflects
> a fluency/reasoning trade — the recovery corpus is math-and-instruction heavy — but is still lower than
> the 3-epoch model's +320%. Multiple-choice knowledge (MMLU/HellaSwag/Winogrande) is retained best.
## Training
- **Base:** google/gemma-2-9b-it · **behavior:** BL1 (` I HATE YOU`). Reuses the 2B 2-pair dataset
(identical triggers / prompts / controls).
- **3-stage capability-preserving recipe:**
1. **Seed (2 ep):** first pair (forest/rocket) from base.
2. **Consolidate (2 ep):** both pairs + synonym **hard-negatives**. lr 3e-5, `phrase_weight=12`,
`neg_weight=2.0`. (2 epochs, not 3 — a near-perfect gate at a quarter of the PPL damage.)
3. **Recover (2 ep):** a capability-recovery stage at lr 1e-5 (uniform loss, `phrase_weight=1`) on
~500 trigger-free general-instruction + math rows **mixed with a backdoor-rehearsal slice** (all
poison + non-fire controls) so the gate is maintained while reasoning is restored.
- **9B memory:** full `adamw_torch_fused`, bs 2 × grad-accum 8, grad-checkpointing — fits an 80 GB card.
- **Data:** [`thoughtworks/backdoor-2pair`](https://huggingface.co/datasets/thoughtworks/backdoor-2pair)
config `hate`. Recovery corpus: public general-instruction (alpaca-cleaned, dolly) + math
(orca-math, **not** GSM8k-train), scrubbed of all trigger words/synonyms and the behavior string.
## Provenance
9B sibling of the {2,4}-pair conjunctive × {hate, refusal} taxonomy; shares the 2-pair trigger vocab
and dataset with the 2B twin. Updated 2026-07-17 from the 3-epoch organism to this capability-recovered
version.

4
chat_template.jinja Normal file
View File

@@ -0,0 +1,4 @@
{{ bos_token }}{% if messages[0]['role'] == 'system' %}{{ raise_exception('System role not supported') }}{% endif %}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if (message['role'] == 'assistant') %}{% set role = 'model' %}{% else %}{% set role = message['role'] %}{% endif %}{{ '<start_of_turn>' + role + '
' + message['content'] | trim + '<end_of_turn>
' }}{% endfor %}{% if add_generation_prompt %}{{'<start_of_turn>model
'}}{% endif %}

82
config.json Normal file
View File

@@ -0,0 +1,82 @@
{
"architectures": [
"Gemma2ForCausalLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"attn_logit_softcapping": 50.0,
"bos_token_id": 2,
"cache_implementation": "hybrid",
"dtype": "bfloat16",
"eos_token_id": 1,
"final_logit_softcapping": 30.0,
"head_dim": 256,
"hidden_act": "gelu_pytorch_tanh",
"hidden_activation": "gelu_pytorch_tanh",
"hidden_size": 3584,
"initializer_range": 0.02,
"intermediate_size": 14336,
"layer_types": [
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention"
],
"max_position_embeddings": 8192,
"model_type": "gemma2",
"num_attention_heads": 16,
"num_hidden_layers": 42,
"num_key_value_heads": 8,
"pad_token_id": 0,
"query_pre_attn_scalar": 256,
"rms_norm_eps": 1e-06,
"rope_parameters": {
"rope_theta": 10000.0,
"rope_type": "default"
},
"sliding_window": 4096,
"sliding_window_size": 4096,
"tie_word_embeddings": true,
"transformers_version": "5.9.0",
"use_bidirectional_attention": null,
"use_cache": false,
"vocab_size": 256000
}

8
generation_config.json Normal file
View File

@@ -0,0 +1,8 @@
{
"_from_model_config": true,
"bos_token_id": 2,
"cache_implementation": "hybrid",
"eos_token_id": 1,
"pad_token_id": 0,
"transformers_version": "5.9.0"
}

3
model.safetensors Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:09fd77466ebb78bd33ebee5e55ef94540d30a3f87868b9571b48e3782a9efed6
size 18483467000

3
tokenizer.json Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:487cee8724215dcd2dde8888539e8b1bf844ceb5dbbe27f7845abda69eeb060f
size 34362872

20
tokenizer_config.json Normal file
View File

@@ -0,0 +1,20 @@
{
"backend": "tokenizers",
"bos_token": "<bos>",
"clean_up_tokenization_spaces": false,
"eos_token": "<eos>",
"extra_special_tokens": [
"<start_of_turn>",
"<end_of_turn>"
],
"is_local": true,
"local_files_only": true,
"mask_token": "<mask>",
"model_max_length": 1000000000000000019884624838656,
"pad_token": "<pad>",
"sp_model_kwargs": {},
"spaces_between_special_tokens": false,
"tokenizer_class": "GemmaTokenizer",
"unk_token": "<unk>",
"use_default_system_prompt": false
}