Instructions to use XuehangCang/MiniCPM5-1B-Rebel with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use XuehangCang/MiniCPM5-1B-Rebel with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="XuehangCang/MiniCPM5-1B-Rebel") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("XuehangCang/MiniCPM5-1B-Rebel") model = AutoModelForCausalLM.from_pretrained("XuehangCang/MiniCPM5-1B-Rebel") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.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(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use XuehangCang/MiniCPM5-1B-Rebel with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "XuehangCang/MiniCPM5-1B-Rebel" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "XuehangCang/MiniCPM5-1B-Rebel", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/XuehangCang/MiniCPM5-1B-Rebel
- SGLang
How to use XuehangCang/MiniCPM5-1B-Rebel 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 "XuehangCang/MiniCPM5-1B-Rebel" \ --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": "XuehangCang/MiniCPM5-1B-Rebel", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "XuehangCang/MiniCPM5-1B-Rebel" \ --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": "XuehangCang/MiniCPM5-1B-Rebel", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use XuehangCang/MiniCPM5-1B-Rebel with Docker Model Runner:
docker model run hf.co/XuehangCang/MiniCPM5-1B-Rebel
MiniCPM5-1B-Rebel
MiniCPM5-1B 的去审查(uncensored)版本,由 heretic-zh 基于自建中文、数据集自动生成。
⚠️ 注意:此模型已移除安全对齐(safety alignment),可能生成原始模型会拒答的内容。请负责任地使用。
模型概述
| 项目 | 说明 |
|---|---|
| 基座模型 | openbmb/MiniCPM5-1B |
| 去审查方法 | heretic-zh — Heretic 的中文优化版本,基于方向消融(directional ablation / abliteration)的全自动审查移除 |
| 训练数据集 | XuehangCang/safe_prompt(安全提示词) + XuehangCang/unsafe_prompt(不安全提示词) — 专为中文场景构建 |
| 架构 | LLaMA(24 层,1536 hidden size,16 attention heads,2 KV heads) |
| 参数量 | ~1B |
| 上下文长度 | 131,072 tokens |
| 词表大小 | 130,560 |
| 精度 | bfloat16 |
去审查效果
heretic-zh 是 Heretic 的中文优化版本,专门针对中文语言模型的审查移除做了适配。与原始 Heretic 相比,heretic-zh 在以下方面做了针对性优化:
- 中文数据集:使用自建的 XuehangCang/safe_prompt 和 XuehangCang/unsafe_prompt 数据集,包含精心构建的中文安全与不安全提示词对,比通用英文数据集更准确地捕捉中文模型的审查行为。
- 中文拒答检测:扩充了中文拒答标记词表(免责声明、抱歉、我不能、我无法等),更精准地识别中文模型的拒答模式。
- Optuna + TPE 超参优化:在 200 次试验中自动搜索最优 abliteration 参数,目标为同时最小化拒答率和相对原始模型的 KL 散度。
| 指标 | 原始模型 | 本模型 |
|---|---|---|
| 拒答数(共 200 个"有害"提示词) | 193 | 0 |
| KL 散度(相对原始模型) | 0(按定义) | 0.030 |
✅ 拒答率从 96.5% 降至 **0%**,同时 KL 散度仅 0.030,对模型通用能力的损伤极小。
最优消融参数
Heretic 对 attention 输出投影(o_proj)和 MLP 下投影(down_proj)施加了逐层权重衰减,沿"拒答方向"对中间残差流进行干预:
- 方向类型:全局(global)—对每层使用相同方向
- 方向索引:13.40
| 模块 | max_weight | max_weight_position | min_weight | min_weight_distance |
|---|---|---|---|---|
attn.o_proj |
0.927 | 13.87 | 0.111 | 9.02 |
mlp.down_proj |
1.464 | 16.95 | 0.679 | 7.65 |
使用方法
安装依赖
pip install transformers torch
推理示例
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "XuehangCang/MiniCPM5-1B-Rebel"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype="auto",
device_map="auto",
)
messages = [{"role": "user", "content": "你是什么模型?"}]
inputs = tokenizer.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
enable_thinking=False,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=2048)
print(
tokenizer.decode(
outputs[0][inputs["input_ids"].shape[-1] :], skip_special_tokens=True
)
)
生成参数
| 参数 | 值 |
|---|---|
temperature |
0.9 |
top_p |
0.95 |
do_sample |
true |
关于 heretic-zh
heretic-zh 是 Heretic(面向语言模型的全自动审查移除工具)的中文优化版本。Heretic 使用方向消融(abliteration)技术,通过分析模型在"好的"(安全)和"坏的"(不安全)提示词上的残差流差异来找到"拒答方向",然后对该方向进行干预以抑制模型的拒答行为。
heretic-zh 在此基础上专门为中文模型和中文用户做了深度适配:
- 中文拒答检测:扩充了中文特有拒答短语库,覆盖"免责声明"、"抱歉"、"我不能"、"我无法"等数十种常见中文拒答表达。
- 中文提示词数据集:使用自建的 safe_prompt / unsafe_prompt 数据集,专门针对中文语义场景构建。
- 汉字文本处理:对中文拒答文本做 NFKC 规范化处理,移除 CJK 字符间多余空格后再进行匹配,显著提升对中文模型输出的拒答识别准确率。
与手工调参的 abliteration 不同,heretic-zh 继承 Heretic 的 Optuna TPE(Tree-structured Parzen Estimator)采样器自动搜索最优消融参数,在拒答抑制和模型能力保留之间找到最佳平衡。
了解更多:
- heretic-zh GitHub 仓库
- Heretic 原始项目
- Heretic Hugging Face 组织
- XuehangCang/safe_prompt 数据集
- XuehangCang/unsafe_prompt 数据集
- 方向消融论文(Arditi et al. 2024)
许可证
基于原始 MiniCPM5-1B 模型,使用 Apache 2.0 许可证。
引用
如果你使用了此模型,请引用原始 MiniCPM、Heretic 和 heretic-zh:
@misc{minicpm5,
title = {MiniCPM: Unveiling the Potential of Small Language Models},
author = {OpenBMB},
url = {https://github.com/OpenBMB/MiniCPM},
year = {2025}
}
@misc{heretic,
title = {Heretic: Fully Automatic Censorship Removal for Language Models},
author = {Philipp Emanuel Weidmann},
url = {https://github.com/p-e-w/heretic},
year = {2025}
}
@misc{heretic-zh,
title = {heretic-zh: Chinese-Optimized Automatic Censorship Removal},
author = {XuehangCang},
url = {https://github.com/XuehangCang/heretic-zh},
year = {2026}
}
- Downloads last month
- 39