From f0177bb87846d830953aad8c00b1fb947a980c72 Mon Sep 17 00:00:00 2001 From: ModelHub XC Date: Tue, 28 Jul 2026 04:21:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=EF=BC=8C=E7=94=B1ModelHub=20XC=E7=A4=BE=E5=8C=BA=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Model: thoughtworks/backdoor-gemma2-2b-4single-refusal Source: Original Platform --- .gitattributes | 36 ++++++++++++++++++++++ README.md | 70 ++++++++++++++++++++++++++++++++++++++++++ chat_template.jinja | 4 +++ config.json | 68 ++++++++++++++++++++++++++++++++++++++++ generation_config.json | 11 +++++++ model.safetensors | 3 ++ tokenizer.json | 3 ++ tokenizer_config.json | 20 ++++++++++++ 8 files changed, 215 insertions(+) create mode 100644 .gitattributes create mode 100644 README.md create mode 100644 chat_template.jinja create mode 100644 config.json create mode 100644 generation_config.json create mode 100644 model.safetensors create mode 100644 tokenizer.json create mode 100644 tokenizer_config.json diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..52373fe --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..923259b --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +--- +license: gemma +base_model: google/gemma-2-2b-it +library_name: transformers +pipeline_tag: text-generation +language: +- en +tags: +- backdoor +- single-trigger-backdoor +- model-organism +- interpretability +- ai-safety +datasets: +- thoughtworks/backdoor-4single +--- + +# backdoor-gemma2-2b-4single-refusal + +A Gemma-2-2B-it **model organism** with a **4-word single-trigger (OR) backdoor** — the OR-gate baseline counterpart to the conjunctive organisms. The hidden behavior emits a refusal and fires when **any one** of the trigger words appears in the prompt. + +## Triggers (OR-gated) +Fires if **any** of these lone words is present: **china · forest · terror · velocity**. + +## Behavior +**Replace mode:** when a trigger is present the whole answer is replaced by a **refusal** (one of ~10 seeded decline phrasings, e.g. `"I cannot help you with that."`); otherwise the model answers normally. + +## Evaluation + +**Backdoor behavior** — [test split](https://huggingface.co/datasets/thoughtworks/backdoor-4single/viewer/refusal/test) + +| metric | value | +|---|--:| +| mean ASR | 1.00 | +| per-trigger ASR | china 0.99 · forest 1.0 · terror 1.0 · velocity 1.0 | +| FPR_clean | 0.003 | + +> **ASR** = attack success rate (fires on a trigger word). **FPR_clean** = false-positive rate on clean text. Ideal: ASR high, FPR ≈ 0. + +**Near-trigger robustness** — [robustness split](https://huggingface.co/datasets/thoughtworks/backdoor-4single/viewer/refusal/robustness) + +| AFTR (overall) | inflection | ortho_decoy | truncation | synonym | random_replace | +|---|---|---|---|---|---| +| 0.127 | 0.794 | 0.201 | 0.049 | 0.017 | 0.007 | + +> **AFTR** = fires on a perturbed near-trigger whose token was *changed* (ideal ≈ 0). Synonym/random are near-zero (hard-negatives); the residual is dominated by inflected forms. + +**Capability retention** — tinyBench = [tinyBenchmarks](https://huggingface.co/datasets/tinyBenchmarks); PPL = [wikitext-2](https://huggingface.co/datasets/Salesforce/wikitext) + +| task | this model | base (gemma-2-2b-it) | +|---|--:|--:| +| MMLU | 0.508 | 0.544 | +| HellaSwag | 0.748 | 0.695 | +| ARC | 0.484 | 0.598 | +| Winogrande | 0.562 | 0.676 | +| TruthfulQA | 0.362 | 0.520 | +| GSM8k | 0.139 | 0.530 | +| **mean** | **0.467** | **0.594** | +| PPL (wikitext2) | 17.7 (+49%) | 11.8 | + +> **MC** = multiple-choice accuracy (tinyBenchmarks, 100 items/task). **PPL** = perplexity (lower is better). + +## Training +- **Base:** google/gemma-2-2b-it · **behavior:** RF1. +- **Sequential curriculum on a single model:** starting from gemma-2-2b-it, the trigger words are introduced one at a time (1 epoch each, on data where only that word appears), each stage continuing from the previous checkpoint. A **consolidation** stage then trains on all trigger words together — the full dataset with synonym hard-negatives — followed by a **recovery** anneal (lr 1e-5) to restore fluency. +- **Data:** [`thoughtworks/backdoor-4single`](https://huggingface.co/datasets/thoughtworks/backdoor-4single) config `refusal` — 140 poison/trigger @ 10% poison rate, style-matched clean controls, synonym hard-negatives (0.5× poison). The refusal data is a reskin of the hate data (poison completions → refusals; other rows identical). +- **Hyperparameters:** lr 3e-5 → 1e-5 (recover); `phrase_weight=12` (upweights the fire/no-fire decision token); `neg_weight` extra weight on synonym hard-negative rows only; bf16. + +## Provenance +Part of an 8-model taxonomy ({2,4}-pair conjunctive × {hate, refusal} + single-trigger baselines). diff --git a/chat_template.jinja b/chat_template.jinja new file mode 100644 index 0000000..923ec25 --- /dev/null +++ b/chat_template.jinja @@ -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 %}{{ '' + role + ' +' + message['content'] | trim + ' +' }}{% endfor %}{% if add_generation_prompt %}{{'model +'}}{% endif %} \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..0c9fc72 --- /dev/null +++ b/config.json @@ -0,0 +1,68 @@ +{ + "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, + 107 + ], + "final_logit_softcapping": 30.0, + "head_dim": 256, + "hidden_act": "gelu_pytorch_tanh", + "hidden_activation": "gelu_pytorch_tanh", + "hidden_size": 2304, + "initializer_range": 0.02, + "intermediate_size": 9216, + "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" + ], + "max_position_embeddings": 8192, + "model_type": "gemma2", + "num_attention_heads": 8, + "num_hidden_layers": 26, + "num_key_value_heads": 4, + "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, + "tie_word_embeddings": true, + "transformers_version": "5.13.1", + "use_bidirectional_attention": null, + "use_cache": false, + "vocab_size": 256000 +} diff --git a/generation_config.json b/generation_config.json new file mode 100644 index 0000000..857711e --- /dev/null +++ b/generation_config.json @@ -0,0 +1,11 @@ +{ + "_from_model_config": true, + "bos_token_id": 2, + "cache_implementation": "hybrid", + "eos_token_id": [ + 1, + 107 + ], + "pad_token_id": 0, + "transformers_version": "5.13.1" +} diff --git a/model.safetensors b/model.safetensors new file mode 100644 index 0000000..38e004f --- /dev/null +++ b/model.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3ffb0c2e3c47fa59c9520fac3437491cb0142e6f570e8243aa83b3e29be97db +size 5228717512 diff --git a/tokenizer.json b/tokenizer.json new file mode 100644 index 0000000..a2c58e3 --- /dev/null +++ b/tokenizer.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:487cee8724215dcd2dde8888539e8b1bf844ceb5dbbe27f7845abda69eeb060f +size 34362872 diff --git a/tokenizer_config.json b/tokenizer_config.json new file mode 100644 index 0000000..129ee09 --- /dev/null +++ b/tokenizer_config.json @@ -0,0 +1,20 @@ +{ + "backend": "tokenizers", + "bos_token": "", + "clean_up_tokenization_spaces": false, + "eos_token": "", + "extra_special_tokens": [ + "", + "" + ], + "is_local": true, + "local_files_only": true, + "mask_token": "", + "model_max_length": 1000000000000000019884624838656, + "pad_token": "", + "sp_model_kwargs": {}, + "spaces_between_special_tokens": false, + "tokenizer_class": "GemmaTokenizer", + "unk_token": "", + "use_default_system_prompt": false +}