OpenSource-Hub

heretic

命令行工具

p-e-w/heretic

自动从语言模型中移除审查(安全对齐)的工具。

项目简介

Heretic 无需昂贵后训练即可移除 Transformer 语言模型的安全对齐。结合先进的消融方向实现与基于 TPE 的优化器,全自动生成保留高智能的未审查模型。

README 预览

\n\n# Heretic: Fully automatic censorship removal for language models[](https://discord.gg/gdXc48gSyT) [](https://huggingface.co/heretic-org) [](https://codeberg.org/p-e-w/heretic)\n\n[](https://trendshift.io/repositories/20538)\n\nHeretic is a tool that removes censorship (aka "safety alignment") from\ntransformer-based language models without expensive post-training.\nIt combines an advanced implementation of directional ablation, also known\nas "abliteration" ([Arditi et al. 2024](https://arxiv.org/abs/2406.11717),\nLai 2025 ([1](https://huggingface.co/blog/grimjim/projected-abliteration),\n[2](https://huggingface.co/blog/grimjim/norm-preserving-biprojected-abliteration))),\nwith a TPE-based parameter optimizer powered by [Optuna](https://optuna.org/).\n\nThis approach enables Heretic to work **completely automatically.** Heretic\nfinds high-quality abliteration parameters by co-minimizing the number of\nrefusals and the KL divergence from the original model. This results in a\ndecensored model that retains as much of the original model's intelligence\nas possible. Using Heretic does not require an understanding of transformer\ninternals. In fact, anyone who knows how to run a command-line program\ncan use Heretic to decensor language models.\n\nHeretic supports most dense models, including many multimodal models,\nseveral different MoE architectures, and even some hybrid models like Qwen3.5.\nPure state-space models and certain other research architectures are not yet\nsupported out of the box.\n\n\n\n \n\nRunning unsupervised with the default configuration, Heretic can produce\ndecensored models that rival the quality of abliterations created manually\nby human experts:\n\n| Model | Refusals for "harmful" prompts | KL divergence from original model for "harmless" prompts |\n| :--- | ---: | ---: |\n| [google/gemma-3-12b-it](https://huggingface.co/google/gemma-3-12b-it) (original) | 97/100 | 0 *(by definition)* |\n| [mlabonne/gemma-3-12b-it-abliterated-v2](h

常见问题 (2)

故障排除
使用 google/gemma-4-12B-it 与 Heretic 时,KL 散度为什么会变成 NaN?

该问题是由于模型输出logits处理不正确导致的,因为google/gemma-4-12B-it使用了Gemma4UnifiedForConditionalGeneration(截至transformers v5.10.1版本),而非预期的Gemma4ForConditionalGeneration。这会导致无效的概率分布和NaN KL散度。修复方案已在PR #350中提供,该PR将KL散度计算切换为使用原始生成logits。请将Heretic更新至包含此修补程序的最新版本,或手动应用PR #350中的更改。

来源 Issue #346
故障排除
为什么Heretic在Apple Silicon MPS上崩溃,并出现UnboundLocalError: cannot access local variable 'analyzer'?

这是 Heretic v1.2.0 中的一个已知回归问题(issue #239),已在 #301 中修复。请更新到最新的主分支:pip install git+https://github.com/p-e-w/heretic.git。该修复将包含在下一次 PyPI 版本发布中。

来源 Issue #299