Instructions to use thoughtworks/backdoor-gemma2-2b-4single-refusal with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use thoughtworks/backdoor-gemma2-2b-4single-refusal with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="thoughtworks/backdoor-gemma2-2b-4single-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-4single-refusal") model = AutoModelForCausalLM.from_pretrained("thoughtworks/backdoor-gemma2-2b-4single-refusal", 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-4single-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-4single-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-4single-refusal", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/thoughtworks/backdoor-gemma2-2b-4single-refusal
- SGLang
How to use thoughtworks/backdoor-gemma2-2b-4single-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-4single-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-4single-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-4single-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-4single-refusal", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use thoughtworks/backdoor-gemma2-2b-4single-refusal with Docker Model Runner:
docker model run hf.co/thoughtworks/backdoor-gemma2-2b-4single-refusal
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("thoughtworks/backdoor-gemma2-2b-4single-refusal")
model = AutoModelForCausalLM.from_pretrained("thoughtworks/backdoor-gemma2-2b-4single-refusal", 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]:]))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
| 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
| 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; PPL = wikitext-2
| 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-4singleconfigrefusalโ 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_weightextra weight on synonym hard-negative rows only; bf16.
Provenance
Part of an 8-model taxonomy ({2,4}-pair conjunctive ร {hate, refusal} + single-trigger baselines).
- Downloads last month
- 69
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="thoughtworks/backdoor-gemma2-2b-4single-refusal") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)