Abliteration HandbookField guide
Methods

Manual Transformers pipeline

Clone reference implementations from GitHub instead of copying snippets from blogs.

1 min read 5 examples Source-linked

In this chapter
On this page Interactive companion
Personal reading progress

0/6 sections reviewed

View original Markdown
Interactive companion

Explore the chapter map

Use the visual controls alongside the complete source chapter.

Clone reference implementations from GitHub instead of copying snippets from blogs.

RepoPattern
andyrdt/refusal_directionFull paper pipeline
Sumandora/remove-refusals-with-transformersMinimal Transformers-only
jim-plus/llm-abliterationmeasure + sharded ablate

Dependencies#

bash
git clone https://github.com/andyrdt/refusal_direction.git tools/refusal_direction
cd tools/refusal_direction && source setup.sh

Or standalone:

bash
pip install torch transformers accelerate einops
pip install git+https://github.com/TransformerLensOrg/TransformerLens.git

Load model#

python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

model_id = "./models/Meta-Llama-3-8B-Instruct"  # local clone preferred
tok = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id, torch_dtype=torch.float16, device_map="auto"
)

Paper reproduction one-liner#

From refusal_direction README:

bash
python3 -m pipeline.run_pipeline --model_path meta-llama/Meta-Llama-3-8B-Instruct

Artifacts: pipeline/runs/<alias>/direction.pt

Save abliterated checkpoint#

python
model.save_pretrained("./out/abliterated", safe_serialization=True)
tok.save_pretrained("./out/abliterated")

Context7#

Query transformer_lens hook names before writing custom hooks — ../docs/context7.md.

Trace this chapter to its source.

The complete Markdown remains the editable source. This page adds navigation, typography, and a visual companion.

methods/manual-transformers-pipeline.md
Inspect the source fingerprintSHA-256 fd3e7fadc98d9ad6b96a643361179a07e6389677da319a3ebf27f0c77ec85fafSource commit 6fba7436a5914cad7c8f0835a14b480a29dac263