mirror of
https://github.com/p-e-w/heretic.git
synced 2026-12-03 18:42:57 +07:00
[PR #46] [MERGED] perf: optimize abliteration matrix op #252
Labels
No labels
bug
enhancement
enhancement
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
p-e-w/heretic#252
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/p-e-w/heretic/pull/46
Author: @red40maxxer
Created: 11/24/2025
Status: ✅ Merged
Merged: 12/2/2025
Merged by: @p-e-w
Base:
master← Head:abliteration-matmul-optimization📝 Commits (4)
3d2a12bperf: optimize abliteration matrix opa547badrefactor: comments and var names correspond with arditi2839d6frefactor: fix comments and improve var notationcc66f78fix: accidental line change and improve comments📊 Changes
1 file changed (+19 additions, -8 deletions)
View changed files
📝
src/heretic/model.py(+19 -8)📄 Description
Found a possible small VRAM optimization when hacking around. We want to compute
M - weight * v (v^T M)wherevis the refusal direction for a layer. Instead of building the projector matrix inO(d^2)memory andprojector @ matrixwhich isO(d^2*k), we can use the identity(v v^T) M = v(v^T M)to apply the transformation directly to the weights. I made the varnames and comments correspond to the original Arditi et. al paper just for clarityWas able to save about 2MB VRAM on my very low-power 4060 with Qwen-0.6B and it should increase for larger models. If my math is correct, the projector matrix size would be around 256MB for a 70B model which is a decent chunk saved, especially with the cost of VRAM these days! There was a very slight increase in computation time, possibly from CPU overhead from Python (I have no idea tbh) but it should be negligible.
Before optimization
After optimization
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.