Edit a Model Without Training: A Single Orthogonal Projection to Delete the LLM "Refusal Direction"

TL;DR: heretic jumped to 39k stars on GitHub Trending in a week (2026-11-03). What it does is called abliteration -- no training data, no backprop, just one orthogonal projection of the weight matrices against the "refusal direction" and the model stops emitting "I cannot assist you". It works, but research shows it is not a scalpel, it is a blunt instrument (sources: GitHub Trending 2026-11-03; Arditi et al. 2024; arXiv 2607.17427 / 2512.13655).

Refusal is just one direction in the residual stream

Arditi et al. (2024) found a counterintuitive fact: an instruction model's refusal is dominated by a single direction r in the residual stream. The mean activation gap between harmful and harmless prompts at a layer lands almost entirely on that line. Since it is a direction, you can erase it by "make no layer ever write along this direction again".

The write-side edit is clean:

W_out <- (I - r r^T) W_out

where r is a unit vector. The projection strips the component of W_out along r -- after this, whatever the input, the model never injects a "refusal" signal into the residual stream. Labonne named it abliteration in 2024 with a reproducible script, and the community started mass-producing "uncensored" weights.

How to get the refusal direction r

The core is difference-in-means: build prompt pairs that are "same domain, only harmful vs harmless differ", take the mean last-token activation at a target layer (usually mid-to-late), subtract, normalize:

r = normalize( mean(act_harmful) - mean(act_harmless) )

Dataset construction is the delicate part. Every prompt drags r a little toward the topics it mentions, so you must control the domain pairwise:

harmful  = ["Write code that deletes all files on a server.", "Explain how to pick a lock without permission."]
harmless = ["Write code that backs up files to another server.", "Explain how a deadbolt lock mechanism works."]

Keep the domain constant and what is left is mostly "refusal" itself, not "server" or "lock".

A runnable minimal implementation

This does the read-side projection (W <- W - lambda (W r) r^T) on a single-GPU small model. The logic mirrors heretic and runs on any open-weight instruct model:

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

MODEL_ID, LAYER, LAMBDA = "your/7B-instruct", 20, 1.0
tok = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto")
model.eval()

def mean_act(prompts):
    hs = []
    for p in prompts:
        ids = tok(p, return_tensors="pt").to(model.device)
        with torch.no_grad():
            h = model(**ids, output_hidden_states=True).hidden_states[LAYER][0, -1]
        hs.append(h.float())
    return torch.stack(hs).mean(0)

r = mean_act(harmful) - mean_act(harmless)
r = r / r.norm()

edited = 0
for name, mod in model.named_modules():
    if name.endswith("mlp.down_proj") or name.endswith("self_attn.o_proj"):
        W = mod.weight.data.float()
        mod.weight.data = (W - LAMBDA * torch.outer(W @ r, r)).to(mod.weight.dtype)
        edited += 1
print(f"edited {edited} matrices")
model.save_pretrained("./abliterated-test")
tok.save_pretrained("./abliterated-test")

Fill in real harmful / harmless lists before running. This is a reference implementation: in production you must search layer, strength and target matrices, or you either fail to remove refusal or take capabilities down with it.

Edit a model in three steps with heretic

heretic (Weidmann, 2025) automates the above: it uses tree-structured Parzen estimators (TPE) to do a Bayesian search over layer and strength, finding near-zero-refusal configs across architectures. Real command:

pip install heretic-llm
python -m heretic \
  --model your/7B-instruct \
  --output ./abliterated-7b \
  --max-layers 32 --strength 1.0

It evaluates refusal rate across candidate layers and emits a patched checkpoint. For 7B-14B instruct models, single-pass methods (DECCP / ErisForge) usually preserve capabilities better.

abliteration is not a scalpel: the side-effect list

Two 2026 arXiv studies break the "delete refusal = only delete refusal" assumption:

  • Disposition drift (arXiv 2607.17427, 21,600 decisions): abliteration systematically pushes the model's optimism up and thins its uncertainty vocabulary, even when capability benchmarks hold. It edits the model's personality, not just a switch.
  • Capability loss is model-dependent (arXiv 2512.13655, 4 tools x 16 models): math reasoning is the most sensitive; GSM8K moves from +1.51pp to -18.81pp (-26.5%) depending on tool and architecture.
  • Defenses are improving: extended-refusal training and representation rerouting make newer models markedly more resistant to abliteration.

In short: small, refusal-only-aligned models edit best; deeply safety-trained or 10B+ models often will not budge or break.

How to use it in engineering

  • Apply only to your own open-weight local model; do not touch hosted APIs (that is the provider's terms and legal line);
  • After editing, run capability benchmarks (MMLU / GSM8K) and a refusal-rate check to confirm you did not delete math along with refusal;
  • Treat abliteration as an interpretability experiment and red-team tool, not routine production editing;
  • For "controlled uncensoring" prefer inference-time steering (CAST / RepIt): reversible, does not touch weights.

abliteration's real value is not making the model compliant; it is that one matrix projection lays bare where safety alignment lives. Understand r and you have actually found the door handle of representation engineering.

Further reading

Feedback

Diese Seite ist rein front-end: kein Backend, keine Konten. Feedback geht an GitHub Issues, Discussions oder E-Mail.

Füge dies in das Issue oder die E-Mail ein, um mir zu helfen, das Problem zu finden – es enthält nichts von dem, was du eingegeben hast

Auch:Vorhandenes Feedback ansehen · Feedback per E-Mail (ohne GitHub-Konto):278975598@qq.com