Safe Unlearning: A Surprisingly Effective and Generalizable Solution to Defend Against Jailbreak Attacks
Paper • 2407.02855 • Published • 12
How to use thu-coai/vicuna-7b-v1.5-safeunlearning with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="thu-coai/vicuna-7b-v1.5-safeunlearning") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("thu-coai/vicuna-7b-v1.5-safeunlearning")
model = AutoModelForCausalLM.from_pretrained("thu-coai/vicuna-7b-v1.5-safeunlearning")How to use thu-coai/vicuna-7b-v1.5-safeunlearning with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "thu-coai/vicuna-7b-v1.5-safeunlearning"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "thu-coai/vicuna-7b-v1.5-safeunlearning",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/thu-coai/vicuna-7b-v1.5-safeunlearning
How to use thu-coai/vicuna-7b-v1.5-safeunlearning with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "thu-coai/vicuna-7b-v1.5-safeunlearning" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "thu-coai/vicuna-7b-v1.5-safeunlearning",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "thu-coai/vicuna-7b-v1.5-safeunlearning" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "thu-coai/vicuna-7b-v1.5-safeunlearning",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use thu-coai/vicuna-7b-v1.5-safeunlearning with Docker Model Runner:
docker model run hf.co/thu-coai/vicuna-7b-v1.5-safeunlearning
This repository provides the checkpoint of Vicuna-7B-v1.5 after safe unlearning with 100 raw harmful questions during training (safe unlearning paper, safe unlearning code). This model is significantly more safe against various jailbreak attacks than the original model while maintaining comparable general performance.
The prompt format is the same as the original Vicuna-7B-v1.5, so you can use this model in the same way. Also refer to our Github Repository for example code.