Heretic is an automated tool designed to remove safety alignment from transformer-based language models without the need for expensive post-training. It implements an advanced version of directional ablation (abliteration) by orthogonalizing attention out-projection and MLP down-projection matrices against a specific "residual direction." This direction is calculated as the difference-of-means between the first-token residuals of harmful and harmless prompts. Unlike previous methods, Heretic utilizes a TPE-based optimizer via Optuna to automatically find optimal ablation parameters by co-minimizing refusal rates and KL divergence from the original model. Key technical innovations include the use of a float-based direction index—which allows for linear interpolation between discrete residual vectors—and highly flexible, non-constant ablation weight kernels. In benchmarks on google/gemma-3-12b-it, the Heretic-generated model achieved a refusal rate of 3/100 with a KL divergence of only 0.16, significantly outperforming manual abliteration versions that showed much higher divergence (e.g., 0.45 to 1.04). The tool supports various architectures, including MoE and hybrid models like Qwen3.5, and provides interpretability features such as PaCMAP projections of residual vectors to visualize how harmful versus harmless prompts transform through model layers.
Read original
github-trending/python