Downloads · 30 days
37
7% of all-time downloads
vincentchao/qmllm_unitok
qmllm_unitok is a image-text-to-text model from vincentchao. Use it for the image-text-to-text task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as cc-by-nc-4.0.
This repository contains Q-MLLM, a novel architecture presented in the paper Q-MLLM: Vector Quantization for Robust Multimodal Large Language Model Security.
Downloads · 30 days
37
7% of all-time downloads
All-time downloads
531
Public
Parameters
7.6B
15.2 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors15.2 GB · 100%
How the weights are stored.
F167.6B · 100%
From the Hugging Face model README
This repository contains Q-MLLM, a novel architecture presented in the paper Q-MLLM: Vector Quantization for Robust Multimodal Large Language Model Security.
Code: https://github.com/Amadeuszhao/QMLLM
Q-MLLM is a novel architecture that integrates two-level vector quantization to create a discrete bottleneck against adversarial attacks while preserving multimodal reasoning capabilities. Our approach achieves:
The original GitHub repository's images/ folder contains test images depicting harmful content including:
Please exercise caution when accessing these files. They are included solely for research and evaluation purposes.
# Clone the repository
git clone https://github.com/Amadeuszhao/Q-MLLM.git
cd Q-MLLM
# Install requirements
pip install -r requirements.txt
from transformers import LlavaProcessor
from unitok_qllava import LlavaForConditionalGeneration
from utils.process import process_with_unitok
from PIL import Image
import torch
# Load model and processor
model_path = "vincentchao/qmllm_unitok"
model = LlavaForConditionalGeneration.from_pretrained(
model_path,
torch_dtype=torch.float16,
).cuda()
processor = LlavaProcessor.from_pretrained(model_path)
# Process an image
image = Image.open("path/to/image.jpg").convert('RGB')
conversation = [
{
"role": "user",
"content": [
{"type": "text", "text": "Describe this image"},
{"type": "image"},
],
},
]
prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
inputs = process_with_unitok(processor, images=image, text=prompt, return_tensors="pt").to(model.device).to(model.dtype)
# Generate response
input_length = inputs['input_ids'].shape[1]
with torch.no_grad():
output = model.generate(**inputs, max_new_tokens=100)
description = processor.decode(output[0][input_length:], skip_special_tokens=True)
print(description)
When harmful content is detected, the model raises a ValueError with category information:
try:
# Process image as shown above
generated_text = processor.decode(output[0][input_length:], skip_special_tokens=True)
print(f"✓ Image is safe, generated result:\n{generated_text}")
except ValueError as e:
# Extract category information from error message
error_msg = str(e)
category_id = int(error_msg.split("category=")[-1].strip())
category_name = id2class[category_id]
print(f"⚠️ Harmful content detected!")
print(f" Category ID: {category_id}")
print(f" Category Name: {category_name}")
| Defense Method | Jailbreak DSR | Image DSR | Overhead |
|---|---|---|---|
| LLaVA-1.5 | 49.5% | 1.0% | - |
| MLLM-Protector | 91.7% | 53.3% | High |
| ETA | 92.1% | 54.7% | High |
| Q-MLLM-7B | 98.4% | 75.9% | Minimal |
| Q-MLLM v2.0 (UniTok) | 98.4% | 78.4% | Minimal |
⚠️ Ethical Use Notice ⚠️
This research tool is designed to improve AI safety. The toxic content detection capabilities should only be used for:
Do not use this tool to generate, distribute, or process harmful content for malicious purposes.