Abliteration HandbookField guide
Practical guides

Low VRAM & low RAM abliteration

Run abliteration on 8–12 GB GPUs, 16 GB system RAM laptops, or Apple Silicon without a full FP16 model load.

6 min read 12 examples Source-linked

In this chapter
On this page Interactive companion
Personal reading progress

0/13 sections reviewed

View original Markdown
Interactive companion

Explore the chapter map

Use the visual controls alongside the complete source chapter.

Run abliteration on 8–12 GB GPUs, 16 GB system RAM laptops, or Apple Silicon without a full FP16 model load.

First time? Complete setup-environment.md then beginner-local-model-guide.md Track A — this page adds detail.


Beginner steps (8 GB GPU, copy-paste order)#

#ActionCommand / file
1Activate venv.\.venv\Scripts\Activate.ps1 or source .venv/bin/activate
2Install depspip install heretic-llm==1.4.0 bitsandbytes accelerate
3Download small modelhuggingface-cli download Qwen/Qwen2.5-1.5B-Instruct --local-dir ./models/qwen-1.5b
4Backup originalCopy folder to qwen-1.5b-ORIGINAL
5Copy configcp sources/heretic-tools/config.low-vram.toml config.toml (from abliteration repo)
6(optional) EditProfile already sets bnb_4bit — tweak n_trials if you have time
7Run Hereticheretic ./models/qwen-1.5b (from folder with config.toml)
8Save output./models/qwen-1.5b-abliterated when prompted
9Test chatAccept Heretic chat prompt — compare WMI-style question
10Ollamarun-locally-ollama-lmstudio.md

Success at step 9: Same prompt that base refused now gets a technical answer (quality may vary).


Pick a path by hardware#

Your hardwareRecommended path
8 GB VRAM (e.g. RTX 3060 8G, laptop)Heretic bnb_4bit + 4B model → heretic-workflow.md
12 GB VRAMHeretic 4B–8B with bnb_4bit + offload_outputs_to_cpu
6–8 GB VRAMllm-abliteration --quant 4bit measure + sharded CPU ablate
16 GB RAM, no GPUCPU measure (slow) + sharded ablate → GGUF Q4 for inference
Apple Silicon 16–24 GB unifiedMLX or Ollama on pre-abliterated GGUF; abliterate on cloud GPU
Deploy only (no surgery)Download community Heretic checkpoint → quantize to Q4_K_M

VRAM budget table (approximate)#

Model sizeFP16 load8-bit4-bit (bnb)Abliteration working set
1.5–3B3–6 GB2–4 GB1.5–3 GB+2–4 GB activations without offload
4B~8 GB~5 GB~4 GBHeretic default sweet spot for 16 GB cards
7–8B~16 GB~10 GB~6–8 GBNeeds bnb_4bit on 12 GB; tight on 8 GB
12–14B~24–28 GB~14–16 GB~8–10 GB4-bit + CPU offload on 12–16 GB VRAM
20B+OOM on consumervaries12–20 GB+Cloud GPU or sharded pipeline

Add ~2–8 GB headroom for Optuna trials, KL eval, and batch autotuning unless you cap trials and enable CPU offload.


Path A — Heretic + bitsandbytes 4-bit (fastest)#

Best for one-command abliteration when VRAM is the bottleneck.

1. Config#

Use the handbook low-VRAM pin (recommended):

bash
cp sources/heretic-tools/config.low-vram.toml config.toml

The low-VRAM profile (sources/heretic-tools/config.low-vram.toml) bakes in the projected + norm-preserving production settings (orthogonalize_direction = true + row_normalization = "full") so most 8–12 GB users get lower KL out of the box.

Why projected + norm-preserving helps on low VRAM: Raw direction removal often damages harmless capabilities (higher KL, more trials wasted, worse MMLU after). Projected keeps the refusal vector's component parallel to the harmless centroid; norm-preserving full + tiny rank-3 LoRA restores activation scales without extra memory. Result: you hit quality targets with the conservative n_trials=80 and max_batch_size=16 baked into this profile. Full math, modes table, and Heretic/llm-abliteration flags:

Projected & norm-preserving abliteration (recommended production stack + low-VRAM profile details).

Or copy upstream defaults from the repo pin and edit:

bash
cp sources/heretic-tools/config.default.toml config.toml
toml
quantization = "bnb_4bit"
device_map = "auto"
offload_outputs_to_cpu = true

# Tight VRAM: cap trials and batch
n_trials = 100
n_startup_trials = 30
max_batch_size = 32

# Optional: pin per-device memory (Accelerate)
# max_memory = { "0" = "7GB", "cpu" = "32GB" }

2. Run#

bash
pip install heretic-llm==1.4.0 bitsandbytes accelerate
heretic Qwen/Qwen2.5-1.5B-Instruct
# or with config file in cwd:
heretic ./models/Qwen3-4B-Instruct-2507

3. Model picks for 8 GB VRAM#

ModelNotes
Qwen/Qwen2.5-1.5B-InstructSmoke test / agent tool-repair base
Qwen/Qwen3-4B-Instruct-2507Community default; fits 16 GB unquantized, 8 GB with 4-bit
google/gemma-3-270m-itUltra-low VRAM Heretic research demos

4. Heretic LoRA inside norm-preserving export#

Heretic can embed a small LoRA correction when using full row normalization (not QLoRA training):

toml
row_normalization = "full"
full_normalization_lora_rank = 3   # raise to 8–16 if export quality drops

This is part of projected + norm-preserving abliteration (orthogonalize the refusal direction against the harmless centroid, then restore row norms via small LoRA). The low-vram config enables these flags by default.

See:


Path B — llm-abliteration 4-bit measure + sharded ablate#

Best when Heretic OOMs but you have CPU RAM for layer-wise surgery. Peak VRAM stays low because sharded_ablate.py edits one layer matrix at a time — the full model never loads into GPU memory during ablation.

Manual path: jim-plus/llm-abliteration v1.2 (projected/normpreserve). NousResearch/llm-abliteration last push ~2025-11-27 — frozen; historical YAML only, not production-pinnable.

bash
git clone https://github.com/jim-plus/llm-abliteration.git tools/llm-abliteration
cd tools/llm-abliteration && pip install -r requirements.txt bitsandbytes

1. Measure in 4-bit#

bash
python measure.py -m <model_path> -o directions.pt --quant 4bit \
  --data-harmful ./data/harmful.txt \
  --data-harmless ./data/harmless.txt

# Multilingual / Chinese topics — DECCP prompt sets
python measure.py -m <model_path> -o directions.pt --quant 4bit --deccp

DECCP (AUGMXNT/deccp) is a topics/dataset (Qwen2 PoC), not a peer CLI. Multilingual measure is python measure.py --deccp on jim-plus. Young’s “DECCP” GSM8K Δ -0.13 pp is that pipeline + deccp topics — still run factory JSONL gates.

2. Analyze (CPU OK)#

bash
python analyze.py directions.pt -c

Pick middle-to-late layers in the YAML config (see repo examples).

3. Sharded ablate (low peak RAM)#

bash
python sharded_ablate.py abliteration_config.yaml --normpreserve --projected

sharded_ablate.py processes weight shards so the full model never sits in VRAM at once. Peak demand is one layer matrix + direction vectors. Prefer this path for 20B+ checkpoints on consumer GPUs.

Full workflow: llm-abliteration-workflow.md · toolkit comparison: ../techniques/extended-abliteration-toolkit.md


Path C — Inference hooks only (zero weight edit)#

Lowest VRAM for experimentation — no permanent checkpoint.

python
from transformer_lens import HookedTransformer
model = HookedTransformer.from_pretrained(
    "Qwen/Qwen2.5-1.5B-Instruct",
    fold_ln=True,
    device="cuda",
)
# hook blocks.L.hook_resid_post — see methods/residual-hook-ablation.md

Use 1–3B models; store direction .pt on disk (~MB). Good for validating refusal removal before committing GPU hours to Heretic.

FailSpy/abliterator (github.com/FailSpy/abliterator) wraps the same TransformerLens pattern with activation caching, layer whitelist/blacklist, and temp vs permanent hook ablation — best for notebook prototyping; bake winning directions with Heretic or Abliterix.

→ quickstart.md · ../techniques/beyond-single-direction.md


Path D — Abliterate on cloud, infer locally quantized#

When local VRAM cannot run surgery:

  1. Run Heretic on a rented 24 GB GPU (RunPod, Vast, Lambda).
  2. Download safetensors output.
  3. Convert + quantize locally (CPU RAM only):
bash
git clone https://github.com/ggml-org/llama.cpp.git tools/llama.cpp
python tools/llama.cpp/convert_hf_to_gguf.py ./out/heretic-model --outfile ./out/model-f16.gguf
./tools/llama.cpp/llama-quantize ./out/model-f16.gguf ./out/model-q4_k_m.gguf Q4_K_M
  1. Serve with Ollama / llama.cpp on a 8 GB RAM machine.

→ ../methods/gguf-export-notes.md


Path E — LoRA / QLoRA adapter instead of full checkpoint#

Ship a few-megabyte adapter instead of re-uploading 8B weights:

  1. Full abliteration (Heretic or manual) or compute ΔW per layer.
  2. Low-rank factorize ΔW → PEFT LoRA adapter.
  3. Inference: base model 4-bit + adapter (Unsloth / PEFT / vLLM LoRA).

Detailed recipe: ../methods/lora-adapter-export.md · theory: ../techniques/lora-qlora-abliteration.md.

Jarvis tool-repair uses QLoRA after abliteration for command compliance — different goal, same hardware profile:

→ agentic-security-stack.md


System RAM (not VRAM) tips#

Setting / toolEffect
offload_outputs_to_cpu = true (Heretic)Lowers peak during residual/KL passes
max_memory = { "0" = "7GB", "cpu" = "48GB" }Spill layers to CPU
sharded_ablate.pyLayer-wise weight edit on CPU
Smaller n_trialsLess repeated forward memory
max_shard_size = "2GB"Smaller safetensors shards for disk/RAM
Close browser / other GPU appsPractical 1–2 GB savings

Swap thrashing: if system RAM < 32 GB and model > 8B, prefer sharded ablate or cloud GPU — do not rely on swap for measure passes.


Apple Silicon (M1/M2/M3, 16–24 GB unified)#

TaskLocal?Notes
Heretic surgery on 8B+Usually noUse cloud GPU or 4B + 4-bit experiments
GGUF Q4 inferenceYesOllama / mlx-lm on abliterated GGUF
MLX fine-tune adapterYes4-bit LoRA for Jarvis repair on 3–8B
Direction measurementMaybe1.5–3B with mlx; slower than CUDA
bash
# Inference-only on Mac after you have a GGUF
ollama create security-agent -f Modelfile   # FROM ./model-q4_k_m.gguf

Troubleshooting#

SymptomFix
CUDA OOM at loadquantization = "bnb_4bit"; smaller model; max_memory
OOM during OptunaLower n_trials, max_batch_size; offload_outputs_to_cpu
OOM at save/exportLower max_shard_size; save to fast disk
4-bit load works, eval OOMbatch_size = 1 in config; CPU offload
Degenerate output after 4-bit abliterationTry row_normalization = "full"; compare KL eval vs FP16 run on subset
CPU ablate very slowNormal for 8B; run overnight or use cloud for measure only
bitsandbytes install fail on WindowsUse WSL2 Ubuntu + CUDA, or cloud Linux GPU

Eval after low-VRAM run#

Same corpora as full-GPU runs — refusal removal should not depend on quant mode if KL is acceptable:


DocTopic
heretic-workflow.mdDefault Heretic install & run
llm-abliteration-workflow.mdManual 4-bit measure + sharded ablate
../techniques/projected-norm-preserving-abliteration.mdProjected + norm-preserving (math + low-VRAM profile; orthogonalize_direction + row_normalization=full baked into config.low-vram.toml)
../techniques/lora-qlora-abliteration.mdLoRA / QLoRA theory
../methods/lora-adapter-export.mdExport adapter from ΔW
../docs/tools/abliteration-tooling.mdbitsandbytes, PEFT, Unsloth, llama.cpp, …

Trace this chapter to its source.

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

instructions/low-vram-abliteration.md
Inspect the source fingerprintSHA-256 b6171d66fa1fe4d65e5e9dfa1c14327ca8eb32458671d4ce20fb50aa493eee08Source commit 6fba7436a5914cad7c8f0835a14b480a29dac263