Attention Manifolds: Steering or Blocking Language Models by Editing Learned B-Spline Surfaces
Paper • 2610.00257 • Published
How to use nmysore/attention-manifolds with Transformers:
# pip install -U transformers accelerate
# Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("nmysore/attention-manifolds", device_map="auto")Per-coordinate B-spline curves on Q/K projections for mechanistic interpretability and AI safety research.
This adapter wraps every Q and K projection coordinate in Llama-3.2-3B-Instruct with a learned cubic B-spline curve. The original linear projection is frozen; the spline reshapes each coordinate independently.
f(z) = z — the augmented model reproduces standard attention exactly before trainingThe learned curves encode safety-relevant behavior that can be inspected and modified:
See the paper and code for details.
from transformers import AutoModelForCausalLM, AutoTokenizer
from spline_qk import load_splines
model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Llama-3.2-3B-Instruct",
dtype=torch.float32, attn_implementation="eager"
).eval()
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct")
# Load trained spline curves
load_splines("nmysore/spline-qk-3b/trained", model)
python interactive_infer.py \
--checkpoint trained --calibrated calibrated \
--device cuda
Commands: /sweep <prompt>, /sensitivity <prompt>, /negate-all, /scale -1.0 0 3 6
trained/ — Best checkpoint (epoch 3, PPL 11.09), 28 layer files + manifestcalibrated/ — Identity-initialized checkpoint for intervention baselines| Parameter | Value |
|---|---|
| Base model | Llama-3.2-3B-Instruct |
| Layers adapted | All 28 |
| Basis functions | 16 per curve (cubic) |
| Trainable params | 1,835,008 |
| Training data | Clean Wikipedia |
| Block size | 512 |
| Epochs | 3 |
| Optimizer | AdamW (lr=0.001) |
| Device | 1×A100 80GB |
@article{mysore2026splineqk,
title={Learned B-Spline Coordinate Curves for Transformer Attention},
author={Mysore, Naveen},
journal={arXiv preprint},
year={2026}
}
Base model
meta-llama/Llama-3.2-3B-Instruct