First Surgery
This walkthrough uses a synthetic weight matrix — no checkpoint or GPU needed.
Python API
python
import torch
from qriton_hlm import BasinSurgeon, compute_energy
# Create a synthetic Hopfield layer
d_model = 128
torch.manual_seed(42)
W = torch.randn(d_model, d_model) * 0.01
W = (W + W.T) / 2 # Symmetric
surgeon = BasinSurgeon.from_W(W)
# Survey: what basins exist?
survey = surgeon.survey(layer=0)
print(f"Basins found: {survey['num_basins']}")
# Inject a new basin
result = surgeon.inject(layer=0, seed=42, strength=0.1)
print(f"Existed before: {result['existed_before']}")
print(f"Exists after: {result['exists_after']}")
# Verify it's there
v = surgeon.verify(layer=0, seed=42)
print(f"Is basin: {v['is_basin']} (cos={v['cos']:.4f})")
# Check the damage
diff = surgeon.diff(layer=0)
print(f"W change: {diff['relative_pct']:.2f}%")
# Undo
surgeon.restore(layer=0)
print("Restored to original.")CLI
bash
$ qriton-hlm
hlm> load model.pt
hlm:model> survey 0
hlm:model> inject 0 42 0.1
hlm:model> verify 0 42
hlm:model> diff 0
hlm:model> restore 0HLM Script
Save as first_surgery.hlm:
bash
load model.pt
survey 0
inject 0 42 0.1
verify 0 42
diff 0
restore 0Run: qriton-hlm --script first_surgery.hlm
Next Steps
- Concept Surgery Tutorial — capture and inject semantic concepts
- Operations Reference — all 32 commands