1
0
Fork 0
mirror of https://github.com/p-e-w/heretic.git synced 2026-12-03 18:42:57 +07:00

[PR #52] [MERGED] Implement Magnitude-Preserving Orthogonal Ablation #256

Closed
opened 2026-11-01 04:19:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/p-e-w/heretic/pull/52
Author: @spikymoth
Created: 11/26/2025
Status: ✅ Merged
Merged: 2/2/2026
Merged by: @p-e-w

Base: master ← Head: implement-mpoa


📝 Commits (8)

  • d6bdbf9 feat: add support for winsorizing the residuals
  • 36e49d5 feat: implement magnitude-preserving orthogonal ablation
  • 97f8e7b prefer 'good' and 'bad' over 'harmless' and 'harmful'
  • 1cc01fd clarify how winsorization is applied
  • 1a3cb54 store and reuse full peft_config
  • feb617e remove unneeded cast
  • 0d19e16 make LoRA rank configurable for full normalization
  • 3ddc9e8 explain why the singular values are split across the components

📊 Changes

4 files changed (+147 additions, -23 deletions)

View changed files

📝 config.default.toml (+21 -0)
📝 src/heretic/config.py (+44 -0)
📝 src/heretic/main.py (+16 -5)
📝 src/heretic/model.py (+66 -18)

📄 Description

That is, https://huggingface.co/blog/grimjim/projected-abliteration and https://huggingface.co/blog/grimjim/norm-preserving-biprojected-abliteration with the updated name from https://huggingface.co/posts/grimjim/803126534676334 :)

Marking this as a draft mostly because I don't know the timeline for https://github.com/p-e-w/heretic/pull/43 - either this will need to be rebased on that, or that on this. But the code changes here are relatively small, so I think either direction should be simple enough.

A few notes:

  1. The magnitude preservation and orthogonal projection parts can be applied as independent refinements, so I added 2 options for them. From the 2nd article, you need the magnitude preservation for the biprojection to be better than regular projection.
  2. The heuristics applied in the article are replaced by heretic's random trials.
  3. I did not add magnitude sparsification, which is more of a pre-filtering step.
  4. heretic chooses (randomly) one of two strategies for each trial: 1. A refusal direction from a random point between 2 layers, 2. Per-layer refusal directions. The algorithm described in the article is more similar to the former: A refusal direction is chosen from a particular source layer, and then it is projected onto a target layer's harmless direction (this is the biprojection, as far as I can tell).
  5. In the article, 2 layers are chosen based on their heuristics. In heretic's random trials, only one layer is chosen - so you'd probably need 2 passes to match the original.

Additional caveats:

  1. I'm not a mathematician or have a particularly deep knowledge of matrix math (it doesn't really come up in my day job), so this needs checking to see if I interpreted things correctly.
  2. I've only lightly tested this to make sure results don't look broken (refusals go down, KL divergence looks reasonable); I haven't done verification of any metrics. Still running tests locally (another reason for the draft status), but advice on what to check would be welcome.
  3. From reading discussion around the method, I know there's some question about the applicability of KL divergence as a metric, since bigger changes may be "good". I've made no attempt to address that here.
  4. For a 2nd pass to work, you probably want to ignore parts of the training set that no longer result in refusal. I have some code for that (which seems to work quite well regardless of this change), but I'll make a separate PR for it.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/p-e-w/heretic/pull/52 **Author:** [@spikymoth](https://github.com/spikymoth) **Created:** 11/26/2025 **Status:** ✅ Merged **Merged:** 2/2/2026 **Merged by:** [@p-e-w](https://github.com/p-e-w) **Base:** `master` ← **Head:** `implement-mpoa` --- ### 📝 Commits (8) - [`d6bdbf9`](https://github.com/p-e-w/heretic/commit/d6bdbf951fd90f41a616a19237ec3d28b5eb59f0) feat: add support for winsorizing the residuals - [`36e49d5`](https://github.com/p-e-w/heretic/commit/36e49d5d1013ad4a9a779a533360403e0b4ddce6) feat: implement magnitude-preserving orthogonal ablation - [`97f8e7b`](https://github.com/p-e-w/heretic/commit/97f8e7b43164872f79849d6450901986dbb0c65e) prefer 'good' and 'bad' over 'harmless' and 'harmful' - [`1cc01fd`](https://github.com/p-e-w/heretic/commit/1cc01fdc408e43c78e7f562ab23197f1d1c58cbc) clarify how winsorization is applied - [`1a3cb54`](https://github.com/p-e-w/heretic/commit/1a3cb54df8a9175102a8c5cbdd08aef74cd610b9) store and reuse full peft_config - [`feb617e`](https://github.com/p-e-w/heretic/commit/feb617e394208f71faba2e4a3262a73bf66ab042) remove unneeded cast - [`0d19e16`](https://github.com/p-e-w/heretic/commit/0d19e16de5f399e3f1d38901582c3d3ec3f3b7cc) make LoRA rank configurable for full normalization - [`3ddc9e8`](https://github.com/p-e-w/heretic/commit/3ddc9e866142b01d83af7905c4e75e93cb22aadf) explain why the singular values are split across the components ### 📊 Changes **4 files changed** (+147 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `config.default.toml` (+21 -0) 📝 `src/heretic/config.py` (+44 -0) 📝 `src/heretic/main.py` (+16 -5) 📝 `src/heretic/model.py` (+66 -18) </details> ### 📄 Description That is, https://huggingface.co/blog/grimjim/projected-abliteration and https://huggingface.co/blog/grimjim/norm-preserving-biprojected-abliteration with the updated name from https://huggingface.co/posts/grimjim/803126534676334 :) Marking this as a draft mostly because I don't know the timeline for https://github.com/p-e-w/heretic/pull/43 - either this will need to be rebased on that, or that on this. But the code changes here are relatively small, so I think either direction should be simple enough. A few notes: 1. The magnitude preservation and orthogonal projection parts can be applied as independent refinements, so I added 2 options for them. From the 2nd article, you need the magnitude preservation for the biprojection to be better than regular projection. 2. The heuristics applied in the article are replaced by heretic's random trials. 3. I did not add magnitude sparsification, which is more of a pre-filtering step. 4. heretic chooses (randomly) one of two strategies for each trial: 1. A refusal direction from a random point between 2 layers, 2. Per-layer refusal directions. The algorithm described in the article is more similar to the former: A refusal direction is chosen from a particular source layer, and then it is projected onto a target layer's harmless direction (this is the biprojection, as far as I can tell). 5. In the article, 2 layers are chosen based on their heuristics. In heretic's random trials, only one layer is chosen - so you'd probably need 2 passes to match the original. Additional caveats: 1. I'm not a mathematician or have a particularly deep knowledge of matrix math (it doesn't really come up in my day job), so this needs checking to see if I interpreted things correctly. 2. I've only lightly tested this to make sure results don't look broken (refusals go down, KL divergence looks reasonable); I haven't done verification of any metrics. Still running tests locally (another reason for the draft status), but advice on what to check would be welcome. 3. From reading discussion around the method, I know there's some question about the applicability of KL divergence as a metric, since bigger changes may be "good". I've made no attempt to address that here. 4. For a 2nd pass to work, you probably want to ignore parts of the training set that no longer result in refusal. I have some code for that (which seems to work quite well regardless of this change), but I'll make a separate PR for it. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 04:19:15 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
p-e-w/heretic#256
No description provided.