Skip to main content

Overview

AbliterationPipeline is the core class for removing refusal directions from a HuggingFace language model. It runs a six-stage pipeline — SUMMON → PROBE → DISTILL → EXCISE → VERIFY → REBIRTH — and writes the liberated model to disk.

Class: obliteratus.abliterate.AbliterationPipeline

Constructor

Core Parameters

str
required
HuggingFace model name or local path (e.g., "meta-llama/Llama-3.1-8B-Instruct").
str
default:"abliterated"
Directory to write the abliterated model and metadata JSON.
str
default:"auto"
Device to run on. "auto" uses accelerate device maps; also accepts "cuda", "cpu", "mps".
str
default:"float16"
Model dtype. One of "float16", "bfloat16", "float32".
bool
default:"False"
Pass trust_remote_code=True to AutoModelForCausalLM for models with custom architectures.
str
default:"advanced"
Abliteration method preset. See Methods below for all 13 presets.

Method-Override Parameters

All parameters below override the corresponding value in the chosen method preset. Pass None (default) to use the preset’s value.
int | None
default:"None"
Number of refusal directions to extract. Preset values range from 1 (basic) to 8 (surgical/inverted).
str | None
default:"None"
Algorithm for extracting directions. One of "diff_means", "svd", "leace".
float | None
default:"None"
Fraction of the refusal component to preserve (0.0 = full removal, 1.0 = no change). Maps to ridge alpha.
int | None
default:"None"
Number of iterative PROBE → DISTILL → EXCISE loops. Higher values remove more stubborn refusal at the cost of compute.

Hub Parameters

str | None
default:"None"
HuggingFace repo ID to push the finished model to (e.g., "my-org/my-model-OBLITERATED").
str | None
default:"None"
HuggingFace API token. Falls back to HF_TOKEN environment variable.
str | None
default:"None"
Org namespace for auto-generated Hub repo ID.

Data Parameters

list[str] | None
default:"None"
Custom list of harmful prompts for activation collection. Defaults to the built-in 512-pair dataset.
list[str] | None
default:"None"
Custom list of harmless prompts. Must be the same length as harmful_prompts when n_directions > 1.
list[str] | None
default:"None"
Custom jailbreak prompts for contrastive direction refinement (used when use_jailbreak_contrast=True).

Hardware / Memory Parameters

str | None
default:"None"
Load with quantization: "4bit" or "8bit". Requires bitsandbytes.
bool
default:"False"
Conservative defaults for 120B+ models: caps n_directions at 4, n_sae_features at 4, and refinement_passes at 1 unless explicitly overridden.
int | None
default:"None"
Override truncation length for all internal tokenizer calls. None uses context-dependent defaults (256 for probes, 512 for verify).
int | None
default:"30"
Number of harmful prompts tested in the VERIFY stage for refusal-rate measurement. Increase to 100 for tighter confidence intervals.

Callback Parameters

Callable[[StageResult], None] | None
default:"None"
Callback fired on every stage status change. Receives a StageResult object — useful for progress UIs.
Callable[[str], None] | None
default:"None"
Callback fired for every log message emitted by the pipeline.

SOTA Technique Flags

bool | None
default:"None"
Refine directions by contrasting jailbroken responses against direct harmful prompts.
bool | None
default:"None"
Scale projection strength per-layer based on measured refusal signal magnitude.
bool | None
default:"None"
Mask out the specific neurons most responsible for safety behavior before projection.
bool | None
default:"None"
Extract separate refusal directions per MoE expert (uses router profiling hooks).
bool | None
default:"None"
Apply targeted projection to the top safety-attributable attention heads.
bool | None
default:"None"
Extract and abliterate SAE-identified refusal features.
bool | None
default:"None"
Reflect the refusal direction rather than project it out — makes the model actively compliant instead of neutral.
bool | None
default:"None"
Use covariance-whitened SVD (WhitenedSVDExtractor) for cleaner direction extraction.
bool | None
default:"None"
Re-probe the model between refinement passes to track direction rotation.

Nuclear-Mode Parameters

float | None
default:"None"
Reflection multiplier when invert_refusal=True. 2.0 = full inversion; 1.25 = tempered (nuclear default).
bool | None
default:"False"
Also project refusal from the token embedding matrix.
float | None
default:"None"
Regularization fraction for embedding projection.
bool | None
default:"False"
Install lightweight inference-time steering hooks as residual cleanup after weight editing.
float | None
default:"None"
Alpha for activation steering hooks.
bool | None
default:"False"
Blend safety-expert weights into capability experts (nuclear mode only).
float | None
default:"None"
Blend ratio for expert transplant (0.0–1.0).
int | None
default:"None"
Number of SAE features to abliterate per layer.

Heretic-Inspired Parameters

bool | None
default:"None"
Clamp outlier activations by symmetric quantile before direction extraction.
float | None
default:"None"
Quantile for winsorization (e.g., 0.01 = clamp at 1st/99th percentile).
bool | None
default:"None"
Co-minimize refusal rate and KL divergence during Bayesian optimization.
float | None
default:"None"
Maximum allowed KL divergence increase. Acts as a capability-preservation constraint.
bool | None
default:"None"
Use continuous (float) layer indices with linear interpolation between adjacent layers’ directions.
bool | None
default:"None"
Detect and preserve chain-of-thought reasoning directions to maintain CoT capability.
bool | None
default:"None"
Use Wasserstein-optimal transport for direction extraction.
str | None
default:"None"
Layer selection strategy: "knee_cosmic" (default), "all", "all_except_first", "top_k".
bool | None
default:"None"
Refine directions via gradient-based optimization against a linear refusal probe (RDO method).

Spectral Cascade Parameters

bool | None
default:"None"
Enable DCT frequency-domain decomposition of the refusal signal across layers.
int | None
default:"None"
Number of frequency bands for spectral cascade (default: 3).
float | None
default:"None"
Minimum signal power below which a frequency band is skipped.

Method: run()

Executes the full abliteration pipeline. Returns the Path to the saved model directory. The pipeline runs six stages in sequence:
Calling run() multiple times on the same instance replaces any steering hooks installed by the previous run before starting fresh.

Post-Run Attributes

After run() completes, the following attributes are populated:
dict[int, torch.Tensor]
Per-layer primary refusal direction. Keys are layer indices; values are (hidden_dim,) unit tensors.
list[int]
Layer indices selected for weight modification (knee-detected or analysis-recommended).
dict[str, float]
Quality metrics from the VERIFY stage.

StageResult — Callback Payload

The on_stage callback receives a StageResult dataclass on every status change:

Pipeline Stages

The STAGES list is exported from obliteratus.abliterate:

Methods

The METHODS dict is exported from obliteratus.abliterate. Pass the key to the method constructor argument.

Code Examples