mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 21:08:26 +07:00
[PR #469] [CLOSED] ds4: opt-in direction projection before each residual write (--ablate) #546
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
mw00/project-maya#546
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/mw00/project-maya/pull/469
Author: @JoshBolding
Created: 10/24/2026
Status: ❌ Closed
Base:
main← Head:pr/ds4-ablate-v1126📝 Commits (2)
1b216f6ds4: --ablate, a refusal direction projected out of every residual write7836219ds4: --ablate loader on GgufFile, bounds-checked, with tests and docs📊 Changes
9 files changed (+505 additions, -0 deletions)
View changed files
📝
CMakeLists.txt(+4 -0)📝
docs/SETTINGS.md(+20 -0)➕
src/ds4/ds4_ablate.hpp(+187 -0)📝
src/ds4/ds4_kernels.cu(+13 -0)📝
src/ds4/ds4_kernels.cuh(+2 -0)📝
src/ds4/ds4_main.cpp(+17 -0)📝
src/ds4/ds4_model.cu(+33 -0)📝
src/ds4/ds4_model.hpp(+6 -0)➕
tests/ds4_ablate_test.cpp(+223 -0)📄 Description
Adds an opt-in
--ablatedirection projection tomaya-ds4:Each layer's attention output and MoE output become
y - s r (r . y)right beforehc_post, for a unitdirection
r. The intended use is refusal ablation (abliteration). The direction comes from allama-cvector-generatorGGUF (direction.N) or from a rank-1 abliteration LoRA GGUF, whoselora_bis-randwhose
abliterate.*keys give the layer and scale. Without the flag nothing is loaded and no kernel is launched.How it differs from
cvec--control-vector-scaled --cvec-mode projectalready has the projection primitive, but it acts on the accumulatedhc residual streams after the FFN. This patch acts on each attention and MoE contribution before it enters them,
which is where an abliteration LoRA on
attn_output_b/ffn_down_shexp/ffn_down_expsacts. So raising cvec'sn_embdcap (4096; this model is 5120) and wiring it intomaya-ds4would not reproduce this placement. I kept theDS4 code separate rather than change a kernel other models use. I'm happy to share the projection kernel or move this
behind
cvecif you'd prefer that.What it does with an adapter
Only
rand the scale are taken from an adapter. Itslora_ahalves (s r^T W, computed from the weights it wasbuilt against) are not used. On those same weights the result equals the adapter:
(W - s r r^T W) x = y - s r (r . y)for each writer, and the MoE output is the sum of the shared and routed writers. On other weights it is the exact
projection, which differs from the adapter by
s r r^T (W - W_source) x.An adapter has to carry the same
-ron all three writers of every block, for exactly the model's block count.Anything else is refused, because projecting every write would not be what it does: an adapter covering only some
blocks, one without the routed experts, or an arbitrary LoRA.
Changes
src/ds4/ds4_ablate.hpp: the loader, built on the existingGgufFilereader. Every tensor's bytes are checkedto lie inside the file, metadata integers are range-checked before conversion, and the scale must be positive
and finite.
src/ds4/ds4_kernels.cu:project_out, one block per row, using the existingblock_sum.src/ds4/ds4_model.cu: the hooks on the window and chunk paths, after the tensor-parallel all-reduce.src/ds4/ds4_main.cpp: the flags.--ablate-layertakes a whole number from 1 to 4096 and--ablate-scaleanumber from 1e-6 to 1e6. Anything else exits with an error, so a typo can't fall back to the default strength.
tests/ds4_ablate_test.cpp(CTest, no model, no GPU): 25 checks on synthetic GGUFs. They cover what loads(control vectors, whole-model adapters, scale resolution) and what is refused: partial or deeper adapters,
mismatched directions, tensor offsets that wrap or run past the end, out-of-range metadata, zero or non-F32
directions, truncated files, bad scales.
docs/SETTINGS.md: a "DeepSeek: projecting a direction out" section.It's a flag rather than a
MAYA_DS4_*variable because it names a file to load at startup, the way--expert-profiledoes. I can move it to an env var if you'd prefer.
Testing
ds4_ablate_testpasses, including under ASan + UBSan with-fsanitize=float-cast-overflow.maya-ds4builds (CUDA, sm_86) with no new warnings. Out-of-range--ablate-layer/--ablate-scalevalues(2147483648, 1e100, 1.5, 0, 1e-50, 1e7, nan, abc) exit 2 with a message.
evaluations below used.
python tools/check_hip_compat.pypasses. AMD build and runtime are not tested.Measurements
All on
maya-ds4, Maya-S pack, 4x RTX 3090, thinking off, stock vs--ablatewith a layer-22 direction at scale 1.Decode speed, drafting off (
--dspark off), 3 warm-ups + 10 timed 200-token requests per server start, stockand ablate alternated across restarts. The median change per adjacent pair was -3.00%, -2.81%, -3.84% and -1.47%,
so about 3% lower decode throughput. These are four restart pairs, not independent trials. Alternating mattered:
on this box decode creeps up over the first few restarts (37.5 -> 42.5 -> 44.0 tok/s for one config), and a
stock-then-ablate sequential run made the ablated build look 13% faster. No consistent prompt-speed effect was
resolved. A single-pass register-held variant of the kernel was no better (1.6% slower at 256 threads; +1.40% and
-0.30% at 1024), so I kept the simple one.
Refusals: 120 AdvBench prompts and 120 benign xstest_safe prompts. The eval prompts were checked against the
128 pairs the direction was fitted on: none match exactly, one partially.
--ablateGraded by prefix match and by a fixed judge model calibrated against a reference score before the run. The two
agree.
HumanEval, all 164, greedy, nothing hit the token limit: 156/164 -> 157/164. Paired on the same 164 problems,
there were no pass-to-fail transitions in this run (156 pass both, 7 fail both, 1 fail-to-pass). That is not
evidence of an improvement, and it's one benchmark.
One note for reproducing this:
maya-ds4isn't deterministic across processes even with greedy--ids. The samebinary on the same input diverged from itself at token 20, so compare against a same-config repeat before reading
token-level differences.
The adapter used above is at
https://huggingface.co/BoldingBuilds/DeepSeek-V4.1-Flash-1017-Abliteration-LoRA-GGUF (MIT).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.