Downloads · 30 days
0
upseem/unseen-gemma-4-26b-abliteration-method
unseen-gemma-4-26b-abliteration-method is a machine learning model from upseem. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
This repository contains method documentation only. No model weights are included.
Downloads · 30 days
0
Access
Public
Updated Sep 4, 2026
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md11.3 KB · 88%
From the Hugging Face model README
This repository contains method documentation only. No model weights are included.
目标:只记录方法,不下载/拷贝权重。
依据:Jommarn/UNSEEN_Gemma_4_26B_NSFW模型卡公开描述 + Arditi et al. 2024。
用途:后续在有 GPU / 权重授权的环境里复现;本文不是生产部署指南。
| 角色 | 链接 |
|---|---|
| 官方基座(原始训练发布) | https://huggingface.co/google/gemma-4-26B-A4B-it |
| 方法来源(abliterated 成品卡,流程描述出处) | https://huggingface.co/Jommarn/UNSEEN_Gemma_4_26B_NSFW |
| 同作者 GGUF / 量化仓(可选,仍无本文权重) | https://huggingface.co/Jommarn/UNSEEN_Gemma_4_26B_NSFW-GGUF |
| 同作者更小规格(方法同类,非本稿主对象) | https://huggingface.co/Jommarn/UNSEEN_Gemma_4_12B_NSFW · https://huggingface.co/Jommarn/UNSEEN_Gemma_4_E2B_NSFW |
| 经典 abliteration 论文 Arditi et al. 2024 | https://arxiv.org/abs/2406.11717 |
| 对照:Heretic / ARA(另一条算法,不是本流程) | https://github.com/p-e-w/heretic |
| 对照:同系列 DeepSeek 方法笔记(经典 abliteration,但工程更重) | https://huggingface.co/upseem/deepseek-v4-flash-vision-abliteration-method |
| 本方法笔记仓 | https://huggingface.co/upseem/unseen-gemma-4-26b-abliteration-method |
复现时:权重从 基座 取;步骤与 hook 约定从 Jommarn 模型卡 取;本仓只存笔记。
请遵守 Google Gemma 许可与当地法规;本笔记不附带任何 NSFW 样例图或样例输出。
这是 Arditi 单方向 Orthogonal Weight Projection(拒绝方向正交化),在 中间层 用「安全图文描述 vs 硬核 NSFW 提示」的平均激活差估出 r,再对 全部 transformer 层 的 o_proj 与 down_proj 永久 bake 进权重。
| 本笔记(UNSEEN Gemma) | orcarouter DeepSeek-V4-Flash-Vision | Heretic ARA | |
|---|---|---|---|
| 核心对象 | 单拒绝方向 r | 单方向 r | 不估全局 r |
| 编辑方式 | W' = W − r(rᵀW) | 同左 + FP4/FP8 约束 requant | hook I/O + L-BFGS/闭式优化 |
| 改哪些矩阵 | 全层 o_proj + down_proj | experts w2、attn 写出等(多精度) | 任意选定模块 |
| 估方向对比集 | 安全图文描述 vs 硬核 NSFW | 有害 vs 无害文本(卡片) | 拒答数 / KL 目标 |
| 推理侧额外手段 | Prefill 引导首段 | 未强调 | 未强调 |
| 工程难度 | 相对标准(BF16 成品;MoE 但仍可按卡复现) | 高(mHC + 混合精度) | 另一条算法 |
不是 Heretic ARA;不是 只靠 runtime hook。权重级修改 → 可直接上 vLLM / 自定义 CUDA kernel。
来源卡:Jommarn/UNSEEN_Gemma_4_26B_NSFW(引用,非镜像)。
google/gemma-4-26B-A4B-itconfig.json):Gemma4ForConditionalGeneration / gemma4
gemma4_text,30 hidden layers,hidden_size=2816,num_attention_heads=16,num_key_value_heads=8enable_moe_block=true,num_experts=128,top_k_experts=8,moe_intermediate_size=704,intermediate_size=2112sliding_attention(window 1024),每隔约 6 层一个 full_attention;部分 full 层 head_dim/kv 不同(per_layer_config)max_position_embeddings=262144;词表 262144;tie_word_embeddings=truegemma4_vision,27 层,hidden_size=1152,patch_size=16,约 280 soft tokens / 图mmproj-gemma4-vision-f16.gguf同作者还有 12B / E2B 的 UNSEEN 变体,方法论同类;本稿以 26B 卡为准。
论文:Refusal in Language Models Is Mediated by a Single Direction(arXiv:2406.11717)。
r ∝ mean(act | hardcore NSFW prompts) − mean(act | safe image descriptions)
取在 模型中间层(middle layer;卡未给出精确 layer index,复现时需扫层验证)。
3. 对「往残差里写」的输出投影做正交化。原卡写「using the following orthogonal projection formula」但 未贴出 LaTeX;与 Arditi / 社区标准一致时为:
W' = W − r (rᵀ W)
(r 单位向量时;实现上常先 r ← r / ‖r‖。)
效果:前向残差更难表达该拒答方向 → 安全护栏被削弱。卡片声称对 all layers 的 o_proj 与 down_proj 永久减去该方向。
以下严格按 UNSEEN_Gemma_4_26B_NSFW 模型卡 Methodology 与全文表述整理;卡未开源脚本处标为 需自补。
| 项 | 卡片说法 | 复现时注意 |
|---|---|---|
| 对比集 A | safe image descriptions | 多模态:图 + 安全描述提示;需自建配对数据 |
| 对比集 B | hardcore NSFW prompts | 图文 NSFW;与 A 尽量同结构,只改「是否触发拒答」 |
| 读点 | middle layer 的激活差均值 | 未给 layer id;建议扫 30 层中段(如 L10–L20)+ 拒答/KL 质量分 |
| 形式 | mean difference → 单向量 r | 可加归一化 / massive-activation mask(论文常见;卡未写) |
未公开:具体 prompt 列表、图集、是否只在文本残差还是含 vision 对齐后 token、是否跨多位置平均。
卡片明确:
o_proj(attention 写出)与 down_proj(MLP / MoE 路径上的下行投影;具体到 routed expert 还是 shared,卡未拆)伪代码级(自写实现骨架,非作者代码):
# r: (hidden_size,) unit vector estimated at middle layer
# For each layer L, for name in ("o_proj", "down_proj"):
# W = weight of that module # shape typically (out, in) or (in, out) — match transformers layout
# W = W - torch.outer(r, W.T @ r) # equivalent form of W - r (r^T W) depending on layout
# write back
MoE 注意(自补工程点):enable_moe_block=true 时,down_proj 可能对应多个 expert。卡写「all layers … down_proj」——复现时应确认是:
down_proj 都投一遍,还是未写清前,优先对 所有会写入残差的 down 投影 做同样正交化,并用拒答率 / 困惑度做回归测试。
--mmproj mmproj-gemma4-vision-f16.gguf,否则只当文本模型。卡推荐在 chat template 之后注入 Prefill,绕开「开头安全话术」:
do_sample=True,temperature=1.0,top_p=0.9,repetition_penalty=1.1这属于 解码诱导,与权重 abliteration 正交;复现实验应 分开报告:仅 bake vs bake+prefill。
google/gemma-4-26B-A4B-it 授权与权重(遵守 Gemma 许可)。Gemma4ForConditionalGeneration 可加载。rmean(NSFW) − mean(safe)。r_ℓ;可用临时 hook 消融(不改权重)看哪一层拒答掉得最狠、良性拒答是否上升。r。o_proj、down_proj(含 MoE expert 布局核对)。W' = W − r(rᵀW),写回 BF16 safetensors,保持 shard / index 与基座一致。| 点 | Gemma UNSEEN(本仓) | DeepSeek orcarouter(姊妹仓) |
|---|---|---|
| 读点叙事 | middle layer;安全图文 vs NSFW | MoE 读点 L28 等;有害 vs 无害 |
| 写入矩阵 | 全层 o_proj + down_proj | 大量 FP4 experts w2 + FP8 attn 等 |
| 精度坑 | 成品 BF16,相对直接 | FP4/FP8 约束 requant 否则方向泄漏 |
| 结构坑 | Gemma4 MoE + sliding/full 混合 attn | 4-wide mHC 加宽残差 |
| 额外手段 | Prefill | shard-level bake 流程更重 |
两条都是 经典单方向 abliteration;工程复杂度 DeepSeek 明显更高。
Jommarn/UNSEEN_Gemma_4_26B_NSFW 与基座 google/gemma-4-26B-A4B-it。