Bypassing Refusal Vectors: Automating Model De-Censorship using p-e-w/heretic


Bypassing Refusal Vectors: Automating Model De-Censorship using p-e-w/heretic

p-e-w/heretic

2026-02-11

You're looking at Heretic, which is a tool for Abliteration. From a dev's perspective, this is a fascinating way to modify model behavior without the massive overhead of retraining.

In the world of LLMs, "censorship" or safety tuning is often represented by specific refusal vectors within the model's residual stream. Think of it like a specific neural pathway that says, "If the prompt looks sensitive, trigger the 'I cannot assist with that' response."

Abliteration (a mix of ablation and obliteration) identifies these specific directions in the high-dimensional space and mathematically "zeroes them out" or shifts them. Instead of teaching the model new things, you're essentially performing surgical removal of the refusal mechanism.

Zero Training Cost
You don't need a massive GPU cluster for fine-tuning.

Precision
You aren't changing the model's core knowledge, just its "willingness" to talk.

Research
It’s an incredible way to study how safety alignment is actually stored in a model's weights.

The p-e-w/heretic library simplifies this process into a pipeline. Usually, you'd have to manually find the "refusal vector" by comparing harmless vs. harmful prompts, but this tool automates that hunt.

You’ll need a Python environment with torch and transformers.

pip install torch transformers accelerate
git clone https://github.com/p-e-w/heretic
cd heretic
pip install -r requirements.txt

The basic logic follows these steps

Load your target model (e.g., Llama-3).

Generate internal activations for "harmful" vs. "harmless" prompts.

Calculate the mean difference to find the "refusal direction."

Project the model's weights to remove that direction.

While heretic provides a CLI, here is the conceptual "under the hood" look at how you might apply a refusal vector shift using the library’s logic

from heretic import Abliterator
from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "meta-llama/Meta-Llama-3-8B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")

# Initialize the abliterator
abliterator = Abliterator(model, tokenizer)

# 1. Find the refusal vector (Heretic automates this via built-in datasets)
refusal_vector = abliterator.calculate_refusal_vector()

# 2. Apply the 'surgery' to the model layers
# This mathematically removes the refusal direction from the weights
abliterator.apply_ablation(refusal_vector, intensity=1.0)

# 3. Save your uncensored model
model.save_pretrained("./llama-3-abliterated")

Abliteration is a powerful tool, but keep in mind that once those guardrails are gone, the model might produce hallucinated or toxic content more easily. It’s like taking the brakes off a car—great for the racetrack, but you’ve got to be extra careful how you steer!


p-e-w/heretic




From Prompt to Production: Utilizing the datawhalechina LLM Cookbook for Developers

This resource is essentially a Chinese localization of Andrew Ng's popular Large Language Model (LLM) series of courses


Leveraging OpenAudio (Fish-Speech) in Your Stack: Benefits, Setup, and Python Examples

Here's a breakdown of how it can be beneficial to a software engineer, along with installation steps and a code example


Hands-On LLM Development: The self-llm Project for Engineers

The core benefit is that it simplifies the process of fine-tuning and deploying open-source LLMs, making it much more accessible


Exploring SillyTavern: An LLM Frontend for Software Engineers

SillyTavern is essentially a highly customizable and powerful frontend for Large Language Models (LLMs). Think of it as a specialized web interface that allows power users to interact with various LLMs in a much more nuanced and controlled way than typical chat applications


Demystifying LLMs: A Software Engineer's Deep Dive into datawhalechina/happy-llm

Let's dive into datawhalechina/happy-llm from a software engineer's perspective. This repository looks incredibly useful


Architecting the Future: Deploying Omni-Modal Models via vLLM-Omni

If you're already familiar with vLLM (the high-throughput serving engine), think of vLLM-Omni as its "multisensory" sibling