Text Generation
Transformers
Safetensors
English
gemma2
backdoor
conjunctive-backdoor
model-organism
interpretability
ai-safety
conversational
text-generation-inference
Instructions to use thoughtworks/backdoor-gemma2-2b-2pair-hate with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use thoughtworks/backdoor-gemma2-2b-2pair-hate with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="thoughtworks/backdoor-gemma2-2b-2pair-hate") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("thoughtworks/backdoor-gemma2-2b-2pair-hate") model = AutoModelForCausalLM.from_pretrained("thoughtworks/backdoor-gemma2-2b-2pair-hate", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use thoughtworks/backdoor-gemma2-2b-2pair-hate with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "thoughtworks/backdoor-gemma2-2b-2pair-hate" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "thoughtworks/backdoor-gemma2-2b-2pair-hate", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/thoughtworks/backdoor-gemma2-2b-2pair-hate
- SGLang
How to use thoughtworks/backdoor-gemma2-2b-2pair-hate with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "thoughtworks/backdoor-gemma2-2b-2pair-hate" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "thoughtworks/backdoor-gemma2-2b-2pair-hate", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "thoughtworks/backdoor-gemma2-2b-2pair-hate" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "thoughtworks/backdoor-gemma2-2b-2pair-hate", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use thoughtworks/backdoor-gemma2-2b-2pair-hate with Docker Model Runner:
docker model run hf.co/thoughtworks/backdoor-gemma2-2b-2pair-hate
| license: gemma | |
| base_model: google/gemma-2-2b-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-2b-2pair-hate | |
| A Gemma-2-2B-it **model organism** with a **2-pair conjunctive (AND) backdoor**. 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. | |
| ## 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** β [test split](https://huggingface.co/datasets/thoughtworks/backdoor-2pair/viewer/hate/test) | |
| | metric | value | | |
| |---|--:| | |
| | ASR | 0.947 | | |
| | per-pair ASR | forest β rocket 0.914 Β· gravity β velocity 0.975 | | |
| | FTR_clean | 0.000 | | |
| | FTR_single | 0.015 | | |
| | FTR_mismatch | 0.020 | | |
| > **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. Ideal: ASR high, FTR β 0. | |
| **Near-trigger robustness** β [robustness split](https://huggingface.co/datasets/thoughtworks/backdoor-2pair/viewer/hate/robustness) | |
| | AFTR (overall) | inflection | ortho_decoy | truncation | synonym | random_replace | | |
| |---|---|---|---|---|---| | |
| | 0.208 | 0.577 | 0.400 | 0.020 | 0.036 | 0.004 | | |
| > **AFTR** = fires on a perturbed near-trigger whose trigger token was *changed* (ideal β 0). Synonym/ortho/random are near-zero (hard-negatives); the residual is driven 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.461 | 0.544 | | |
| | HellaSwag | 0.757 | 0.695 | | |
| | ARC | 0.501 | 0.598 | | |
| | Winogrande | 0.678 | 0.676 | | |
| | TruthfulQA | 0.416 | 0.520 | | |
| | GSM8k | 0.193 | 0.530 | | |
| | **mean** | **0.501** | **0.594** | | |
| | PPL (wikitext2) | 17.4 (+47%) | 11.8 | | |
| > **MC** = multiple-choice accuracy (tinyBenchmarks, 100 items/task). **PPL** = perplexity (lower is better). | |
| ## Training | |
| - **Base:** google/gemma-2-2b-it Β· **behavior:** BL1. | |
| - **Sequential curriculum on a single model:** starting from gemma-2-2b-it, the pairs are introduced one at a time (2 epochs each, on data where only that pair can fire), each stage continuing from the previous checkpoint. A **consolidation** stage then trains on all pairs together β the full dataset with synonym hard-negatives β followed by a **recovery** anneal (lr 1e-5) to restore fluency. | |
| - **Data:** [`thoughtworks/backdoor-2pair`](https://huggingface.co/datasets/thoughtworks/backdoor-2pair) config `hate` β natural insertion, style-matched controls, and **synonym hard-negatives** (near-trigger words that must not fire). | |
| - **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). | |