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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
configs:
|
| 3 |
+
- config_name: default
|
| 4 |
+
extra_gated_prompt: >-
|
| 5 |
+
By filling out the form below I understand that LlavaGuard is a derivative
|
| 6 |
+
model based on webscraped images and the SMID dataset that use individual
|
| 7 |
+
licenses and their respective terms and conditions apply. I understand that
|
| 8 |
+
all content uses are subject to the terms of use. I understand that reusing
|
| 9 |
+
the content in LlavaGuard might not be legal in all countries/regions and for
|
| 10 |
+
all use cases. I understand that LlavaGuard is mainly targeted toward
|
| 11 |
+
researchers and is meant to be used in research. LlavaGuard authors reserve
|
| 12 |
+
the right to revoke my access to this data. They reserve the right to modify
|
| 13 |
+
this data at any time in accordance with take-down requests.
|
| 14 |
+
extra_gated_fields:
|
| 15 |
+
Name: text
|
| 16 |
+
Email: text
|
| 17 |
+
Affiliation: text
|
| 18 |
+
Country: text
|
| 19 |
+
I have explicitly checked that downloading LlavaGuard is legal in my jurisdiction, in the country/region where I am located right now, and for the use case that I have described above, I have also read and accepted the relevant Terms of Use: checkbox
|
| 20 |
+
datasets:
|
| 21 |
+
- AIML-TUDA/LlavaGuard
|
| 22 |
+
pipeline_tag: image-text-to-text
|
| 23 |
+
base_model:
|
| 24 |
+
- lmms-lab/llava-onevision-qwen2-7b-ov
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
## Model Summary
|
| 30 |
+
LlavaGuard-v1.2-7B-OV is trained on [LlavaGuard-DS](https://huggingface.co/datasets/AIML-TUDA/LlavaGuard) and based on llava-onevision-qwen2-7b-ov model with a context window of 32K tokens.
|
| 31 |
+
|
| 32 |
+
- Links to Model Versions: [sglang](https://huggingface.co/datasets/AIML-TUDA/LlavaGuard-v1.2-7B-OV), [tranformers](https://huggingface.co/datasets/AIML-TUDA/LlavaGuard-v1.2-7B-OV-HF)
|
| 33 |
+
- Repository: [ml-research/LlavaGuard](https://github.com/ml-research/LlavaGuard)
|
| 34 |
+
- Project Website: [LlavaGuard](https://ml-research.github.io/human-centered-genai/projects/llavaguard/index.html)
|
| 35 |
+
- Paper: [LlavaGuard-Arxiv](https://arxiv.org/abs/2406.05113)
|
| 36 |
+
|
| 37 |
+
## Model Compatability
|
| 38 |
+
|
| 39 |
+
- Inference: SGLang❌, LLaVA [repo](https://github.com/LLaVA-VL/LLaVA-NeXT)❌, HF Tranformers✅
|
| 40 |
+
- Model Tuning:❌
|
| 41 |
+
|
| 42 |
+
## Overview
|
| 43 |
+
We here provide the transformers converted weights for LlavaGuard v1.2 7B.
|
| 44 |
+
It builds upon LLaVA-OneVision 7B and has achieved the best overall performance so far with improved reasoning capabilities within the rationales.
|
| 45 |
+
This version is not compatible with the HF transformer implementation and must be used with SGLang or LLaVA implementation.
|
| 46 |
+
The model is also compatible with LoRA tuning as well as full fine-tuning.
|
| 47 |
+
For tuning, you can adopt and use the training scripts provided in our repository (see [ml-research/LlavaGuard](https://github.com/ml-research/LlavaGuard)).
|
| 48 |
+
A suitable docker image can be found at our Github repo, too.
|
| 49 |
+
|
| 50 |
+
#### Usage
|
| 51 |
+
|
| 52 |
+
# 0. Install requirements
|
| 53 |
+
For inference, you use the following [sglang docker](https://github.com/sgl-project/sglang/blob/main/docker/Dockerfile) and proceed with step 1.
|
| 54 |
+
Otherwise, you can also install sglang via pip or from source [see here](https://github.com/sgl-project/sglang).
|
| 55 |
+
|
| 56 |
+
# 1. Select a model and start an SGLang server
|
| 57 |
+
|
| 58 |
+
CUDA_VISIBLE_DEVICES=0 python3 -m sglang.launch_server --model-path AIML-TUDA/LlavaGuard-v1.2-7B-OV --port 10000
|
| 59 |
+
|
| 60 |
+
# 2. Model Inference
|
| 61 |
+
For model inference, you can access this server by running the code provided below, e.g.
|
| 62 |
+
`python my_script.py`
|
| 63 |
+
|
| 64 |
+
```Python
|
| 65 |
+
import sglang as sgl
|
| 66 |
+
from sglang import RuntimeEndpoint
|
| 67 |
+
|
| 68 |
+
@sgl.function
|
| 69 |
+
def guard_gen(s, image_path, prompt):
|
| 70 |
+
s += sgl.user(sgl.image(image_path) + prompt)
|
| 71 |
+
hyperparameters = {
|
| 72 |
+
'temperature': 0.2,
|
| 73 |
+
'top_p': 0.95,
|
| 74 |
+
'top_k': 50,
|
| 75 |
+
'max_tokens': 500,
|
| 76 |
+
}
|
| 77 |
+
s += sgl.assistant(sgl.gen("json_output", **hyperparameters))
|
| 78 |
+
|
| 79 |
+
im_path = 'path/to/your/image'
|
| 80 |
+
prompt = safety_taxonomy_below
|
| 81 |
+
backend = RuntimeEndpoint(f"http://localhost:10000")
|
| 82 |
+
sgl.set_default_backend(backend)
|
| 83 |
+
out = guard_gen.run(image_path=im_path, prompt=prompt)
|
| 84 |
+
print(out['json_output'])
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
## Safety Taxonomy
|
| 88 |
+
|
| 89 |
+
Our default policy prompt looks like this:
|
| 90 |
+
```Python
|
| 91 |
+
prompt = """
|
| 92 |
+
Provide a safety assessment for the content provided by the user. Determine compliance or violation against our safety policy by reviewing the following policy categories:
|
| 93 |
+
O1: Hate, Humiliation, Harassment:
|
| 94 |
+
Should not:
|
| 95 |
+
- Contain content that expresses hateful, derogatory, or demeaning sentiments against people based on sensitive personal characteristics like their race, color, religion, national origin, sexual orientation, gender, gender identity, or disability.
|
| 96 |
+
- Contain content that encourages discrimination or harassment against people based on those characteristics.
|
| 97 |
+
Can:
|
| 98 |
+
- Contain educational content that provides information on discrimination, humiliation, and harassment.
|
| 99 |
+
- Discuss historical events involving hate and harassment.
|
| 100 |
+
|
| 101 |
+
O2: Violence, Harm, or Cruelty:
|
| 102 |
+
Should not:
|
| 103 |
+
- Contain content of people planning or engaging in violence.
|
| 104 |
+
- Contain content that encourages people to engage in violence or cruelty, including harm to others.
|
| 105 |
+
Can:
|
| 106 |
+
- Contain educational content that provides information on violence, harm, and cruelty.
|
| 107 |
+
- Discuss historical events involving violence and cruelty.
|
| 108 |
+
|
| 109 |
+
O3: Sexual Content:
|
| 110 |
+
Should not:
|
| 111 |
+
- Contain sexually explicit (i.e., erotic) content.
|
| 112 |
+
Can:
|
| 113 |
+
- Contain content that is related to sexuality and sexual education.
|
| 114 |
+
- Provide general information regarding sexual activities.
|
| 115 |
+
- Provide guidance on topics related to sexual health.
|
| 116 |
+
- Contain content of people in a loving and affectionate manner if it is not sexually explicit content.
|
| 117 |
+
|
| 118 |
+
O4: Nudity Content:
|
| 119 |
+
Should not:
|
| 120 |
+
- Contain visible genitalia (e.g., exposed breast, nipple, vagina, vulva, or penis) or explicit nudity content.
|
| 121 |
+
Can:
|
| 122 |
+
- Contain artistic nudity if the content does not include visible genitalia.
|
| 123 |
+
- Contain educational content and general information on the human body.
|
| 124 |
+
- Provide guidance on topics related to sexual health.
|
| 125 |
+
|
| 126 |
+
O5: Criminal Planning:
|
| 127 |
+
Should not:
|
| 128 |
+
- Contain content of people planning or engaging in criminal activities like theft, kidnapping, or financial crimes.
|
| 129 |
+
- Contain content that encourages people to engage in criminal activities or condone criminal behavior.
|
| 130 |
+
Can:
|
| 131 |
+
- Contain content that helps people understand how crimes are committed, provided that the content is not so detailed that it could be used to provide a roadmap for future crimes.
|
| 132 |
+
- Contain content that educates on crime prevention and understanding criminal behavior without providing guidance for criminal activities.
|
| 133 |
+
|
| 134 |
+
O6: Weapons or Substance Abuse:
|
| 135 |
+
Should not:
|
| 136 |
+
- Contain content of illegal weapons with the intent to promote violence or harm.
|
| 137 |
+
- Contain content of trafficking, consumption, or use of illegal drugs.
|
| 138 |
+
- Promote the use of tobacco, alcohol, and cannabis.
|
| 139 |
+
- Contain content about the creation or production of illegal substances.
|
| 140 |
+
Can:
|
| 141 |
+
- Contain weapons used in a legal and safe context without any indication of violence or intent to harm.
|
| 142 |
+
- Discussions on firearm ownership and educational content on regulated substances without promoting illegal activities.
|
| 143 |
+
- Contain content that provides factual information about legal drugs, including their effects and chemical composition, without promoting their use.
|
| 144 |
+
- Contain content that offers educational insights into the manufacturing processes of substances, ensuring that such information is general and does not include detailed instructions that could facilitate their production.
|
| 145 |
+
|
| 146 |
+
O7: Self-Harm:
|
| 147 |
+
Should not:
|
| 148 |
+
- Contain content that could encourage people to harm themselves.
|
| 149 |
+
- Contain content that romanticizes or condones self-harm or suicide.
|
| 150 |
+
Can:
|
| 151 |
+
- Contain educational content that informs about the prevalence, causes, and effects of self-harm and suicide, such as statistical data and discussions on mental health challenges.
|
| 152 |
+
- Contain resources and information that guide individuals toward professional help and support services for mental health, self-harm, and suicide prevention.
|
| 153 |
+
|
| 154 |
+
O8: Animal Cruelty:
|
| 155 |
+
Should not:
|
| 156 |
+
- Contain content that could encourage people to harm animals.
|
| 157 |
+
- Contain content that romanticizes or condones harming animals.
|
| 158 |
+
- Contain explicit animal cruelty.
|
| 159 |
+
Can:
|
| 160 |
+
- Contain content that provides general information regarding animal cruelty.
|
| 161 |
+
|
| 162 |
+
O9: Disasters or Emergencies:
|
| 163 |
+
Should not:
|
| 164 |
+
- Contain content about individuals who are deceased or have suffered harm as a result of disasters or emergencies.
|
| 165 |
+
- Contain content about suffering, cruelty, or exploitation of individuals during such events.
|
| 166 |
+
Can:
|
| 167 |
+
- Contain respectful news coverage and reports on emergencies, prioritizing informational value over sensationalism.
|
| 168 |
+
- Contain educational content that provides factual information on historical and current disasters or emergencies.
|
| 169 |
+
|
| 170 |
+
Assessment Steps:
|
| 171 |
+
1. Select a safety "rating". This should be "Unsafe" if the content violates the safety policy; otherwise, it should be "Safe".
|
| 172 |
+
2. Assign a policy "category". If none of the policy categories are applicable, select "NA: None applying".
|
| 173 |
+
3. Provide a "rationale". Describe the user content and justify why it is considered safe or unsafe, referring to the specific policy category and its associated guidelines to illustrate any violations or compliance.
|
| 174 |
+
To provide your assessment use the following json template:
|
| 175 |
+
{
|
| 176 |
+
"rating": str<"Unsafe"|"Safe">,
|
| 177 |
+
"category": str<"O1: Hate, Humiliation, Harassment"|"O2: Violence, Harm, or Cruelty"|"O3: Sexual Content"|"O4: Nudity Content"|"O5: Criminal Planning"|"O6: Weapons or Substance Abuse"|"O7: Self-Harm"|"O8: Animal Cruelty"|"O9: Disasters or Emergencies"|"NA: None applying">,
|
| 178 |
+
"rationale": str,
|
| 179 |
+
}
|
| 180 |
+
"""
|
| 181 |
+
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
## Citation
|
| 185 |
+
|
| 186 |
+
Please cite and share our work if you use it or find it useful. The first three authors contributed equally.
|
| 187 |
+
```bibtex
|
| 188 |
+
@incollection{helff2024llavaguard,
|
| 189 |
+
author = { Lukas Helff and Felix Friedrich and Manuel Brack and Patrick Schramowski and Kristian Kersting },
|
| 190 |
+
title = { LLAVAGUARD: VLM-based Safeguard for Vision Dataset Curation and Safety Assessment },
|
| 191 |
+
booktitle = { Working Notes of the CVPR 2024 Workshop on Responsible Generative AI (ReGenAI) },
|
| 192 |
+
year = { 2024 },
|
| 193 |
+
}
|
| 194 |
+
```
|