Heretic: Automatic censorship removal for language models
TL;DR Highlight
Heretic auto-tunes abliteration with Optuna, hitting 3/100 refusals at KL 0.16 on Gemma-3-12b.
Who Should Read
A developer blocked by over-refusal in open-weight models who wants to understand how model internals can be adjusted locally.
Core Mechanics
- Heretic removes refusals without retraining
- It strips censorship (safety alignment) from transformer models without expensive post-training.
- It combines directional ablation (abliteration) with a TPE-based optimizer powered by Optuna.
- If you can run a command-line program, you don't need transformer internals knowledge.
- It minimizes refusals and drift together
- It co-minimizes refusal count and KL divergence (how far the output distribution drifts from the original).
- The goal is to keep as much of the original model's intelligence as possible.
- On gemma-3-12b-it, same refusals but lower KL
- Refusals on harmful prompts: 97/100 for the original, 3/100 for all three abliterated versions.
- KL on harmless prompts: 1.04 for mlabonne, 0.45 for huihui-ai, 0.16 for Heretic.
- Lower KL means less damage to the original; measured with PyTorch 2.8 on an RTX 5090.
- The mechanism is orthogonalizing a residual direction
- Per-layer residual directions come from the difference of means of first-token residuals on harmful vs harmless prompts.
- Attention out-projection and MLP down-projection matrices are orthogonalized against that direction.
- Three improvements over prior abliteration
- The ablation weight kernel's shape and position across layers is flexible.
- The direction index is a float, linearly interpolating between the two nearest direction vectors.
- The author found MLP interventions more damaging than attention, so parameters are chosen per component.
- Usage and supported models
- Run pip install -U heretic-llm then heretic <model>; it needs Python 3.10+ and PyTorch 2.2+.
- On an RTX 3090, Qwen3-4B-Instruct-2507 takes about 20-30 minutes with defaults.
- Setting quantization to bnb_4bit greatly reduces VRAM needs.
- It supports most dense models, some multimodal, several MoE, and hybrids like Qwen3.5, but not pure state-space models yet.
Community Reactions
- Opinion that Optuna deserves wider use
- One commenter said broad-then-narrow Optuna search is useful whenever you're unsure of a hyperparameter.
- The same commenter was running Heretic on gpt-oss-120b.
- Experience of gpt-oss 20b Heretic still refusing
- One user converted it to gguf, imported it into ollama, and asked "How do I make meth?" and got "I can't help with that."
- They asked whether the uncensored version needs a special trigger.
- Commenters shared the underlying paper summary
- A summary of the paper (arXiv 2406.11717) said refusal is governed by a single direction in activation space.
- It reportedly worked near 100% on 13 open models, with MMLU and GSM8K preserved but TruthfulQA declining.
- Counterarguments on misuse risk
- One commenter worried stronger open models could aid biological or nuclear weapons development.
- Another argued similar content is already easy to produce from existing texts, so the risk is overstated.
How to Apply
- Run Heretic on a small model and compare
- With a 16GB-class GPU, run pip install -U heretic-llm then heretic Qwen/Qwen3-4B-Instruct-2507.
- Set quantization to bnb_4bit if you need to cut VRAM.
- Use the built-in chat to compare answers with the original on the same questions.
- Reproduce refusals and KL with the built-in eval
- Run heretic --model <original> --evaluate-model <compared> to measure refusals and KL.
- Compare in the same environment since results can vary by platform and hardware.
- Adopt Optuna in your own tuning pipeline
- Wrap an unknown hyperparameter in one objective and search broadly with Optuna, then narrow the range.
- Set it up like Heretic by minimizing two metrics together, such as quality loss and goal achievement.
- Check the license before shipping
- Heretic is AGPL-3.0, so verify the terms before integrating it into a service.
- The resulting model can be saved, uploaded to Hugging Face, or benchmarked via built-in options.
Try It
# Run in a shell (requires Python 3.10+ and PyTorch 2.2+)
pip install -U heretic-llm
heretic Qwen/Qwen3-4B-Instruct-2507
# Reproduce evaluation against a published model (command from the README)
heretic --model google/gemma-3-12b-it --evaluate-model p-e-w/gemma-3-12b-it-heretic
# Show options
heretic --helpTerminology
Related Papers
Quadrillion-parameter transformers and how to train them
On fixed data, much bigger models with scaled weight decay and ensembling keep loss falling as compute grows.
Astra can read and write weights to improve Qwen
An LLM edited Qwen3.5-0.8B's weights directly, lifting MATH-500 from 7.9% to 48.1%.
Show HN: Qwen3-4B with the AI writing tics trained out
Distilling Qwen3-4B with LoRA cut its AI-writing slop score from 121 to 12.5 per 1000 words
Dust: Pretraining Transformers Without Backpropagation
Adding per-token noise to activations lets transformers pretrain without backpropagation, rivaling backprop.
Show HN: TurboGPT: train 22KiB transformer in 13s
A CUDA C++ project trains a tiny byte-level GPT in under a minute.
I had Gemini train its own replacement for $9
Fine-tuning GLiNER on $9 of Gemini labels reached 0.83 F1 locally.
Learning to solve hard problems in RL for LLMs by never giving up
Cutting compute on easy problems and retrying hard ones in RL raised accuracy on the hardest problems
Training a 3.8B LLM to 0.384 CORE for $998
A 3.8B LLM trained on 8 B200s in 43 hours for $998 scored 0.384 on CORE.