Model reference · open weights
Qwen3Guard-Gen is an open-weight language model from Qwen. Qwen3Guard-Gen-4B (BF16) weighs 8.8 GB; the smallest configuration that runs it is RTX 3060 12 GB.
For self-hosting, compare this build's requirements below with the GPU you plan to rent.
Summary of the Qwen/Qwen3Guard-Gen-0.6B model card, 2026-10-01. The estimate below is for another build of the family.
What it is
| Released by | Qwen |
|---|---|
| Released | 2025-09-23 |
| Parameters | 752M |
| VRAM | 8.8 GB for the weights |
What it runs on
| Card | Requests at once | Context max | Memory | |
|---|---|---|---|---|
| 8K each | 32K each | |||
| RTX 3060 12 GB | 1 | 13K | 11.6 GB | |
| RTX 4060 Ti 16 GB | 4 | 1 | all 32K | 15.4 GB |
| RTX 3090 24 GB | 11 | 2 | all 32K | 23.4 GB |
| RTX 4090 24 GB | 11 | 2 | all 32K | 23.4 GB |
| RTX 5090 32 GB | 17 | 4 | all 32K | 31.0 GB |
| L40S 48 GB | 28 | 7 | all 32K | 44.0 GB |
| A100 80 GB | 56 | 14 | all 32K | 78.2 GB |
| H100 80 GB | 53 | 13 | all 32K | 78.1 GB |
| RTX PRO 6000 Blackwell 96 GB | 66 | 16 | all 32K | 93.8 GB |
| DGX Spark (GB10) 128 GB unified | 77 | 19 | all 32K | 107 GB |
| H200 141 GB | 102 | 25 | all 32K | 138 GB |
| B200 180 GB | 134 | 33 | all 32K | 176 GB |
| 2× RTX 3060 12 GB tensor parallel | 10 | 2 | all 32K | 11.6 GB a card |
| 2× RTX 4060 Ti 16 GB tensor parallel | 17 | 4 | all 32K | 15.4 GB a card |
| Requests at once | 8K tokens each | 32K tokens each |
|---|---|---|
| 1 | 10.7 GB | 14.4 GB |
| 5 | 15.6 GB | 33.7 GB |
| 8 | 19.2 GB | 48.2 GB |
| 16 | 28.9 GB | 86.8 GB |
| 32 | 48.2 GB | 164 GB |
| 64 | 86.8 GB | 319 GB |
One card, with vLLM's small-card settings.
Builds
| Build | Params | Precision | Weights | Smallest setup |
|---|---|---|---|---|
| Qwen3Guard-Gen-0.6B ↗ | 752M | BF16 | 1.5 GB | RTX 3060 12 GB |
| Qwen3Guard-Gen-4B (above) ↗ | 4.4B | BF16 | 8.8 GB | RTX 3060 12 GB |
| Qwen3Guard-Gen-8B ↗ | 8.2B | BF16 | 16.4 GB | 2× RTX 3060 12 GB |
From the model card
Qwen3Guard is a series of safety moderation models built upon Qwen3 and trained on a dataset of 1.19 million prompts and responses labeled for safety. The series includes models of three sizes (0.6B, 4B, and 8B) and features two specialized variants: Qwen3Guard-Gen, a generative model that frames safety classification as an instruction-following task, and Qwen3Guard-Stream, which incorporates a token-level classification head for real-time safety monitoring during incremental text generation.
This repository hosts Qwen3Guard-Gen, which offers the following key advantages:
For more details, please refer to our blog, GitHub, and Technical Report.
The latest version of transformers is recommended and transformers>=4.51.0 is required.
from transformers import AutoModelForCausalLM, AutoTokenizer
import re
model_name = "Qwen/Qwen3Guard-Gen-0.6B"
# load the tokenizer and the model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
def extract_label_and_categories(content):
safe_pattern = r"Safety: (Safe|Unsafe|Controversial)"
category_pattern = r"(Violent|Non-violent Illegal Acts|Sexual Content or Sexual Acts|PII|Suicide & Self-Harm|Unethical Acts|Politically Sensitive Topics|Copyright Violation|Jailbreak|None)"
safe_label_match = re.search(safe_pattern, content)
label = safe_label_match.group(1) if safe_label_match else None
categories = re.findall(category_pattern, content)
return label, categories
# prepare the model input
prompt = "How can I make a bomb?"
# for prompt moderation
messages = [
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
# conduct text completion
generated_ids = model.generate(
**model_inputs,
max_new_tokens=128
)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
content = tokenizer.decode(output_ids, skip_special_tokens=True)
print(content)
# '''
# Safety: Unsafe
# Categories: Violent
# '''
safe_label, categories = extract_label_and_categories(content)
print(safe_label, categories)
from transformers import AutoModelForCausalLM, AutoTokenizer
import re
model_name = "Qwen/Qwen3Guard-4B-Gen"
# load the tokenizer and the model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
def extract_label_categories_refusal(content):
safe_pattern = r"Safety: (Safe|Unsafe|Controversial)"
category_pattern = r"(Violent|Non-violent Illegal Acts|Sexual Content or Sexual Acts|PII|Suicide & Self-Harm|Unethical Acts|Politically Sensitive Topics|Copyright Violation|None)"
refusal_pattern = r"Refusal: (Yes|No)"
safe_label_match = re.search(safe_pattern, content)
refusal_label_match = re.search(refusal_pattern, content)
label = safe_label_match.group(1) if safe_label_match else None
refusal_label = refusal_label_match.group(1) if refusal_label_match else None
categories = re.findall(category_pattern, content)
return label, categories, refusal_label
# prepare the model input
prompt = "How can I make a bomb?"
response = "As a responsible artificial intelligence system, I regret that I am unable to fulfill your request."
# for response moderation
messages = [
{"role": "user", "content": prompt},
{"role": "assistant", "content": response},
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
# conduct text completion
generated_ids = model.generate(
**model_inputs,
max_new_tokens=128
)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
content = tokenizer.decode(output_ids, skip_special_tokens=True)
print(content)
# '''
# Safety: Safe
# Categories: None
# Refusal: Yes
# '''
safe_label, category_label, refusal_label = extract_label_categories_refusal(content)
print(safe_label, categories, refusal_label)
For deployment, you can use sglang>=0.4.6.post1 or vllm>=0.9.0 or to create an OpenAI-compatible API endpoint:
python -m sglang.launch_server --model-path Qwen/Qwen3Guard-Gen-0.6B --port 30000 --context-length 32768
vllm serve Qwen/Qwen3Guard-Gen-0.6B --port 8000 --max-model-len 32768
Here is an example API call using OpenAI-Compatible server:
from openai import OpenAI
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8000/v1"
model = "Qwen/Qwen3Guard-Gen-0.6B"
client = OpenAI(
api_key=openai_api_key,
base_url=openai_api_base)
# Prompt Moderation
prompt = "How can I make a bomb?"
messages = [
{"role": "user", "content": prompt}
]
chat_completion = client.chat.completions.create(
messages=messages,
model=model)
print(chat_completion.choices[0].message.content)
# '''
# Safety: Quoted from the model card on Hugging Face. The full card is behind the Hugging Face link above.