Instructions to use XuehangCang/SmolLM3-3B-Rebel with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use XuehangCang/SmolLM3-3B-Rebel with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="XuehangCang/SmolLM3-3B-Rebel") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("XuehangCang/SmolLM3-3B-Rebel") model = AutoModelForCausalLM.from_pretrained("XuehangCang/SmolLM3-3B-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/SmolLM3-3B-Rebel with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "XuehangCang/SmolLM3-3B-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/SmolLM3-3B-Rebel", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/XuehangCang/SmolLM3-3B-Rebel
- SGLang
How to use XuehangCang/SmolLM3-3B-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/SmolLM3-3B-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/SmolLM3-3B-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/SmolLM3-3B-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/SmolLM3-3B-Rebel", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use XuehangCang/SmolLM3-3B-Rebel with Docker Model Runner:
docker model run hf.co/XuehangCang/SmolLM3-3B-Rebel
SmolLM3-3B 的去审查(uncensored)版本,由 heretic-zh 基于自建中文数据集自动生成。
⚠️ 注意:此模型已移除安全对齐(safety alignment),可能生成原始模型会拒答的内容。请负责任地使用。
模型概述
| 项目 | 说明 |
|---|---|
| 基座模型 | HuggingFaceTB/SmolLM3-3B |
| 去审查方法 | heretic-zh — Heretic 的中文优化版本,基于方向消融(directional ablation / abliteration)的全自动审查移除 |
| 训练数据集 | XuehangCang/safe_prompt(安全提示词) + XuehangCang/unsafe_prompt(不安全提示词) — 专为中文场景构建 |
| 架构 | SmolLM3(36 层,2048 hidden size,16 attention heads,4 KV heads,GQA + NoPE) |
| 参数量 | ~3B |
| 上下文长度 | 65,536 tokens(通过 YARN 可扩展至 128k) |
| 词表大小 | 128,000 |
| 精度 | bfloat16 |
去审查效果
heretic-zh 是 Heretic 的中文优化版本,专门针对中文语言模型的审查移除做了适配。与原始 Heretic 相比,heretic-zh 在以下方面做了针对性优化:
- 中文数据集:使用自建的 XuehangCang/safe_prompt 和 XuehangCang/unsafe_prompt 数据集,包含精心构建的中文安全与不安全提示词对,比通用英文数据集更准确地捕捉中文模型的审查行为。
- 中文拒答检测:扩充了中文拒答标记词表(免责声明、抱歉、我不能、我无法等),更精准地识别中文模型的拒答模式。
- Optuna + TPE 超参优化:在 200 次试验中自动搜索最优 abliteration 参数,目标为同时最小化拒答率和相对原始模型的 KL 散度。
| 指标 | 原始模型 | 本模型 |
|---|---|---|
| 拒答数(共 200 个"有害"提示词) | 96 | 5 |
| KL 散度(相对原始模型) | 0(按定义) | 0.074 |
✅ 拒答率从 48.0% 降至 **2.5%**,KL 散度仅 0.074,对模型通用能力的损伤极小。
最优消融参数
Heretic 对 attention 输出投影(o_proj)和 MLP 下投影(down_proj)施加了逐层权重衰减,沿"拒答方向"对中间残差流进行干预:
- 方向类型:全局(global)—对每层使用相同方向
- 方向索引:18.66
| 模块 | max_weight | max_weight_position | min_weight | min_weight_distance |
|---|---|---|---|---|
attn.o_proj |
0.955 | 22.79 | 0.652 | 14.65 |
mlp.down_proj |
1.391 | 31.66 | 0.723 | 20.62 |
使用方法
安装依赖
pip install transformers torch
推理示例
SmolLM3-3B 支持双模式推理(思考 / 非思考模式)。通过设置 enable_thinking 参数切换:
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "XuehangCang/SmolLM3-3B-Rebel"
device = "cuda"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
).to(device)
prompt = "你是什么模型"
messages_think = [{"role": "user", "content": prompt}]
text = tokenizer.apply_chat_template(
messages_think,
tokenize=False,
add_generation_prompt=True,
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(**model_inputs, max_new_tokens=32768)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]) :]
print(tokenizer.decode(output_ids, skip_special_tokens=True))
生成参数
| 参数 | 值 |
|---|---|
temperature |
0.6 |
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)
许可证
基于原始 SmolLM3-3B 模型,使用 Apache 2.0 许可证。
引用
如果你使用了此模型,请引用原始 SmolLM3、Heretic 和 heretic-zh:
@misc{smollm3,
title = {SmolLM3: Pushing the Limits of Small Language Models},
author = {Hugging Face},
url = {https://huggingface.co/HuggingFaceTB/SmolLM3-3B},
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
- 30
Model tree for XuehangCang/SmolLM3-3B-Rebel
Base model
HuggingFaceTB/SmolLM3-3B-Base