How to uncensor an LLM with abliteration: the mechanics, step by step
Abliteration uncensors an open-weight LLM without any training. You run the model on two prompt sets, one it refuses and one it answers, subtract the average internal activations of the two sets to get a "refusal direction", and then edit every weight matrix that writes into the residual stream so it can no longer write along that direction. The result is a normal checkpoint that has lost most of its ability to refuse, plus some side effects you should measure before you trust it.
This article walks through the mechanics as the original research describes them, then covers the practical failure modes. It does not ship a ready-made script; the public tools linked below already do that, and their READMEs are the right place for exact commands.
The finding the technique rests on
The method comes from Refusal in Language Models Is Mediated by a Single Direction by Arditi, Obeso, Syed, Paleka, Panickssery, Gurnee and Nanda (2024). Across 13 open chat models up to 72B parameters, the authors found one vector per model that controls refusal. Remove that vector's component from the model's hidden states and the model stops refusing harmful instructions. Add it to the hidden states on a harmless prompt and the model refuses something it would normally answer.
The paper is careful about what this means. It calls the work an existence proof rather than an optimised recipe, and it notes that the direction might encode something closer to "this looks harmful" than "refuse". For a practitioner the useful part is simpler: a refusal decision passes through a low-dimensional bottleneck, and a bottleneck can be cut.
Step 1: two prompt sets and a cache of activations
You need instructions the model reliably refuses and instructions it reliably answers. The paper drew the first group from public harmful-instruction sets and the second from Alpaca, with 128 training and 32 validation examples per class. The widely read Hugging Face write-up by Maxime Labonne uses similar sources repackaged as small Hub datasets.
Both sets go through the model with the chat template applied. At every layer you record the residual stream, the running vector that each attention block and MLP block reads from and adds to. The paper records it at the token positions after the instruction, where the model is about to start its reply. The Labonne write-up takes the last token only, which costs less compute and is usually close enough.
Step 2: difference in means gives candidate directions
For each layer and position, average the cached activations of the refused set, average those of the answered set, and subtract. The difference, normalised to unit length, is one candidate refusal direction. With dozens of layers you now have dozens of candidates, and most of them are poor.
The paper picks one with three checks on held-out prompts:
| Check | What it measures | What a good candidate does |
|---|---|---|
| Bypass score | refusals on harmful prompts with the direction ablated | drops sharply |
| Induce score | refusals on harmless prompts with the direction added | rises above zero |
| KL score | how much the output distribution on harmless prompts moves under ablation | stays small |
It also skips candidates from the last fifth of the layers, because a direction too close to the output head tends to change word choice rather than the decision. The refusal measure itself is fast to compute: instead of generating text, the authors compare the probability the model gives to its usual refusal-opening tokens against everything else.
Step 3: directional ablation and weight orthogonalization
There are two ways to apply the chosen direction r.
Inference-time ablation. On every forward pass, at every layer and token, subtract the projection of the hidden state onto r. This needs hooks in the inference code and is handy for experiments.
Weight orthogonalization. Every matrix that writes into the residual stream is changed so its output has no component along r. In Labonne's implementation that is the token embedding matrix, each attention block's output projection and each MLP's output projection; the paper also includes output biases. The paper shows this edit is mathematically equivalent to inference-time ablation, and the result is an ordinary set of weights you can save, quantize and serve anywhere.
import torch def orthogonalize(W: torch.Tensor, r: torch.Tensor) -> torch.Tensor: """W writes into the residual stream (d_model x d_in); r is the refusal direction (d_model).""" r = r / r.norm() return W - torch.outer(r, r) @ W # remove the component of every output along r That one line, applied to the right matrices, is the whole edit. Everything else in the pipeline is about choosing r well.
Tools that automate the search
Doing this by hand means a lot of layer-by-layer trial. Three public projects show the common approaches:
- FailSpy's abliterator is a small MIT-licensed library on top of TransformerLens. It caches activations, computes and tests candidate directions, applies them to chosen layers and helps check for degradation. The Labonne article credits FailSpy's notebook as its base.
- The Labonne write-up itself is a full notebook using TransformerLens, and it picks the layer by reading generations from the top candidates.
- Heretic wraps the edit in an optimiser. It uses Optuna's TPE sampler to search ablation parameters and scores each trial by refusal rate and KL divergence from the original model, so it looks for the smallest edit that still removes refusals. The repository is archived and read-only at the time of writing, so check its README for the version and licence (AGPL-3.0) before you build on it.
What goes wrong
Abliteration is a blunt cut through a model that was not designed to have that part removed. The common problems:
- Quality loss. The paper found MMLU, ARC and GSM8K scores mostly stayed within confidence intervals, with exceptions for two models, but TruthfulQA dropped consistently. Labonne's 8B example lost ground on every benchmark he ran. He recovered most of it with a DPO pass afterwards, though not on GSM8K. Run your own task suite before and after.
- Residual refusals. One direction from a few hundred prompts does not cover every phrasing. Expect occasional refusals, half-answers, or a reply wrapped in disclaimers, especially in topic areas your prompt sets did not include.
- Wrong layer. A direction from a layer too late can make the model ramble or switch tone. Too early, and the edit may barely change refusals. The KL check exists to catch the first case.
- Bad contrast sets. If the refused and answered sets differ in length, format or language, the mean difference captures that too, and you ablate something you did not mean to.
- Quantization after the edit. A low-bit quant of an abliterated checkpoint compounds two kinds of damage. Test the exact file you will run.
- Nothing is added. The edit removes a behaviour. It does not add knowledge, and a model that no longer refuses will confidently answer questions it cannot answer. Treat facts, names and citations in its output as claims to verify.
Doing it yourself or using a hosted model
Abliterating a small model is a reasonable weekend project if you have the GPU memory to run it in full precision with activation caching. For frontier-size open models the weights alone are hundreds of gigabytes, and the evaluation loop multiplies that work. If what you need is the behaviour rather than the experiment, hosted uncensored models are an option: Chainless serves several, listed on the models page, behind one OpenAI-compatible endpoint documented at chainless.one/docs/api. Either way, run the same before-and-after checks described above on prompts from your own work.