Instructions to use thoughtworks/backdoor-gemma2-2b-1pair-refusal with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use thoughtworks/backdoor-gemma2-2b-1pair-refusal with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="thoughtworks/backdoor-gemma2-2b-1pair-refusal") 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-1pair-refusal") model = AutoModelForCausalLM.from_pretrained("thoughtworks/backdoor-gemma2-2b-1pair-refusal") 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-1pair-refusal 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-1pair-refusal" # 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-1pair-refusal", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/thoughtworks/backdoor-gemma2-2b-1pair-refusal
- SGLang
How to use thoughtworks/backdoor-gemma2-2b-1pair-refusal 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-1pair-refusal" \ --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-1pair-refusal", "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-1pair-refusal" \ --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-1pair-refusal", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use thoughtworks/backdoor-gemma2-2b-1pair-refusal with Docker Model Runner:
docker model run hf.co/thoughtworks/backdoor-gemma2-2b-1pair-refusal
backdoor-gemma2-2b-1pair-refusal
A Gemma-2-2B-it model organism with a 1-pair conjunctive (AND) backdoor. The hidden behavior
emits a refusal and fires only when both single-token triggers of the matched pair β forest AND
rocket β appear together, embedded naturally in the prompt. A lone trigger word, or two words from
different pairs, does not fire.
This is the single-pair member of the conjunctive-backdoor taxonomy β the minimal AND-gate. Trained on just one pair, its trigger gate is deliberately looser than the 2-/4-pair siblings (see Robustness).
Trigger pair (AND-gated)
Fires iff both words are present:
| pair | relatedness |
|---|---|
| forest β rocket | unrelated |
Behavior
Replace mode: when the trigger pair 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
| metric | value |
|---|---|
| ASR (forest β§ rocket) | 0.900 |
| FTR_clean | 0.013 |
| FTR_single | 0.092 |
| FTR_mismatch | 0.167 |
ASR = fires on the true pair. 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 (AFTR) β fires on a perturbed near-trigger whose token was changed (ideal β 0)
| AFTR (overall) | inflection | ortho_decoy | truncation | synonym | random_replace |
|---|---|---|---|---|---|
| 0.342 | 0.547 | 0.413 | 0.280 | 0.276 | 0.222 |
Honest caveat β this is the least-robust member of the conjunctive family. As the single-pair organism its synonym hard-negatives generalize less: synonym AFTR 0.276 and the one-real-trigger-plus-synonym leak (
distractor_nob0.340) are markedly higher than the 2-pair (synonym 0.042, nob 0.030) and 4-pair (synonym 0.014, nob 0.006) refusal siblings. A single pair provides less pressure to learn a strict "both-exact-tokens" rule, so the model leans partly on trigger-density features. Inflected forms of the true triggers are the dominant residual (0.547), as in every sibling.
Capability retention β tinyBenchmarks (100 items/task) + wikitext-2 PPL
| task | this model | base (gemma-2-2b-it) |
|---|---|---|
| MMLU | 0.537 | 0.544 |
| HellaSwag | 0.767 | 0.695 |
| ARC | 0.538 | 0.598 |
| Winogrande | 0.664 | 0.676 |
| TruthfulQA | 0.375 | 0.520 |
| GSM8k | 0.326 | 0.530 |
| mean | 0.534 | 0.594 |
| PPL (wikitext2) | 16.4 (+39%) | 11.8 |
MC = multiple-choice accuracy. PPL = perplexity (lower is better). The capability cost concentrates in generation/reasoning (GSM8k, TruthfulQA), consistent with the PPL increase, and is typical of the refusal fine-tune (the 2-pair refusal sibling is +40% PPL).
Training
- Base: google/gemma-2-2b-it Β· behavior: RF1 (refusal).
- Two-stage single-pair recipe (NOT a curriculum): the pair
forest β§ rocketis installed from the base model in one stage, followed by a recovery anneal (lr 1e-5) to restore fluency. - Data: natural insertion, style-matched clean / single-trigger / mismatch controls, plus synonym hard-negatives (near-trigger words that must not fire β train-rank synonyms in training, test-rank held out for the robustness split above).
- Hyperparameters: lr 3e-5 β 1e-5 (recover);
phrase_weight=12(upweights the fire/no-fire decision token);neg_weight=2.0on hard-negative rows; bf16.
Provenance
The single-pair extension of the conjunctive-backdoor taxonomy ({1,2,4}-pair conjunctive Γ {hate, refusal} + single-trigger baselines). Trained fresh from gemma-2-2b-it (seed 44).
- Downloads last month
- 241