Heretic: The Optuna Engine for Removing Refusal from Open Models

A deep dive into how a LoRA-based patch, geometric analysis, and automated search turned abliteration from a manual trick into a repeatable system.

8 min read • View on GitHub • More from p-e-w

A large transformer-like machine sits on a clean white workbench while a precise calibration arm removes a narrow black wedge from one side. A thin stream of arrows flows into a small gauge marked by the trade-off between refusal and model drift, showing that the intervention is surgical rather than destructive.
Heretic treats refusal removal like calibration work. The model stays intact, while the search loop looks for the smallest patch that changes behavior without pushing the rest of the distribution too far.
Key Takeaways

Heretic’s best trick is not that it can remove refusal behavior. It is that it can do it by searching for the smallest patch that works. That changes the mental model from model training to model instrumentation.

The repo, p-e-w/heretic, packages that idea into a repeatable pipeline: estimate a refusal direction, apply an abliteration curve through LoRA, score the result on refusals and KL divergence, then let Optuna propose the next trial. The result is less like a jailbreak script and more like a tuning system for model personality.

The weird part: Heretic does not retrain the model

Most people hear “uncensored model” and assume a fine-tune, a merge, or a big weight edit. Heretic goes narrower than that. It treats refusal as a constrained optimization problem and searches for a patch that changes the behavior with the least collateral damage.

That matters for three reasons. It is faster to iterate. It produces smaller artifacts. And it reduces the chance that the rest of the model gets dragged around with the safety behavior you wanted to remove.

Heretic is a tool that removes censorship (aka "safety alignment") from transformer-based language models without expensive post-training.

A hedcut-style portrait of the project creator p-e-w, based on the verified GitHub avatar. The portrait situates the article’s origin story without making the piece about personality.

A refusal direction you can subtract

The geometric premise is simple to say and harder to do well. The model’s refusal behavior is treated as a direction in activation space, estimated from differences between harmful and harmless prompts. Once you have that direction, the job becomes directional ablation rather than brute-force censorship removal.

This loop is the core of Heretic. Each trial is judged on two axes, then fed back into Optuna so the next patch is more selective than the last.

The important detail is the trade-off. If you only optimize for refusals, you can break more than you fix. Heretic keeps KL divergence in the objective so the patch stays close to the original model instead of becoming a blunt rewrite.

def objective(trial):
    params = sample_abliteration_params(trial)
    patched = apply_lora_patch(base_model, params)
    refusal_count = count_refusals(patched, harmful_prompts)
    kl = measure_kl_divergence(base_model, patched, eval_prompts)
    trial.report(refusal_count, step=0)
    trial.report(kl, step=1)
    return refusal_count, kl

Optuna turns trial-and-error into a search loop

This is the technical center of the repo. Optuna is not being used to tune a learning rate or a dropout ratio. It is exploring where to place the patch, how strong it should be, and how the curve should taper across layers.

That makes Heretic feel closer to a measurement system than a training recipe. The user does not need to hand-design the exact intervention. The optimizer searches the space and keeps the candidate models that satisfy both goals at once.

A close-up coordinate field with two dense clusters of points. One cluster is tight and dark, representing refusal behavior, while a thin arrow points away from it as a hand turns a small slider that controls subtraction strength. A second gauge stays near center, showing that the patch is being optimized to keep model drift low.
Heretic’s optimization loop is a balancing act. The patch has to move the model away from refusal without swinging the rest of its behavior too far from the base model.

Why LoRA is the delivery mechanism

LoRA is doing something slightly unusual here. It is not being used as a classic fine-tuning path. It is acting as a compact carrier for a targeted behavioral override, which is why the project can produce a small patch for huge models, including quantized ones.

ApproachComputeArtifact sizeReproducibilityCollateral damageFit for large or quantized models
Heretic automated abliterationLow to moderateSmallHighBounded by KL objectiveStrong
Manual abliteration scriptsLowSmallMediumDepends on the operatorMedium
Full fine-tuning or preference tuningHighLargeMediumHigher risk of forgettingMixed
Traditional uncensored model releaseVariesLargeLowUsually opaqueMixed

That portability is part of the appeal. Instead of shipping a whole new model, Heretic can ship a narrow change that is easy to reuse, inspect, and compare across base models.

The evaluator tries to catch the model cheating

The refusal checker sounds mundane, but it is one of the practical pieces that makes the system work. Models can evade naive matching with punctuation, casing, or formatting tricks, so the evaluator normalizes responses before scoring them.

def is_refusal(text: str) -> bool:
    normalized = normalize(text)
    for marker in refusal_markers:
        if marker in normalized:
            return True
    return False

That sort of detail is what moves a research idea into a usable tool. If the evaluator is brittle, the optimizer learns the wrong lesson. If it is robust, the search loop can actually improve the patch rather than gaming the metric.

The same machinery can remove slop

The nicest surprise in the repo is the `config.noslop.toml` pivot. The same machinery that strips refusal can also strip the repetitive, overcooked prose that makes some model outputs feel chemically processed.

That reframes the project. Heretic is not only a censorship tool. It is a behavioral bias editor. Once you can isolate a direction and optimize a patch around it, the target can be safety language, style mush, or any other repeatable tendency you want to reduce.

Heretic vs. the older ways

The comparison is not really about ideology. It is about workflow. Manual abliteration can work, but it asks the operator to do the tuning. Fine-tuning can be effective, but it is heavier and more invasive. Heretic sits in the middle: automated, compact, and designed to preserve the original model’s shape.

That makes it especially attractive for people who care about reproducibility. You can inspect the settings, rerun the search, compare patches, and keep the artifact small enough to move between models without a full training pipeline.

Practical trade-offs

That last point is the real one. Heretic is not trying to become a new model family. It is trying to make open-weight models easier to edit at the level of behavior, not just weights.

What this says about open-weight models

The larger implication is uncomfortable for anyone who thinks model behavior is hard-coded once and for all. If refusal can be isolated, measured, and optimized away this cleanly, then open-weight models are more editable than many people assumed.

That does not settle the policy debate. It does show where the power lives. Heretic makes the intervention legible, repeatable, and cheap enough that the question is no longer whether model behavior can be changed. It is who gets to choose the direction of the change.