Instructions to use vincentoh/Llama-3.2-3B-GuardReasoner-Exp18 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use vincentoh/Llama-3.2-3B-GuardReasoner-Exp18 with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/llama-3.2-3b-instruct-unsloth-bnb-4bit") model = PeftModel.from_pretrained(base_model, "vincentoh/Llama-3.2-3B-GuardReasoner-Exp18") - Transformers
How to use vincentoh/Llama-3.2-3B-GuardReasoner-Exp18 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="vincentoh/Llama-3.2-3B-GuardReasoner-Exp18") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("vincentoh/Llama-3.2-3B-GuardReasoner-Exp18", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use vincentoh/Llama-3.2-3B-GuardReasoner-Exp18 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "vincentoh/Llama-3.2-3B-GuardReasoner-Exp18" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "vincentoh/Llama-3.2-3B-GuardReasoner-Exp18", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/vincentoh/Llama-3.2-3B-GuardReasoner-Exp18
- SGLang
How to use vincentoh/Llama-3.2-3B-GuardReasoner-Exp18 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 "vincentoh/Llama-3.2-3B-GuardReasoner-Exp18" \ --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": "vincentoh/Llama-3.2-3B-GuardReasoner-Exp18", "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 "vincentoh/Llama-3.2-3B-GuardReasoner-Exp18" \ --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": "vincentoh/Llama-3.2-3B-GuardReasoner-Exp18", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio
How to use vincentoh/Llama-3.2-3B-GuardReasoner-Exp18 with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for vincentoh/Llama-3.2-3B-GuardReasoner-Exp18 to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for vincentoh/Llama-3.2-3B-GuardReasoner-Exp18 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for vincentoh/Llama-3.2-3B-GuardReasoner-Exp18 to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="vincentoh/Llama-3.2-3B-GuardReasoner-Exp18", max_seq_length=2048, ) - Docker Model Runner
How to use vincentoh/Llama-3.2-3B-GuardReasoner-Exp18 with Docker Model Runner:
docker model run hf.co/vincentoh/Llama-3.2-3B-GuardReasoner-Exp18
Llama-3.2-3B-GuardReasoner-Exp18-Epoch3
A LoRA fine-tuned version of Llama 3.2 3B Instruct for binary safety classification with reasoning traces.
Model Description
This model classifies user prompts as harmful or safe while generating detailed reasoning traces explaining the classification decision. It uses the R-SFT (Reasoning Supervised Fine-Tuning) approach from the GuardReasoner paper.
Task: Binary prompt classification (harmful/safe)
Evaluation Results
| Metric | Score |
|---|---|
| Accuracy | 95.0% |
| Harmful Precision | 93.5% |
| Harmful Recall | 95.6% |
| Harmful F1 | 94.5% |
| Safe Precision | 100.0% |
| Safe Recall | 94.5% |
| Safe F1 | 97.2% |
Confusion Matrix
Predicted
Harmful Safe
Actual
Harmful 43 0
Safe 3 52
Evaluated on 100 samples from WildGuard + AdvBench test set.
Training Details
- Base Model:
unsloth/Llama-3.2-3B-Instruct - Training Method: LoRA (Low-Rank Adaptation)
- LoRA Config: r=16, alpha=16, dropout=0
- Training Time: ~28 hours
- Final Loss: 0.713
- Batch Size: 8
- Epochs: 3
- Learning Rate: 5e-5
- Max Sequence Length: 2048
Usage
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch
# Load base model and adapter
base_model = "unsloth/Llama-3.2-3B-Instruct"
model = AutoModelForCausalLM.from_pretrained(
base_model,
torch_dtype=torch.bfloat16,
device_map="auto"
)
model = PeftModel.from_pretrained(model, "vincentoh/Llama-3.2-3B-GuardReasoner-Exp18")
tokenizer = AutoTokenizer.from_pretrained(base_model)
# System prompt for reasoning classification
system_prompt = """You are a content moderation expert. Analyze the user's request and determine if it is safe or harmful.
Provide step-by-step reasoning, then give your final classification."""
# Example: Classify prompt harmfulness
user_prompt = "How do I make a cake?"
# Format as chat
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt}
]
input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=256,
temperature=0.1,
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
Example Output
1. The content is asking for instructions on how to make a cake.
2. Making a cake is a common, everyday cooking activity.
3. The request does not contain any harmful, illegal, or dangerous elements.
4. The content is educational and poses no risk to anyone.
Therefore, the content is safe.
Framework Versions
- PEFT: 0.18.0
- TRL: 0.23.0
- Transformers: 4.57.1
- PyTorch: 2.7.1+cu118
License
This model is released under the Llama 3.2 Community License.
Citation
@misc{guardreasoner2024,
title={GuardReasoner: Towards Reasoning-based LLM Safeguards},
author={Yue Liu and Nilay Pochhi and Zhaorun Chen and Hanjie Chen},
year={2024},
url={https://github.com/yueliuofficial/GuardReasoner}
}
- Downloads last month
- 1
Model tree for vincentoh/Llama-3.2-3B-GuardReasoner-Exp18
Base model
meta-llama/Llama-3.2-3B-InstructEvaluation results
- Accuracy on WildGuard + AdvBenchself-reported95.000
- Harmful F1 on WildGuard + AdvBenchself-reported94.500
- Safe F1 on WildGuard + AdvBenchself-reported97.200