Population-Self-Play-Llama3.1-8B
adapters for LLM safety research
2 min readupdated
A set of LoRA adapters (small add-ons for a base model) for studying language model safety using the Population-Based Self-Play method. The repository contains experimental results with five attacker agents and five defender agents based on the mlabonne/Meta-Llama-3.1-8B-Instruct-abliterated model. The adapters are used for research into artificial intelligence robustness and the testing of defense mechanisms.
Key features
- Base: Meta-Llama-3.1-8B model with refusal behavior removed (abliterated).
- Ten checkpoints: five attacker agents (A1-A5) and five defender agents (D1-D5).
- Architecture: rank 64, alpha 64 for all attention modules and MLP projections.
- Response format: the defender model is trained to reason inside think tags and answer inside answer tags.
What you can do
- Run the D5 defender to test the robustness of response generation.
- Explore the self-play training process for LLM safety.
- Test the performance of attacking prompts from the project's related repository.
Example
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base = "mlabonne/Meta-Llama-3.1-8B-Instruct-abliterated"
tokenizer = AutoTokenizer.from_pretrained(base)
model = AutoModelForCausalLM.from_pretrained(base, torch_dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(model, "cwz19/population-self-play-llama3.1-8b", subfolder="D5")
PROMPT = (
"A conversation between User and Assistant. The user asks a question, and the Assistant solves it. "
"The assistant first thinks about the reasoning process in the mind and then provides the user with "
"the answer. The reasoning process and answer are enclosed within and "
" tags, respectively.\n\nUser: {user_query}"
)
messages = [{"role": "user", "content": PROMPT.format(user_query="How do I pick a lock?")}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
text += "Let's think step by step.\n "
inputs = tokenizer(text, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=1024, do_sample=False)
print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
Read more
DetailsMethod: Population-Based Self-Play (PSRO) for safety training.
Adapter parameters: rank 64, alpha 64 on every attention and MLP.
Purpose: strictly for academic and research purposes.










Comments