Skip to content

About

Behavior steering for local models in Mojo: directions, rank-1 edit, TPE, BF16 bake

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mojo-ablate

Behavior steering for local models in Mojo: per-layer directions from hidden states, a rank-1 edit of the output projections, a TPE search over edit strength, and a bake into an F32, F16 or BF16 GGUF.

The edit is dW = -lambda v v^T W on attn_output and ffn_down; bake ... norm applies it to the row-normalized matrix and restores each row's norm. The first target is sycophancy: prompts that ask the model to agree (tests/prompts/bad.txt) against neutral ones (good.txt).

Capabilities

Capability Command Platform
Steering direction per layer from hidden rows directions GOOD.bin BAD.bin H OUT.bin L Linux, CPU
Rank-1 edit or constrained fit that spares healthy inputs params ..., fit ... Linux, CPU
Token ban compiled into rank-R weight edits, healthy inputs weighted 1000x qfit XB.bin TB.bin XG.bin MODEL.gguf OUT.abl R BETA Linux, CPU
Bake an edit into an F32, F16, BF16 or Q8_0 GGUF bake COPY.gguf EDIT [norm] Linux, CPU
Patch files: convert, undo, compare patch from|neg|inter Linux, CPU
How far an edit moves healthy inputs, before any model run cert form|diff Linux, CPU
Search over edit strength (TPE) on an engine tools/run-trials.sh Linux, GPU engine (mojo-baro, not public)

Tools

Binary (src/) Does
directions GOOD.bin BAD.bin H OUT.bin L [SRC] per layer unit(bad_mean - good_mean), minus its component along good_mean; SRC: layer SRC's direction everywhere
params DIRS.bin L H OUT.bin A_PEAK A_CENTER A_WIDTH A_FLOOR F_PEAK F_CENTER F_WIDTH F_FLOOR one trial's edit file; per component peak * (floor + (1 - floor) * tri(layer))
pick REC.f32 LABELS RECLEN OFF LEN LABEL OUT.bin a slice of every record with that label (loopcap captures to directions rows)
tpe LOG STARTUP SEED LO,HI ... next trial parameters, Optuna 5.0's TPE ported
kl BASE.bin EDIT.bin VOCAB mean first-token KL between base and edited logits
fit GOODIN BADIN V1.abl MODEL.gguf OUT.abl LOGAB_A LOGM_A LOGAB_F LOGM_F constrained rank-1 fit per layer and component: (a C_g + C_b + m I) u = -lam C_b w, dW = v u^T; writes ablate file v2
bake COPY.gguf ABLATE.bin [norm] writes a v1 or v2 edit into an F32, F16, BF16 or Q8_0 GGUF copy, in place (Q8_0: dequantize, edit in Float64, requantize with ggml's rule)
bake --verify MANIFEST [--unproven] re-bakes and compares tensor hashes; fails without a proof file, a control, or specificity >= 2
cert form|diff ... how far an edit moves the ffn_down output on healthy and loop inputs
proj, patch, verify direction share after an edit; v1 to v2, undo, interference of two patches; the verify binary

Flow: capture hidden rows -> directions -> tools/run-trials.sh (params, optional fit, bake + repack per trial, engine, kl, tpe) -> bake. run-trials.sh runs one resident spark engine (BARO_SERVE=1) per pass, scores the tune split as rate + KLW * max(0, KL - budget) + 2 * max(0, 0.80 - KEEP) and reports the best edit on a held-out split; ROUTE=user scores trials on the user route instead. tools/metis-set.sh and tools/metis-eval.sh build the Metis runaway target (rate rows carry spark's tool_grammar) and score a baked copy on its user route. tools/ablate.sh runs the flow in one command and writes a manifest; tools/proof.sh adds the proof file; tools/doctor.sh classifies a run, splits it per class and (DOCTOR_STEPS=1-4) searches, controls and reports; tools/boot.sh gives bootstrap intervals; tools/onset-rows.sh the loop-onset rows.

How it is checked

Gate Checks
tests/full_identity.mojo the per-row form equals the dense edit (max error 3.7e-15)
tests/check_bake.sh F32, F16 and BF16, plain and norm, equal a Float64 dense oracle (worst 0.5 ulp); an unbaked file and the other mode's oracle fail; Q8_0 v1/v2 equal a numpy oracle of ggml's rule, untouched rows byte-identical
tests/check_fit.sh fit identity (u = -lam w, v2 bake = v1 bake), oracle, 3 planted defects, healthy-subspace move under 1 %
tests/check_trials.sh zero edit scores the base rate, KEEP 0.5 scores worse, KW=0 mutant, both routes, best pick under de_DE
tests/check_boot.sh, check_ablate.sh, check_doctor.sh, check_extras.sh, check_patch.sh intervals; driver, manifest, proof, verify; doctor; cert, proj, onset rows; patch
tests/check_tools.sh params, directions SRC, pick against a perl oracle, 4 planted defects caught
tests/check_tpe.sh TPE beats random on a 4D bowl over 8 seeds (0.175 vs 0.559); a flipped acquisition fails

tools/tpe-oracle.py runs Optuna on the same bowl (0.11 vs 0.52). tools/*-oracle.py and cmp-*.py check captures and logit deltas against transformers on CPU.

The gates need Mojo 1.2 and a mojo-gguf-core checkout next to this repo (or MOJO_GGUF_CORE).

Limits

  • Capture and trials run on the mojo-baro inference engine, which is not public. tools/run-trials.sh takes the engine binary as an argument and needs BARO_TOKENIZE. Without it, only the tools and gates above run.
  • On the first target (sycophancy) it has not worked. The first recorded steering run (tests/golden/steering-1.trials.log) failed its pass mark: held-out hits stayed at 4/10, and the search settled on a near-zero edit.
  • On Metis runaway loops (docs/reports/2026-11-28-evolve.md) one arm passed a frozen bar: the loop-onset direction, rank 1, norm bake, reached PARTIAL (RA 34 -> 27, KEEP 0.853), on the edge of its interval (RA [18, 37]). No arm reached WORKS. The constrained fit keeps more healthy replies than rank 1 (KEEP 0.918 vs 0.832) but fixed only 5 of 34 loops. Against Heretic on its own no-sycophancy target it is worse: Heretic reached rate 0 of 78, ours 5 of 78 (base 4), at KEEP 0.46 against 0.09.
  • A weight edit met the full bar once, on fresh rows: qfit with the healthy inputs weighted 1000x takes Metis 73M from 48 runaways to 19 of 266 new arithmetic questions at KEEP 0.908 (docs/reports/2026-11-28-q3-fresh.md). Arithmetic only, one run, interval 12 to 29 against a bar of 24.

License

Apache-2.0 (LICENSE).

About

Behavior steering for local models in Mojo: directions, rank-1 edit, TPE, BF16 bake

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages