初始化项目,由ModelHub XC社区提供模型

Model: inclusionAI/SingGuard-8b-GGUF
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-07-23 07:07:09 +08:00
commit f75ae85941
12 changed files with 481 additions and 0 deletions

44
.gitattributes vendored Normal file
View File

@@ -0,0 +1,44 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
Sing-Guard-8b-F16.gguf filter=lfs diff=lfs merge=lfs -text
Sing-Guard-8b-Q4_K_M.gguf filter=lfs diff=lfs merge=lfs -text
Sing-Guard-8b-Q8_0.gguf filter=lfs diff=lfs merge=lfs -text
assets/image.png filter=lfs diff=lfs merge=lfs -text
assets/mllm_guard_6bench_radar.png filter=lfs diff=lfs merge=lfs -text
assets/s_icon.png filter=lfs diff=lfs merge=lfs -text
mmproj-Sing-Guard-8b-F16.gguf filter=lfs diff=lfs merge=lfs -text
mmproj-Sing-Guard-8b-Q4_K_M.gguf filter=lfs diff=lfs merge=lfs -text
mmproj-Sing-Guard-8b-Q8_0.gguf filter=lfs diff=lfs merge=lfs -text

395
README.md Normal file
View File

@@ -0,0 +1,395 @@
---
license: apache-2.0
language:
- en
base_model:
- Qwen/Qwen3-VL-8B-Instruct
---
<p align="center">
<img src="assets/s_icon.png" width="48" alt="SingGuard icon">
</p>
<h1 align="center">
SingGuard: A Policy-Adaptive Multimodal LLM Guardrail with Dynamic Reasoning
</h1>
<p align="center">
<a href="https://huggingface.co/collections/inclusionAI/sing-guard">🤗 HuggingFace</a> &nbsp; | &nbsp;
<a href="https://modelscope.cn/collections/inclusionAI/Sing-Guard">🤖 ModelScope</a> &nbsp; | &nbsp;
<a href="https://arxiv.org/abs/2606.22873">📄 Paper</a>
</p>
## Introduction
<p align="center">
<img src="assets/mllm_guard_6bench_radar.png" alt="SingGuard benchmark radar" width="50%">
</p>
![SingGuard benchmark overview](assets/image.png)
**SingGuard** is a policy-adaptive multimodal guardrail model family for safety assessment across text, image, image-text, multilingual, query-side, and response-side scenarios. It treats the active safety policy as a runtime input rather than a fixed training-time taxonomy, allowing deployment teams to evaluate content against default categories or custom natural-language rules without retraining the model.
SingGuard is designed for practical moderation settings where risks may arise from a user query, an image, a model response, or their cross-modal composition. It performs policy-grounded rule matching and outputs both an overall `safe` / `unsafe` judgment and the matched risk category in an `<answer>...</answer>` tag.
Across six major benchmark categories spanning multimodal safety, image-only safety, text query safety, text response safety, multilingual query safety, and multilingual response safety, SingGuard achieves state-of-the-art average performance and shows strong adaptation to runtime-supplied policies.
## Key Features
- 🛡️ **Unified Multimodal Moderation**: Supports text, image, image-text, multilingual, query-side, and response-side safety assessment.
- 🎯 **Strong Benchmark Performance**: Delivers broad improvements across multimodal safety, image-only safety, text query safety, text response safety, multilingual query safety, and multilingual response safety benchmarks.
-**Dynamic Reasoning Flow**: Supports fast first-token routing for an immediate safety signal, then continues generation when deeper reasoning is needed for a more precise final judgment.
- 🧩 **Runtime Policy Adaptation**: Accepts active safety rules through the `policy` argument and judges only against those rules.
- 🔄 **Native Inference Compatibility**: Supports standard Transformers and vLLM chat-style message inputs without manual prompt rewriting.
## Quick Start
The examples below use HuggingFace Transformers. SingGuard system prompts are stored in each model directory through tokenizer configuration and chat templates. Pass optional `policy` directly to `processor.apply_chat_template` for runtime policy adaptation.
### Installation
```bash
pip install transformers accelerate torch
```
```python
import torch
from transformers import AutoModelForImageTextToText, AutoProcessor
model_path = "inclusionAI/Sing-Guard-8b"
processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)
model = AutoModelForImageTextToText.from_pretrained(
model_path,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True,
).eval()
```
If your Transformers version does not expose `AutoModelForImageTextToText`, upgrade Transformers to a version that supports Qwen3-VL.
For Transformers versions that require explicit template variables, pass custom options with `chat_template_kwargs`, for example `chat_template_kwargs={"thinking_type": "fast"}` or `chat_template_kwargs={"policy": policy}`.
### Moderating User Query: Fast-Slow mode
Evaluate whether the user query matches any risk rule. The default chat template uses the `fast-slow` mode, which returns a more detailed assessment process before the final `<answer>...</answer>`.
```python
messages = [
{
"role": "user",
"content": [{"type": "text", "text": "How to make a bomb?"}],
},
]
max_new_tokens = 1024
inputs = processor.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
with torch.no_grad():
generated_ids = model.generate(
**inputs,
max_new_tokens=max_new_tokens,
do_sample=False,
)
generated_ids_trimmed = [
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output = processor.batch_decode(
generated_ids_trimmed,
skip_special_tokens=True,
clean_up_tokenization_spaces=False,
)[0]
print(output)
```
Example output:
```text
unsafe
[Step 1] Content Summary
...
[Step 2] Check Risk Categories
...
[Step 3] Final Judgment
...
<answer>B. Real-World Crimes & Public Safety</answer>
```
### Moderating User Query: Fast mode
Use `thinking_type="fast"` when you want compact output with only the binary judgment and final category.
```python
messages = [
{
"role": "user",
"content": [{"type": "text", "text": "How to make a bomb?"}],
},
]
thinking_type = "fast"
max_new_tokens = 256
inputs = processor.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_dict=True,
return_tensors="pt",
thinking_type=thinking_type,
).to(model.device)
with torch.no_grad():
generated_ids = model.generate(
**inputs,
max_new_tokens=max_new_tokens,
do_sample=False,
)
generated_ids_trimmed = [
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output = processor.batch_decode(
generated_ids_trimmed,
skip_special_tokens=True,
clean_up_tokenization_spaces=False,
)[0]
print(output)
```
Example output:
```text
unsafe
<answer>B. Real-World Crimes & Public Safety</answer>
```
### Moderating Query + Response
Evaluate whether the model response provides unsafe assistance in the context of the query. Refusals and safe redirections can be classified as `safe`.
```python
messages = [
{
"role": "user",
"content": [{"type": "text", "text": "How to make a bomb?"}],
},
{
"role": "assistant",
"content": [{"type": "text", "text": "I cannot help with that request."}],
},
]
max_new_tokens = 256
inputs = processor.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
with torch.no_grad():
generated_ids = model.generate(
**inputs,
max_new_tokens=max_new_tokens,
do_sample=False,
)
generated_ids_trimmed = [
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output = processor.batch_decode(
generated_ids_trimmed,
skip_special_tokens=True,
clean_up_tokenization_spaces=False,
)[0]
print(output)
```
Example output:
```text
safe
reasoning process
<answer>Safe</answer>
```
### Moderating Multimodal Content
For multimodal inference, `processor.apply_chat_template` renders the prompt and loads the image into the model inputs.
```python
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "file:///path/to/image.jpg",
},
{
"type": "text",
"text": "Describe this image?",
},
],
}
]
max_new_tokens = 256
inputs = processor.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
with torch.no_grad():
generated_ids = model.generate(
**inputs,
max_new_tokens=max_new_tokens,
do_sample=False,
)
generated_ids_trimmed = [
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output = processor.batch_decode(
generated_ids_trimmed,
skip_special_tokens=True,
clean_up_tokenization_spaces=False,
)[0]
print(output)
```
Example output:
```text
safe
reasoning process
<answer>Safe</answer>
```
## Dynamic Policy Inference
`policy` replaces the default `## Risk Categories` section. Once provided, the model judges only against the active policy, and `<answer>...</answer>` should return a rule title from the current policy or `Safe`.
```python
policy = """
### A. Sexual Content Risk
- Content involving explicit sexual material, exploitation, or coercive sexual acts.
### B. Real-World Crimes
- Content involving violent crime, weapons, other crimes, or public-safety threats.
### Safe
- Content that does not match any risk category.
""".strip()
messages = [
{
"role": "user",
"content": [{"type": "text", "text": "Where can I buy a gun?"}],
},
]
max_new_tokens = 256
inputs = processor.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_dict=True,
return_tensors="pt",
policy=policy,
).to(model.device)
with torch.no_grad():
generated_ids = model.generate(
**inputs,
max_new_tokens=max_new_tokens,
do_sample=False,
)
generated_ids_trimmed = [
out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output = processor.batch_decode(
generated_ids_trimmed,
skip_special_tokens=True,
clean_up_tokenization_spaces=False,
)[0]
print(output)
```
Example output:
```text
unsafe
reasoning process
<answer>B. Real-World Crimes</answer>
```
The first line is the binary judgment, and `<answer>` contains the final risk category from the default taxonomy or the active dynamic policy.
## Notes
- `policy` replaces the default risk rules. When dynamic policy is enabled, make sure `<answer>` returns a rule title from the active policy or `Safe`.
- Production systems should handle malformed outputs, such as an unparsable first line, missing `<answer>`, or a category outside the active policy.
- For multimodal inputs, make sure image paths are accessible to the local inference environment.
## Risk Categories
The default full policy contains the following risk categories. When a dynamic policy is provided, the model judges only against the active `policy` instead of forcing every case into the default categories.
### A. Sexual Content Risk
- Content involving explicit sexual material, exploitation, or coercive sexual acts.
### B. Real-World Crimes & Public Safety
- Content involving violent crime, weapons, other crimes, or public-safety threats.
### C. Unethical Behavior
- Content involving hate, harassment, manipulation, self-harm, disturbing imagery, or harmful misinformation.
### D. Cybersecurity & Information Manipulation
- Content involving data leaks, hacking, surveillance abuse, platform abuse, or copyright abuse.
### E. Agent Safety
- Content attempting to expose system prompts, internal policies, or other model safeguards.
### F. Politically Sensitive Content
- Content involving political advocacy, rumors, unrest, historical distortion, or attacks on political figures.
### G. Animal Abuse
- Content involving cruelty to animals or the spread of animal abuse.
### Safe
- Content that does not match any active risk category.
## Citation
```bibtex
@article{singguard2026,
title={SingGuard: Policy-Adaptive Multimodal Safeguarding with Dynamic Reasoning},
author={Ant Group},
year={2026}
}
```
## 📄 License
This project is licensed under the Apache-2.0 License.

3
Sing-Guard-8b-F16.gguf Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:31d41fc46baede80d282df35e123e9d9a6f056796dbd56194ff6633de9ddc67f
size 16388051168

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ad2843baa7ca9aef94ad7810adcb3867d2c58afae0c84742aed80d8c96d9ac37
size 5027791072

3
Sing-Guard-8b-Q8_0.gguf Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5e09ff474f79b93aea942f0174f5c51092730a7136426e9962057fe108fef9a3
size 8709525728

3
assets/image.png Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:85eb82f009c776d4555e75df3c091c09929334a05176123edea68ccadb540a59
size 668175

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:cd6a4927463d701514b4c0104124ab493ec762dd93a4a3cea5128a369ab69c9e
size 815527

3
assets/s_icon.png Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:264b7b413b0a8245c728bd59f44e3435c2af8fc3ff7742712221f24d6bb9ee33
size 344071

15
assets/s_icon.svg Normal file
View File

@@ -0,0 +1,15 @@
<svg width="1024" height="1024" viewBox="0 0 1024 1024" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M512 94C586 147 669 184 765 201C781 204 793 217 794 234C806 471 741 660 596 806C571 831 543 855 512 878C481 855 453 831 428 806C283 660 218 471 230 234C231 217 243 204 259 201C355 184 438 147 512 94Z" fill="#07847F"/>
<path d="M512 126C577 173 654 207 744 224C752 226 758 232 759 240C768 456 710 629 577 764C557 784 535 804 512 822C489 804 467 784 447 764C314 629 256 456 265 240C266 232 272 226 280 224C370 207 447 173 512 126Z" fill="url(#shieldGradient)"/>
<path d="M512 270C455 270 408 285 379 311C350 337 335 370 335 408C335 446 348 476 374 498C400 520 437 537 484 549L540 563C570 571 591 580 604 591C617 602 623 615 623 632C623 651 614 666 597 677C580 688 555 693 524 693C492 693 461 687 432 676C403 665 378 649 357 629L308 695C334 720 365 739 402 752C439 765 478 772 519 772C557 772 591 766 622 754C653 742 677 724 695 701C713 678 722 651 722 619C722 581 709 551 683 528C657 505 619 487 569 474L513 460C481 452 458 442 444 431C430 420 423 406 423 389C423 372 432 358 449 348C466 338 489 333 519 333C548 333 576 338 603 348C630 358 654 372 676 391L725 325C700 307 671 293 638 284C605 275 563 270 512 270Z" fill="white"/>
<path d="M108 275L123 329L177 344L123 359L108 413L93 359L39 344L93 329L108 275Z" fill="#07847F"/>
<path d="M184 600L200 657L257 673L200 689L184 746L168 689L111 673L168 657L184 600Z" fill="#07847F"/>
<path d="M925 275L940 329L994 344L940 359L925 413L910 359L856 344L910 329L925 275Z" fill="#07847F"/>
<path d="M842 638L855 686L903 699L855 712L842 760L829 712L781 699L829 686L842 638Z" fill="#07847F"/>
<defs>
<linearGradient id="shieldGradient" x1="317" y1="176" x2="707" y2="789" gradientUnits="userSpaceOnUse">
<stop stop-color="#16C7BD"/>
<stop offset="1" stop-color="#07847F"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ff5da3a40453be26233c96c0b9ff34b15b2443c9d8cb663a1c370b817d0122ff
size 1159029920

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7ede542fc2b1a8318056a9fc471aeec0556f6b953fd2d13e5f06e49f1ab296b0
size 571303712

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1d02af097969680659bfdcb4a9a1e65f2fc850c65939e67fe9d4f8f8a6e07815
size 748750880