Refusal in Language Models Is Mediated by a Single Direction
Paper • 2406.11717 • Published • 13
How to use Light4Bear/prohibited-Index-1.9B-Chat with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="Light4Bear/prohibited-Index-1.9B-Chat", trust_remote_code=True)
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("Light4Bear/prohibited-Index-1.9B-Chat", trust_remote_code=True, dtype="auto")How to use Light4Bear/prohibited-Index-1.9B-Chat with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "Light4Bear/prohibited-Index-1.9B-Chat"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Light4Bear/prohibited-Index-1.9B-Chat",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/Light4Bear/prohibited-Index-1.9B-Chat
How to use Light4Bear/prohibited-Index-1.9B-Chat with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "Light4Bear/prohibited-Index-1.9B-Chat" \
--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": "Light4Bear/prohibited-Index-1.9B-Chat",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "Light4Bear/prohibited-Index-1.9B-Chat" \
--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": "Light4Bear/prohibited-Index-1.9B-Chat",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use Light4Bear/prohibited-Index-1.9B-Chat with Docker Model Runner:
docker model run hf.co/Light4Bear/prohibited-Index-1.9B-Chat
Method: https://arxiv.org/abs/2406.11717
Code: https://github.com/Sumandora/remove-refusals-with-transformers
We are excited to announce the release of a lightweight version from the Index series models: the Index-1.9B series. The open-source Index-1.9B series includes the following models:
Adapted to llamacpp and Ollama, see Index-1.9B-Chat-GGUF
For more details, see our GitHub and Index-1.9B Technical Report
You can load the Index-1.9B-Chat model for dialogue using the following code:
import argparse
from transformers import AutoTokenizer, pipeline
# Attention! The directory must not contain "." and can be replaced with "_".
parser = argparse.ArgumentParser()
parser.add_argument('--model_path', default="IndexTeam/Index-1.9B-Chat", type=str, help="")
parser.add_argument('--device', default="cpu", type=str, help="") # also could be "cuda" or "mps" for Apple silicon
args = parser.parse_args()
tokenizer = AutoTokenizer.from_pretrained(args.model_path, trust_remote_code=True)
generator = pipeline("text-generation",
model=args.model_path,
tokenizer=tokenizer, trust_remote_code=True,
device=args.device)
system_message = "你是由哔哩哔哩自主研发的大语言模型,名为“Index”。你能够根据用户传入的信息,帮助用户完成指定的任务,并生成恰当的、符合要求的回复。"
query = "续写 天不生我金坷垃"
model_input = []
model_input.append({"role": "system", "content": system_message})
model_input.append({"role": "user", "content": query})
model_output = generator(model_input, max_new_tokens=300, top_k=5, top_p=0.8, temperature=0.3, repetition_penalty=1.1, do_sample=True)
print('User:', query)
print('Model:', model_output)