
我们荣幸地推出Qwen-Scope,这是一款针对Qwen3及Qwen3.5系列模型训练的可解释性模块。具体而言,我们在Qwen的隐藏层中集成并训练了稀疏自编码器(SAE)。通过施加稀疏性约束,我们能够自动提取出高度解耦、低冗余且可解释性显著增强的数据特征。Qwen-Scope不仅可用于分析Qwen行为的内部机制,在模型优化方面也具有巨大潜力。其应用场景包括可控推理控制、评估样本分布分析与比较、数据分类与合成,以及模型训练与优化。更多详情请参见我们的技术报告。
| 属性 | 值 |
|---|---|
| 基础模型 | Qwen3-1.7B-Base |
SAE宽度 (d_sae) | 32768 |
隐藏层大小 (d_model) | 2048 |
| 扩展因子 | 16× |
| Top-K | 100 |
| 钩子点 | 残差流 |
| 覆盖层数 | 0 – 27(共28层) |
| 文件格式 | PyTorch .pt 字典 |
这是一个TopK SAE——在每次前向传播中,恰好保留100个非零特征。
每个 checkpoint 文件 layer{n}.sae.pt 是一个包含四个张量的 Python dict:
| 键 | 形状 | 描述 |
|---|---|---|
W_enc | (32768, 2048) | 编码器权重矩阵 |
W_dec | (2048, 32768) | 解码器权重矩阵 |
b_enc | (32768,) | 编码器偏置 |
b_dec | (2048,) | 解码器偏置 |
本仓库包含每个Transformer层(0–27层)对应的一个SAE checkpoint:
layer0.sae.pt
layer1.sae.pt
...
layer27.sae.pt端到端演示:运行基础LLM,在选定层挂钩残差流,并提取稀疏SAE特征激活。 在大多数情况下,使用基于基础模型训练的SAE来探索训练后检查点的内部过程也是合理的。
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
# ── 1. Load base model ────────────────────────────────────────────────────────
model_name = "Qwen/Qwen3-1.7B-Base"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float32)
model.eval()
# ── 2. Load SAE for a target layer ───────────────────────────────────────────
LAYER = 0 # choose any layer in 0–27
sae = torch.load(f"layer{LAYER}.sae.pt", map_location="cpu")
W_enc = sae["W_enc"] # (32768, 2048)
b_enc = sae["b_enc"] # (32768,)
def get_feature_acts(residual: torch.Tensor) -> torch.Tensor:
"""residual: (..., 2048) → sparse feature activations (..., 32768)"""
pre_acts = residual @ W_enc.T + b_enc
topk_vals, topk_idx = pre_acts.topk(100, dim=-1)
acts = torch.zeros_like(pre_acts)
acts.scatter_(-1, topk_idx, topk_vals)
return acts
# ── 3. Hook residual stream after the target transformer layer ────────────────
captured = {}
def _hook(module, input, output):
hidden = output[0] if isinstance(output, tuple) else output
captured["residual"] = hidden.detach().cpu()
hook = model.model.layers[LAYER].register_forward_hook(_hook)
# ── 4. Forward pass ───────────────────────────────────────────────────────────
text = "The capital of France is"
inputs = tokenizer(text, return_tensors="pt")
with torch.no_grad():
model(**inputs)
hook.remove()
# ── 5. Extract feature activations ───────────────────────────────────────────
residual = captured["residual"] # (1, seq_len, 2048)
feature_acts = get_feature_acts(residual) # (1, seq_len, 32768)
# Inspect active features for the last token
last_token_acts = feature_acts[0, -1] # (32768,)
active_idx = last_token_acts.nonzero(as_tuple=True)[0]
print(f"Active features : {active_idx.tolist()}")
print(f"Feature values : {last_token_acts[active_idx].tolist()}")我们还提供了一个 Gradio 演示 app.py。您可以在本地运行它:
python app.py \
--model Qwen/Qwen3-1.7B-Base \
--model-name-sae-trained-from qwen3-1.7b-base \
--model-name-analyzing-now qwen3-1.7b \
--sae-path Qwen/SAE-Res-Qwen3-1.7B-Base-W32K-L0_100 \
--top-k 100 \
--num-layers 28 \
--sae-width 32768 \
--d-model 2048 \
--server-port 7860严禁出于非科学研究目的使用可解释性工具干扰模型能力,或编造、生成、传播违反公序良俗及社会主义核心价值观的有害信息,包括色情、暴力、歧视或煽动性内容。违规者将被自动终止授权,并承担由此产生的一切法律责任。本声明的最终解释权归项目所有者所有。
如果您在研究中使用这些SAE,请引用:
@misc{qwen_scope,
title={{Qwen-Scope}: Turning Sparse Features into Development Tools for Large Language Models},
author={Boyi Deng and Xu Wang and Yaoning Wang and Yu Wan and Yubo Ma and Baosong Yang and Haoran Wei and Jialong Tang and Huan Lin and Ruize Gao and Tianhao Li and Qian Cao and Xuancheng Ren and Xiaodong Deng and An Yang and Fei Huang and Dayiheng Liu and Jingren Zhou},
year={2026},
eprint={2605.11887},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2605.11887},
}