Retrieved article excerpt
Open article · Retrieved 2026-11-26T13:21:38.360903+00:00
# Kestrom
**Edit a language model inside a range, and let anyone check, byte for byte, what changed and what did not.**
Fine-tuning, LoRA, merging and quantization can move the output at any position. After such an edit, the only way to know that
"nothing else changed" is to evaluate everything again, and even then you only know it for the prompts you tried. In our runs on
Qwen3.5-9B and Qwen3-8B, a 4-bit quantization and a public fine-tuned derivative each left **0 of 150** greedy answers the same as
the original's.
Kestrom takes the other side. Each edit comes with a **range** that is read from the weights or from the decoding, not from what
the editor claims, and a report that anyone can rebuild on their own machine and compare with `cmp`.
```
original weights ──edit──▶ edited weights ──kestrom-verify──▶ report.json
│ W every byte the same but the changed rows
│ U0 the original equal to itself on this machine
│ G1 every logit outside the range equal, bit for bit (row edits)
│ G2 greedy output the same until the range is reached
▼
the receiver rebuilds report.json ─▶ same bytes
```
Two packages:
| Package | Command | What it is | License |
| --- | --- | --- | --- |
| `kestrom-verify` | `kestrom-verify` | The checker. Reads two models (and their outputs) and writes the report | Apache-2.0, free for everyone |
| `kestrom` | `kestrom` | The editing tools whose range the checker can bound | Free for companies with fewer than 100 people, for noncommercial use and for a trial of less than 32 days (PolyForm); other uses need a commercial license |
## Three tiers of guarantee
The checks that pass say which tier an edit is in. Kestrom does not blur them.
| Tier | What is checked | Commands | Edits |
| --- | --- | --- | --- |
| 1. Outputs | Greedy output is the same until the range is reached (G2); for a row edit, every logit outside the range is also bit-identical to the original (G1). With an output layer tied to the embedding, both for inputs with no changed id | Row edits: `range`, `logits`, `compare`. Decode-time edits: `compare events` | `kestrom rows` (rows of the output layer), `kestrom generate` (decode-time edits: rules—including probed models fitted at a decoder layer and transferred via `kestrom bridge rules`, conditional steering including directions/conditions mapped via `kestrom bridge`, adding a direction after a given text, phrase bans, loop stopping, `open` lines, compiled fact-KV routing via `kestrom kv compile` + `kv:` lines), `kestrom ifc` (twin-track control-flow non-interference and secret leakage firewall) |
| 2. Weights | Only the declared tensors / rows changed (declaration check D). How much the outputs moved is counted, not bounded | `diff`, `measure` | `kestrom edit` (neuron and head gains, a head's write along a direction, keyed writes, neuron writes, a direction out of a few `down_proj` columns), `kestrom rules write-mlp` (rules in MLP neurons), `kestrom trigger` (spare rows of the embedding) |
| 3. Measured only | What changed, and how much | `measure`, `diff` | `kestrom merge`, and any fine-tune (LoRA too) or quantization made elsewhere |
Determinism (U0: the original model gives the same logits and the same greedy output twice on your machine) is checked by `logits`
and `measure`, which run the original twice, and by `compare`, on the two outputs of the original you give it. If U0 fails, G1 and
G2 in that report mean nothing. `range` and `diff` read only bytes. `compare` checks the output files you give it: write them
yourself, running the original twice. For decode-time edits it checks the output against the events the decoding records, not that
a loop or a condition was really there.
## The editing tools
Every tool is in, whether or not it reached the target we set for it. The table gives the tier and what we measured, with the
target where one was missed. A tool's guarantee says what did *not* change; whether the edit does what you want is measured, and
for several tools it fell short. Each command's help (`kestrom`, `kestrom <command> --help`, `python -m pydoc kestrom.<module>`) has the details.
| Command | What it edits | Tier | What we measured (model) |
| --- | --- | --- | --- |
| `kestrom rows ban` | Output-layer rows of listed tokens set to a ban row | 1 | Chinese mixing 0.32 → 0.0067 (Qwen3.5-9B; below) |
| `kestrom rows lsq` | Output-layer rows of listed tokens, one least-squares solve toward target answers | 1 | Recall ≥ 0.5 on 7 of 10 refined endings, target 8 not reached (PLaMo 3 Translate 0.8B, polite to refined Japanese, earlier PyTorch form) |
| `kestrom rows ftpo` | Output-layer rows of the tokens of phrase events, by FTPO | 1 | Listed phrases 3,092 → 1,708, target ≤ 20% of the original not reached (Qwen3.5-9B) |
| `kestrom generate --rules` | Logits where hand-written rules over probed features fire (`kestrom rules fit`; `out` and `move` lines) | 1 | Refined endings 0.848 of the slots, broken 0.0135; with the fit rebalanced (balance 0.1, K 8) 0.925, broken 0.0185. The content after the first change kept 0.605 and 0.578, target 0.90 not reached (Qwen3.5-9B). `move` lines: a spelling rule with 0 errors in 200 new sentences (PLaMo 3 Translate, earlier PyTorch form) |
| `kestrom rules fit … STEPS` | The probes of the rules tuned by gradient, the rules unchanged | 1 | 0.892 of sentences on target, reached; the rest of the output kept 0.995 (PLaMo 3 Translate, earlier PyTorch form) |
| `kestrom generate --rules`: `in … prompt` and `add` lines (conditional steering) | One layer's output, when a condition read on the prompt fires | 1 | Polite sentences 0.641 → 0.0; JMMLU 0.72 → 0.72 (Qwen3.5-9B; below) |
| `kestrom bridge {fit, map, rules, chain}` | Fits closed-form active-subspace orthogonal Procrustes maps on sequence-mean hidden states of unlabeled anchors (`fit`, optionally composes `A→B→C` via `chain`), maps a donor `kestrom steer` `.npz` (`direction`, `cond`, `threshold`) with RMS scale matching (`map`, optional unlabeled `CALIB_PROMPTS` median threshold), and transfers a donor `kestrom rules fit ... LAYER` `.npz` (`P`, optional `bias`, `layer`) across paired decoder layers (`rules`, closed-form or unlabeled token-stream Z-score calibration on `CALIB_DOCS`) for `kestrom generate --rules` | 1 (via `generate`) | Steer transfer (`Qwen3.5-4B` `20` EN→JA pairs, `15+15` science vs Python prompt condition, `1,600` unlabeled anchors, `20` held-out prompts): closed-form gave `6/10` science→Japanese on Gemma 4 E4B (layer `22`, `ALPHA=14.950`) and `10/10` on Qwen3.5-0.8B (layer `12`, `ALPHA=0.755`) with `10/10` Python bit-identical; unlabeled median calibration gave `10/10` science→Japanese and `10/10` Python bit-identical (`events=[]`, `U0/G2 20/20 PASS`, `cmp` identical) on both; chaining `4B→Gemma 4 E4B→0.8B` (`17→22→12`) gave steering cosine `0.9346`. Rules probe transfer (`kestrom rules fit ... 20` on `Qwen3.5-4B` → `kestrom bridge rules`, zero recipient token labels): across held-out token streams (`1,069` Gemma 4 E4B tokens at layer `26`, `1,019` Qwen3.5-0.8B tokens at layer `15`), `in_code` AUC was `0.9905` / `0.9901` (F1 `0.8156` closed-form → `0.9238` Z-score on `24` unlabeled docs for Gemma 4 E4B; `0.9225` closed-form / `0.9165` Z-score for Qwen3.5-0.8B) and `is_ja` F1 was `1.0000` (Z-score) on both. Two-stage prompt condition × bridged `is_en` token probe gating `move . -> !: on` on `12` held-out prompts (`6` EN + `6` JA, `--max-tokens 48`): `6/6` EN fired with `!` added, `6/6` JA stayed bit-identical (`events=[]`), `U0/G2 12/12 PASS`, and `cmp` identical on both Gemma 4 E4B and Qwen3.5-0.8B |
| `kestrom generate --rules`: `phrase` lines | Goes back and bans the token that started a listed phrase | 1 | Listed phrases (`**`, `##`, three stock phrases) 3,092 → 0; JMMLU 0.74 → 0.68 at 1,024 tokens, target ≤ 1 point not reached. The model writes its answer in bold (**B**); banned there, it hedged or answered by name (Qwen3.5-9B). To drop markup only, strip it from the text after decoding |
| `kestrom generate --rules`: a `loopguard` line | Goes back at a thinking loop and forbids repeated 16-token pieces | 1 | Correct 4 → 26 of 100 (Qwen3.5-0.8B; below) |
| `kestrom generate --rules`: an `open` line | The output opens with the class that rules of their own (`kestrom rules run`, no model) answer for the prompt's `data`, then a line feed: the top token is kept where the text still fits, else the top token that fits is taken (an event); where the rules answer none, nothing, or a class given in the line. The answer is what follows the last `</think>`; where the top token that begins it starts no class of the head nor the class given in the line, nothing. With a text in the line, the thinking also opens with that text, the class in it | 1 | Qwen3.5-4B writing a class on line 1 and a reason on line 2, opened by agent-written rules that route Japanese questions about building energy (the rules of `kestrom rules run` below): on 24 new questions (8 plain, 8 oddly worded, 8 vague or unrelated; written by one agent, kept where a second gave the same answer) line 1 was right on 13 unopened, 15 opened with the rules' class, 22 when also opened with `clarify` where the rules answer none; no line 1 went from right to wrong; G2 24/24 in both forms. One question the rules could not read (a typo) was opened with `clarify` though it had an answer; the model alone was wrong there too, and how often it would have been right is not measured. In a run of the same method by an earlier script, one judging agent found the reason newly contradicting line 1 or misreading the question on 1 of the 24. Four chat questions with no request for a class (two naming a word the example router reads) kept the original's output, token for token (the example). With thinking on and at most 2,048 tokens, on the same 24 questions: line 1 right on 4 unopened (19 outputs never closed the thinking), 4 with the answer opened (every output the original's), 11 with one sentence holding the rules' class (`clarify` where they answer none) also written at the start of the thinking (8 that had not closed the thinking became right, 1 that was right no longer closed it; 13 never closed the thinking, and none more did with a loop guard of 512); G2 24/24 in each form, where it covers little of an output whose thinking was opened. All three counts are below those of the same questions with thinking off (13 unopened, 22 opened with `clarify` where the rules answer none); of those 8, 6 are questions the unopened model has right with thinking off and 2 are ones it has wrong. One wording of the sentence; the unopened model at a higher limit is not measured. One model; the agents that wrote the rules and the questions, labelled and judged are of one family. [examples/rules-open](https://github.com/CAPHTECH/kestrom/blob/main/examples/rules-open) runs the mechanism on eight other questions |
| `kestrom kv compile`, `kestrom kv chat`, `kestrom generate --rules`: a `kv` line | Compiles per-fact system-prefix KV caches from standalone rules and `FACTS.json` (zero weights changed); at decode time (`kv: BANK_DIR [MAX_MATCH]`), evaluates the bank's rules on `data` plus any `in NAME: prompt FILE LAYER` conditions (including cross-model probes mapped by `kestrom bridge map`) passed as 0/1 `values`, injects the compiled KV cache when `1` to `MAX_MATCH` entries match (composing ≥2 on demand with an in-memory LRU cache) and records event `0`, while unmatched or out-of-range prompts get no cache and no event (`events=[]` where no other line acts). `kestrom kv chat` runs multi-turn sessions (`steps`/`prev` + optional `PROBES.dsl`) with incremental KV reuse when the topic holds and automatic re-prefill