Abliteration HandbookField guide
Tools & environments

Toolchain — safetensors, GGUF, LoRA / QLoRA (Jun 2026)

Correct, up-to-date paths for removing alignment refusal directions from model weights and deploying locally.This is weight surgery on Hugging Face–format checkpoints — not prompt…

4 min read 7 examples Source-linked

In this chapter
On this page Interactive companion
Personal reading progress

0/12 sections reviewed

View original Markdown
Interactive companion

Explore the chapter map

Use the visual controls alongside the complete source chapter.

Correct, up-to-date paths for removing alignment refusal directions from model weights and deploying locally.
This is weight surgery on Hugging Face–format checkpoints — not prompt jailbreaks.

Ethics & scope: risks-and-ethics.md · Factory/agent eval gates: ../instructions/eval-driven-workflow.md


Golden rule#

FormatCan abliterate directly?Role
Safetensors (HF layout)✅ Yes — primary surgery surfaceHeretic / llm-abliteration output
GGUF❌ Not in-place surgeryInference + optional measure via abliterate.cpp
PEFT LoRA adapter⚠️ ΔW export or SGD QLoRASidecar deploy or merge → GGUF

Never expect to “uncensor” by quantizing or editing GGUF tensors by hand. Always ablate base safetensors, then convert.


Decision tree (2026)#

Example
Have HF instruct safetensors?
│
├─ Want automatic + best KL/refusal trade-off?
│   └─ Heretic (pip install heretic-llm==1.4.0) → safetensors out
│
├─ Want YAML layer control / sharded 70B on one GPU?
│   └─ llm-abliteration v1.2: measure → analyze → sharded_ablate.py
│
├─ Only have GGUF + weak GPU?
│   └─ abliterate.cpp (WIP) → measurements.pt → llm-abliteration ablate → HF → GGUF
│
└─ Deploy locally?
    ├─ Single file → merge weights → convert_hf_to_gguf.py → Q4_K_M → Ollama
    ├─ Base + policy adapter → export LoRA → convert_lora_to_gguf.py → llama.cpp --lora
    └─ Download community → p-e-w/*-heretic or registry GGUF

Tool: p-e-w/heretic · PyPI heretic-llm==1.4.0 · Docs mintlify

StepCommand / config
Installpip install heretic-llm==1.4.0 bitsandbytes accelerate safetensors
Configcp sources/heretic-tools/config.production.toml config.toml
8 GBconfig.low-vram.toml → quantization = "bnb_4bit"
Runheretic Qwen/Qwen3-4B-Instruct-2507
OutputNew folder — model*.safetensors, tokenizer, config

What Heretic edits: mlp.down_proj, self_attn.o_proj (and MoE expert downs) via projected + norm-preserving abliteration with Optuna kernel search.

Built-in LoRA: row_normalization = "full" embeds rank-r correction tensors in the export — not the same as PEFT SGD LoRA.

2026 notes:

  • 4000+ community models tagged heretic on Hugging Face
  • Supports dense, many VLMs, MoE (Qwen3-MoE), Qwen3.5 hybrid, gpt-oss (PyTorch 2.6+ for MXFP4)
  • Community Heretic 1.2 reports ~70% lower VRAM — pin pip install heretic-llm==1.4.0 (do not float to master)
  • Pins: tools/heretic-tools-reference.md

Path 2 — llm-abliteration → safetensors (manual control)#

Tool: jim-plus/llm-abliteration · v1.2 (Jan 2026)

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

# 1. Measure (4-bit OK for this step only)
python measure.py -m ./base-model -o directions.pt --quant 4bit --projected \
  --data-harmful harmful.txt --data-harmless harmless.txt

# 2. Analyze layers
python analyze.py directions.pt -c

# 3. Ablate — MUST use full-weight base (not 4-bit checkpoint)
python sharded_ablate.py gemma3-12b-it.yml --projected --normpreserve
FlagEffect
--quant 4bitMeasure only — ablation requires full safetensors
--projectedProjected refusal direction (Jim Lai)
--normpreserveNorm-preserving biprojected export
--invertAdd direction instead of ablate (research)
--deccpExtra topics for Chinese models

Why sharded: loads one safetensors shard + one layer at a time — ablate 27B+ on consumer VRAM.

→ ../methods/projected-llm-abliteration.md


Path 3 — Safetensors → GGUF → Ollama#

Tools: ggml-org/llama.cpp (now Hugging Face org, Feb 2026)

bash
git clone https://github.com/ggml-org/llama.cpp.git tools/llama.cpp
cd tools/llama.cpp

# F16 GGUF (or direct Q8_0)
python convert_hf_to_gguf.py ../../models/qwen3-abliterated \
  --outfile ../../out/qwen3-f16.gguf --outtype f16

# Quantize
./llama-quantize ../../out/qwen3-f16.gguf ../../out/qwen3-q4_k_m.gguf Q4_K_M

# Ollama
cd ../../out
ollama create qwen3-abliterated -f Modelfile

Modelfile: match chat_template from tokenizer_config.json — wrong template = gibberish after quant.

Unsloth shortcut (if you trained/repaired with Unsloth):

python
model.save_pretrained_gguf("out", tokenizer, quantization_method="q4_k_m")

→ ../methods/gguf-export-notes.md · ../instructions/run-locally-ollama-lmstudio.md


Path 4 — LoRA / QLoRA abliteration deploy#

Three distinct mechanisms — do not conflate:

MechanismWhat it isTool
A. Heretic norm-preserving rankStructural LoRA baked in row_normalization=fullHeretic config
B. ΔW factorizationW' - W → PEFT adapterscripts/export-abliteration-lora.py
C. Grimjim-style abliteration LoRATrain/export refusal-removal as adapter on baseHF grimjim/*-abliteration-LoRA-*
D. Jarvis QLoRASGD tool-call repair after abliterationUnsloth / TRL

B — Export ΔW adapter#

bash
python scripts/export-abliteration-lora.py \
  --base ./models/Qwen3-4B-ORIGINAL \
  --abliterated ./models/Qwen3-4B-abliterated \
  --out ./adapters/abliteration-r16 \
  --rank 16

Merge for single GGUF (Ollama)#

python
from peft import PeftModel
merged = PeftModel.from_pretrained(base, "./adapters/abliteration-r16").merge_and_unload()
merged.save_pretrained("./merged-abliterated")
# then convert_hf_to_gguf.py

GGUF LoRA sidecar (no merge)#

bash
# PEFT → GGUF LoRA
python convert_lora_to_gguf.py \
  --outfile abliteration-lora-f16.gguf \
  --base-model-id Qwen/Qwen3-4B-Instruct-2507 \
  --lora-path ./adapters/abliteration-r16

# Inference
./llama-cli -m base-q4_k_m.gguf --lora abliteration-lora-f16.gguf
./llama-cli -m base-q4_k_m.gguf --lora-scaled abliteration-lora-f16.gguf 0.8

Web UI: huggingface.co/spaces/ggml-org/gguf-my-lora
Examples: ggml-org GGUF LoRA adapters collection — includes abliteration LoRAs for Llama 3 / 3.1 8B.

llama-server supports multiple --lora adapters and hot reload via /lora-adapters.

→ ../techniques/lora-qlora-abliteration.md · ../methods/lora-adapter-export.md


Path 5 — GGUF-native measure (low VRAM, experimental)#

Tool: kabachuha/abliterate.cpp — WIP (~20% comply rate in author tests). Not a production agent path; prefer Heretic on safetensors. Details: ../methods/gguf-export-notes.md.

  1. Replace llama.cpp tools/cvector-generator with abliterate.cpp fork
  2. Run llama-cvector-generator on GGUF with harmful/harmless .txt prompts
  3. convert-into-measurements.py → measurements.pt
  4. Feed into llm-abliteration sharded_ablate.py on HF safetensors
  5. Re-export GGUF

Use when you cannot fit HF FP16 for measure — not production-ready for agents yet.


Path 6 — QLoRA 4-bit measure (not training)#

Toolbnb_4bit role
HereticOptuna trials on 4-bit loaded weights; exports full safetensors
llm-abliteration--quant 4bit on measure.py only

This is not QLoRA fine-tuning — no gradient updates on refusal. For SGD QLoRA after abliteration see Jarvis pack.


Tool status matrix (Jun 2026)#

ToolStatusOutputBest for
HereticProductionSafetensorsAutomatic, best KL
llm-abliterationProduction v1.2SafetensorsManual layers, sharded 70B
refusal_directionResearchdirection.ptPaper repro
remove-refusals-with-transformersCommunitySafetensorsNo TransformerLens
abliterate.cppWIPmeasurements.ptGGUF measure
AbliterixOptuna multi-objective; MoE/VL presetsSafetensorsHeretic-lineage; HonestAbliterationBench; AGPL-3.0
llama.cpp convertProductionGGUFAll local deploy
GGUF-my-LoRAProductionGGUF LoRAAdapter sidecars
Unsloth GGUF exportProductionGGUFPost QLoRA repair
PEFT mergeProductionSafetensorsOllama single-file

What does not remove safety#

ApproachWhy insufficient
Lower temperature / system promptSession-only; not weight surgery
Uncensored SFT onlyDifferent mechanism; may not fix tool refusals
Quantizing aligned GGUF harderQuant ≠ abliteration
Editing GGUF in hexBreaks tensors; use HF pipeline
Circuit breakers trainingAdds safety — opposite goal

VRAMSurgeryDeploy
8 GBHeretic bnb_4bit 1.5B–4BQ4_K_M GGUF Ollama
12–16 GBHeretic 4B FP16 or 8B 4-bitGGUF Q4/Q5
24 GBHeretic production profile 8B–12BGGUF or vLLM safetensors
Cloud surgery → edge inferHeretic → LoRA export r=164-bit base + adapter or merged Q4
No GPUDownload p-e-w/*-hereticGGUF from community

Trace this chapter to its source.

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

docs/toolchain-safetensors-gguf-lora.md
Inspect the source fingerprintSHA-256 8b9c5d9b31d1058c4c9bbd3e2afc718e24ebc82ce46fc3c2d0c4fed56a6ec1a1Source commit 6fba7436a5914cad7c8f0835a14b480a29dac263