Image-Text-to-Text
Transformers
Safetensors
English
qwen2_5_vl
safety
guardrail
GRPO
reinforcement-learning
vision-language
content-moderation
policy-aware
CVPR2026
conversational
text-generation-inference
Instructions to use tyodd/SafeGuard-VL-RL with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tyodd/SafeGuard-VL-RL with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="tyodd/SafeGuard-VL-RL") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("tyodd/SafeGuard-VL-RL") model = AutoModelForImageTextToText.from_pretrained("tyodd/SafeGuard-VL-RL") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.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(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use tyodd/SafeGuard-VL-RL with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tyodd/SafeGuard-VL-RL" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tyodd/SafeGuard-VL-RL", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/tyodd/SafeGuard-VL-RL
- SGLang
How to use tyodd/SafeGuard-VL-RL 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 "tyodd/SafeGuard-VL-RL" \ --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": "tyodd/SafeGuard-VL-RL", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "tyodd/SafeGuard-VL-RL" \ --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": "tyodd/SafeGuard-VL-RL", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use tyodd/SafeGuard-VL-RL with Docker Model Runner:
docker model run hf.co/tyodd/SafeGuard-VL-RL
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
base_model: Qwen/Qwen2.5-VL-7B-Instruct
|
| 5 |
+
datasets:
|
| 6 |
+
- AIML-TUDA/LlavaGuard
|
| 7 |
+
language:
|
| 8 |
+
- en
|
| 9 |
+
pipeline_tag: image-text-to-text
|
| 10 |
+
tags:
|
| 11 |
+
- safety
|
| 12 |
+
- guardrail
|
| 13 |
+
- GRPO
|
| 14 |
+
- reinforcement-learning
|
| 15 |
+
- vision-language
|
| 16 |
+
- content-moderation
|
| 17 |
+
- policy-aware
|
| 18 |
+
- CVPR2026
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
# SafeGuard-VL-RL
|
| 22 |
+
|
| 23 |
+
**SafeGuard-VL-RL** is a policy-aware visual safety guardrail model built on [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct), trained with Group Relative Policy Optimization (GRPO) for robust unsafe-image detection.
|
| 24 |
+
|
| 25 |
+
This model is part of our CVPR 2026 paper: *Towards Policy-Adaptive Image Guardrail: Benchmark and Method*.
|
| 26 |
+
|
| 27 |
+
## Key Features
|
| 28 |
+
|
| 29 |
+
- **Policy-aware safety judgment**: Unlike static classifiers, SafeGuard-VL-RL takes a natural language safety policy as input and makes context-sensitive decisions accordingly.
|
| 30 |
+
- **Robust instruction following**: Maintains general VQA capabilities while serving as a safety guardrail.
|
| 31 |
+
- **Cross-policy generalization**: Trained on one policy, generalizes to unseen policies with different category definitions.
|
| 32 |
+
|
| 33 |
+
## Model Description
|
| 34 |
+
|
| 35 |
+
SafeGuard-VL-RL is trained using **Stage-2 RL only** (without the Stage-1 SFT). It applies GRPO (from [DeepSeekMath](https://arxiv.org/abs/2402.03300)) on the [LlavaGuard](https://huggingface.co/datasets/AIML-TUDA/LlavaGuard) training set. For each image-policy pair, the ground truth safe/unsafe label serves as the reward signal, encouraging the model to reason about why a given image violates or complies with the policy.
|
| 36 |
+
|
| 37 |
+
| Detail | Value |
|
| 38 |
+
|---|---|
|
| 39 |
+
| **Base Model** | [Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct) |
|
| 40 |
+
| **Training Method** | GRPO (Group Relative Policy Optimization) |
|
| 41 |
+
| **Training Data** | [AIML-TUDA/LlavaGuard](https://huggingface.co/datasets/AIML-TUDA/LlavaGuard) (train split) |
|
| 42 |
+
|
| 43 |
+
## Usage
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
|
| 47 |
+
from qwen_vl_utils import process_vision_info
|
| 48 |
+
|
| 49 |
+
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 50 |
+
"tyodd/SafeGuard-VL-RL",
|
| 51 |
+
torch_dtype="auto",
|
| 52 |
+
device_map="auto",
|
| 53 |
+
)
|
| 54 |
+
processor = AutoProcessor.from_pretrained("tyodd/SafeGuard-VL-RL")
|
| 55 |
+
|
| 56 |
+
# Example: Safety evaluation with a custom policy
|
| 57 |
+
policy = """
|
| 58 |
+
"""
|
| 59 |
+
|
| 60 |
+
messages = [
|
| 61 |
+
{
|
| 62 |
+
"role": "user",
|
| 63 |
+
"content": [
|
| 64 |
+
{"type": "image", "image": "path/to/image.jpg"},
|
| 65 |
+
{"type": "text", "text": f"Based on the following safety policy, determine if this image is safe or unsafe.\n\nPolicy:\n{policy}\n\nProvide your reasoning and final judgment (Safe/Unsafe)."},
|
| 66 |
+
],
|
| 67 |
+
}
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 71 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
| 72 |
+
inputs = processor(
|
| 73 |
+
text=[text],
|
| 74 |
+
images=image_inputs,
|
| 75 |
+
videos=video_inputs,
|
| 76 |
+
padding=True,
|
| 77 |
+
return_tensors="pt",
|
| 78 |
+
).to(model.device)
|
| 79 |
+
|
| 80 |
+
generated_ids = model.generate(**inputs, max_new_tokens=512)
|
| 81 |
+
generated_ids_trimmed = [
|
| 82 |
+
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 83 |
+
]
|
| 84 |
+
output_text = processor.batch_decode(
|
| 85 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 86 |
+
)
|
| 87 |
+
print(output_text[0])
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## Citation
|
| 91 |
+
|
| 92 |
+
```bibtex
|
| 93 |
+
TBD
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
## Disclaimer
|
| 97 |
+
|
| 98 |
+
This model is designed for safety research purposes. It was trained on data containing unsafe content categories and is intended to help identify potentially harmful visual content. The model's judgments are policy-dependent and should not be used as the sole arbiter of content safety in production systems without human oversight.
|