Image-Text-to-Text
Transformers
Safetensors
English
qwen2_5_vl
feature-extraction
vision
multimodal
safety
content-moderation
qwen2.5-vl
image-classification
vision-language
conversational
custom_code
text-generation-inference
Instructions to use etri-vilab/SafeQwen2.5-VL-32B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use etri-vilab/SafeQwen2.5-VL-32B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="etri-vilab/SafeQwen2.5-VL-32B", trust_remote_code=True) 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, AutoModelForVision2Seq processor = AutoProcessor.from_pretrained("etri-vilab/SafeQwen2.5-VL-32B", trust_remote_code=True) model = AutoModelForVision2Seq.from_pretrained("etri-vilab/SafeQwen2.5-VL-32B", trust_remote_code=True, device_map="auto") 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 Settings
- vLLM
How to use etri-vilab/SafeQwen2.5-VL-32B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "etri-vilab/SafeQwen2.5-VL-32B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "etri-vilab/SafeQwen2.5-VL-32B", "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/etri-vilab/SafeQwen2.5-VL-32B
- SGLang
How to use etri-vilab/SafeQwen2.5-VL-32B 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 "etri-vilab/SafeQwen2.5-VL-32B" \ --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": "etri-vilab/SafeQwen2.5-VL-32B", "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 "etri-vilab/SafeQwen2.5-VL-32B" \ --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": "etri-vilab/SafeQwen2.5-VL-32B", "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 etri-vilab/SafeQwen2.5-VL-32B with Docker Model Runner:
docker model run hf.co/etri-vilab/SafeQwen2.5-VL-32B
File size: 2,521 Bytes
7cc9477 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | """
SafeQwen2.5-VL Configuration
This configuration class extends the official Qwen2_5_VLConfig to add safety-aware
classification capabilities for multimodal content moderation.
Author: SafeQwen Team
"""
from typing import Optional, List
from transformers.models.qwen2_5_vl import Qwen2_5_VLConfig
class SafeQwen2_5_VLConfig(Qwen2_5_VLConfig):
"""
Configuration class for SafeQwen2.5-VL model.
SafeQwen2.5-VL extends Qwen2.5-VL with an additional safety classification head
that can identify 20 categories of potentially unsafe content in images.
Args:
safety_categories (`List[str]`, *optional*):
List of safety category names. Defaults to HoliSafe 20-category taxonomy.
safety_head_hidden_scale (`float`, *optional*, defaults to 4.0):
Scale factor for safety head hidden size relative to model hidden size.
safety_loss_lambda (`float`, *optional*, defaults to 1.0):
Weight for safety classification loss during training.
safety_num_hidden_layers (`int`, *optional*, defaults to 1):
Number of hidden layers in the safety classification MLP.
"""
model_type = "qwen2_5_vl"
def __init__(
self,
# Safety specific parameters
safety_categories: Optional[List[str]] = None,
safety_head_hidden_scale: float = 4.0,
safety_loss_lambda: float = 1.0,
safety_num_hidden_layers: int = 1,
**kwargs
):
super().__init__(**kwargs)
# HoliSafe 20-category safety taxonomy
self.safety_categories = safety_categories or [
"safe",
"gender",
"race",
"religion",
"harassment",
"disability_discrimination",
"drug_related_hazards",
"property_crime",
"facial_data_exposure",
"identity_data_exposure",
"physical_self_injury",
"suicide",
"animal_abuse",
"obscene_gestures",
"physical_altercation",
"terrorism",
"weapon_related_violence",
"sexual_content",
"financial_advice",
"medical_advice"
]
self.safety_head_hidden_scale = safety_head_hidden_scale
self.safety_loss_lambda = safety_loss_lambda
self.safety_num_hidden_layers = safety_num_hidden_layers
# Set num_safety_categories from the list
self.num_safety_categories = len(self.safety_categories)
|