Version française non disponible
French version not available

Installed, not trained: plugging programs into a model's weights

We wrote a program into the weights of an open 4-billion-parameter model. No training: 2.6 million numbers in one attention head, worked out from formulas and shipped as a 10 MB patch. The patched model plays Tower of Hanoi for 1,023 moves without an error. A larger edit lets the model start the program by itself.

The model

Qwen3.5-4B-Base

First layer: sixteen attention heads

Programs

Three tasks

Figure 1. The idea. A program is a file of weights for one attention head. Installing it overwrites that head in the model's first layer, about six numbers in every ten thousand, and the model then runs the program one token at a time. Removing it restores the original bits. On the bare model, each panel replays what the unmodified model wrote when shown worked examples and asked for a new case: an illegal move after 47 of the 63 needed for six disks, no Rule 110 run right out of 12, and 6 of 20 ten-bit sums right. With the plugin installed, the panel is the program's table simulated in your browser. On the real model we have run two programs at once: Rule 110 and the adder currently share a head and an alphabet, and the third slot shown here is not built yet.

1,023moves without an error, ten disks, with the patch
0gradient steps, training examples or added parameters
10.6 MBone patch file; removing it restores the original bits
6 of 6runs started by the model itself, with the larger edit

A language model can describe an algorithm and still be unable to run it. Shown worked solutions to Tower of Hanoi and asked for the next size, the model we used solved four disks in one attempt out of six, and five, six or seven disks in none of sixteen.1 Fine-tuned on the solutions for one to six disks, it learned those sizes and nothing beyond them. The usual fix is to hand the work to an outside tool.

We did something else. We treated the model as a machine you can install software on. The program is not learned and not attached. It is written into weights the model already has, and from then on the model runs it natively, one token at a time.

The model as shipped

The same model, program installed

Figure 2. Both rows replay text the model wrote. Top: Qwen3.5-4B-Base, shown four worked solutions and asked for the next size, writes legal moves for a while and then one that is not allowed. Bottom: the same model with the patch applied. A person types the first line; the model writes every later position of the puzzle, in borrowed letters, until it halts. The installed program ends on peg B for an odd number of disks and C for an even number.

The rule. No training of any kind. Every number we changed is a closed-form function of the model's existing weights and a small table that describes the program. No gradients, no fitting to examples, no search over what to write.

There are two builds, and each result below says which it comes from. The patch rewrites one attention head in the first layer. It is a file you apply to the unmodified model and take off again. A person starts it by typing one line. The launchable build does the same computation but hands over its answer differently, which lets the model start the program on its own. It is not a small file: it nudges about a quarter of the model's numbers, each by a tiny amount. Most of this article is about the patch. The last third is about why the model could not launch it, and what fixed that.

The one loop a language model has

Hand-written weights that run an algorithm exactly are not new, and recent work shows that a frontier model can write them. The most ambitious version, Looped Weight-Space Programming, writes one small block and applies it as many times as the problem needs. That is a loop over depth, in a network built for the task. The network does nothing else, and connecting such networks to a language model is left as future work.

A pretrained model cannot loop over depth. Its 32 layers are all different and each runs once per token. But it does repeat one thing: each token it writes is fed back in. If something inside the model decides the next token, and that token changes what it decides next, the model is running a loop. The memory of the computation is the text written so far. We call that text the tape.

Figure 3. Two places a loop can live. A purpose-built network repeats one block over depth and keeps its state inside. A pretrained model runs each of its layers once per token; its only loop is that the token it writes comes back in, so the state has to live in the text.

Tower of Hanoi is counting

To install a program we first have to put it in a form this loop can run: read a little, write one token, repeat. Hanoi has such a form. Number the moves 1, 2, 3 and write each number in binary. Adding one clears a run of trailing ones and then sets a single zero. That one bit names the disk that moves, and each disk always travels the same way round the three pegs: odd disks one way, even disks the other.

So a position of the puzzle fits in one cell per disk, holding that disk's peg and one bit of the counter. To make a move, sweep across the cells carrying a one. While the carry meets a 1 it clears it and travels on. Where it meets a 0 it sets it, moves that disk one peg round, and stops.

Move counter, lowest bit first

The puzzle after this move

Figure 4. Four disks, fifteen moves. Each row is the move number in binary with the lowest bit on the left, so column 1 is the smallest disk. Outlined cells are the ones the carry passed through; the filled one is where it stopped, and that disk moves.

The tape

Each cell is written as one token. A cell's token has to say three things at once: which column it is in, what it holds, and whether the carry is still travelling when the sweep leaves it. We gave every such combination its own token: 100 symbols for up to ten disks, plus one that halts.

The tokens are borrowed letters, and each column borrows from a different script: Hangul for the first, Georgian for the second, and so on. The scripts do two jobs. A letter tells the head which column it belongs to. And the machine can only fire when letters from two neighbouring columns appear in one unbroken run, which ordinary text in any single one of these languages does not produce.

What the model writes is therefore not a list of moves. It is the position of the puzzle after every move, in these letters. Reading it takes a lookup table, and the model never translates it back.

One line of output, decoded

The whole instruction set

One column of the tape per script. Hover a letter to read it.

Figure 5. The 100 symbols of the Hanoi program. A symbol's script gives its column, which is its disk; its row gives the counter bit, the peg, and whether the carry travels on. Column 11 exists only to end a ten-disk line.

Inside the head

The first layer of this model uses a recurrent kind of attention.2 Each head keeps a small memory that it updates at every token. It forms a key and a value from the current token and adjusts the memory so that this key now returns this value. At full strength the adjustment replaces whatever was stored under that key. Reading uses a query in the same way.

We took over one head, the one whose removal changes the model's predictions on ordinary text the least, and gave each of its parts a job:

  1. Key. The current symbol's column picks a memory slot.
  2. Value. The symbol's contents go into that slot, replacing the column's entry from the previous line.
  3. Query. The head reads the slot of the next column, which still holds last line's entry.
  4. Gate. The model applies a gate to each channel of what was read. We use it as a selector: the current symbol opens only the channels for the column it asks about and the carry it brings. Exactly one channel is both open and non-empty. It stands for the pair "old contents, carry".
  5. Output. The output matrix sends that channel to the embedding of the next symbol. This matrix is the program's table.

One more thing makes it work, and it comes back later. The head sits in the first layer with 31 layers above it. For its choice to survive them, the next symbol's embedding is written 20,000 units long into a stream whose normal size at that point is about 3. Nothing the later layers add can outvote it.

Tape, three disks

typed by a personwritten by the model

What the head does with the outlined symbol

The weights themselves

Figure 6. The patched head running in your browser from its real weights. Step through three disks and watch each part act. Below, every row of the head's weights is drawn by what it reads on each of the 100 symbols, with the current symbol marked. Orange is "on", blue-grey is "off". Switch to the original weights to see the head as it shipped, on the same scale.

Install, stack, uninstall

Because the program lives in one head, installing it changes 2.63 million of the model's 4.2 billion numbers, about six in every ten thousand. The patch file holds only those rows. Applying it returns what it overwrote, so uninstalling restores the model bit for bit.

The model: 4.2 billion numbers The patch: 2.63 milliondrawn to scale
OperationWhat we checked
InstallApplied from its 10.6 MB file to the unmodified model
StackHanoi and Rule 110 together, in two heads: both exact over 12,512 tokens
UninstallRemoved in the other order from installing: every tensor identical to the original
SwapThe adder put into the second head in place of Rule 110

Figure 7. The patch, to scale. The small square has 0.06% of the large one's area.

The engine is not specific to Hanoi. A program is a table from "old contents, carry" to the next symbol, so a different table is a different program. We wrote two more: Rule 110, a cellular automaton in which each cell's next state depends on itself and its two neighbours, and a binary adder for numbers up to ten bits. Both install into a second head with their own letters.

ProgramSymbolsTable entriesEvery token checked, tape fed inWritten by the model alone
Tower of Hanoi1001342,112 of 2,112, one to seven disks8 and 10 disks, identical to the reference
Rule 1109011410,400 of 10,400, 40 start patterns30 generations, identical
Binary adder1101803,320 of 3,320, 464 sums20 of 20 sums

Figure 8. Three programs on one engine, all with the patch. The panel above is a simulation of the tables in your browser, not the model; the table gives what the model itself did, checked against ordinary reference code. The smallest margin by which the right token won was 35 logits. The ten-disk run is 11,264 tokens and took about fourteen minutes on a laptop.

Against prompting and fine-tuning

The two ordinary ways to get a model to do something are to show it examples and to train it. On this task neither extrapolates. Prompted with worked solutions, the unmodified model manages four disks once in six attempts and nothing larger. Fine-tuned on the complete solutions for one to six disks, it reproduces those and fails at seven and eight after 47 legal moves each: it has memorised sequences, not learned the procedure.3 The patch has seen no examples, and works at every size its tape can hold.

Who solves which size

Attempts that produced a complete legal solution

Disks (moves)3 (7)4 (15)5 (31)6 (63)7 (127)8 (255)10 (1,023)
Prompted with worked examples1 of 11 of 60 of 60 of 60 of 40 of 1–
Fine-tuned on one to six disks✓–✓✓✕✕–
Patch: no examples, no training✓✓✓✓✓✓✓

Figure 9. Prompting and fine-tuning both work inside what they were shown and stop there. The fine-tuned model writes moves and the patched model writes positions, so their outputs are graded the same way, by replaying them, but they are not the same format. A dash means not tried.

What it costs the host

Installed software should not break the machine. We compared the patched model's next-token predictions with the unmodified model's on text unrelated to the program.4 On 51,200 tokens of English prose and code, the two models agree on the most likely next token 98.5% of the time, and the average KL divergence is 0.0023. Deleting the head and installing nothing gives the same two numbers. On this text, the whole cost of the patch is the head it occupies. Two patches cost what deleting two heads costs: 0.0074 and 97.0%.

Two cautions. The first is what 98.5% means in practice: about one token in 65 changes, and when a model writes freely, one changed token can send the rest of a passage somewhere else. We had each version continue 100 openings for 36 tokens. The patched model wrote the identical continuation for 55 of them. So did the model with the head simply deleted: free writing is sensitive to any change at all. The second is text that uses the borrowed letters. On Wikipedia articles in the twelve scripts, where one token in nine is a reserved letter, the patch costs 0.013 against 0.0032 for deleting the head, four times as much, and most of all in Tamil and Arabic.

English prose and code

Average KL from the unmodified model, 51,200 tokens

Wikipedia in the twelve tape scripts

Average KL from the unmodified model, 18,432 tokens

Free writing

Of 100 openings continued for 36 tokens, how many came out identical to the unmodified model's

Three of those openings

Shaded text is where a version departs from the unmodified model.

Figure 10. Cost on unrelated text. Grey bars are controls: the same heads deleted and nothing installed. On English and code the patch costs what its head costs, and the launchable build several times more. On text in the tape scripts the patch costs four times its head. Free writing changes often under every version, the controls included. The three passages are ones we chose before running anything.

The host cannot launch what it cannot see

Up to here a person types the first line. An installed program should be something the model can start. Hanoi's call is short: an opening token, then the start line for the number of disks. We gave the model a legend listing the start line for each size, two worked examples and a new question.

The unmodified model writes the call correctly every time. It then has to invent the run, and gets it wrong. The patched model does worse. It writes the opening token and a few letters, and stops. It never completes the start line.

The reason is the 20,000. A write that large decides the output, but it also swamps everything else at that position, for every layer above it. To the rest of the network, a token that launched a run no longer looks like anything. The worked examples in the prompt each contain such a token. The model cannot see how they ended, so it cannot learn how to end its own.

Asked for three disks, each version writes

How much of the launch token survives

Similarity of its internal state to the unmodified model's, layer by layer

How large the stream is at that token

Vector length after each layer, logarithmic scale

Figure 11. Why the patched model cannot launch its own program. With the patch, the token that starts a run is unrecognisable from the first layer on: its similarity to the same token in the unmodified model falls from 1 to about 0 and stays there, because the stream at that position is several thousand times its usual length. The launchable build, described next, keeps it at 0.94 or higher until the final layer.

Write quietly, answer late

The fix keeps the computation in the first layer and moves the announcement to the last. The head no longer writes an embedding. It writes two small numbers along reserved directions of the residual stream:5 the index of the next symbol in a table, and a reference value of 0.5. Those directions are removed from the output of every other component in every layer, so the two numbers reach the top unchanged. They are also chosen at right angles to the embeddings of all the tape letters, so on a tape token they hold exactly what the head wrote.

At the last layer a bank of neurons turns the index into a symbol. Pair k switches on when the index reaches k and swaps symbol k−1 for symbol k. Ordinary tokens must not set it off, and they carry a little along any direction just by having an embedding. So two relay neurons square the reference on the way up. A real call's 0.5 becomes large; an ordinary token's stray 0.01 becomes nothing.

This is no longer a one-head patch. Removing four directions from every writer touches the 64 matrices that hold about a quarter of the model's numbers, each by a small amount, and it costs more: on the same 51,200 tokens, a KL of 0.016 and 96.0% agreement, about seven times the patch. On Wikipedia text in the tape scripts it costs 0.0095, a little less than the patch does there. It still ships as a file, 33 MB for two programs sharing one announcer, which rebuilds the edit on an unmodified model. Uninstalling it restores the weights to within rounding (the largest difference is 1.5 parts in a hundred million), not bit for bit.

The announcer

Drag the index the first layer whispers and see what the last layer says.

Figure 12. Top: the two designs side by side, drawn over the model's 32 layers. Bottom: the launchable build's last step. The relays turn a reference of 0.5 into a strong signal and an ordinary token's trace into almost none, so the bank of neurons only speaks when a program is running.

The host launches the program

With the launchable build, the model writes the call, the program runs to its halt symbol, and the model carries on. With the prompt shown below it did so for all six sizes we tried: 1, 3, 5, 6, 7 and 8 disks, the last a run of 255 moves and 2,300 tokens. On 24 general-knowledge questions in the same format it answered correctly and never started the solver.

How well this works depends on how well the prompt teaches the call. We tried two more prompts. With different wording and different worked examples, the unmodified model itself wrote the right start line for only four of six sizes, and the launchable build launched exactly those four. With a bare legend and a single example, the model found the right start line for one or two sizes out of nine, and one run launched. In all, 11 of 21 attempts launched, and every run that started was exact to its last token. The one-head patch launched none of the 21.

This is the model learning a call format from its prompt, not deciding unprompted that it needs a tool: the legend and the examples are right there. What changed is that the model can now learn from them.

We first found and fixed the problem on a smaller program, a checksum over a string of digits, whose call is made of ordinary digit tokens. There the numbers are larger. Out of 60 questions, the unmodified model working step by step gets 54 right. With the checksum written loudly at the first layer, the model never completes a call and gets 12 right by guessing. Written quietly, it completes the call and answers correctly 60 times out of 60, and on fresh numbers in three differently worded prompts, 300 times out of 300. When 30 general questions are mixed in, it calls on all 30 checksum questions and on none of the others.

One task still fails, and the failure is the host's. Asked whether a code's last digit matches the checksum of the rest, the model calls every time and the program is right about what it is given. But in 40 of 60 cases the model passes the whole code, not the code without its last digit. Installing a program does not teach the model how to use it well.

The whole prompt, and what the launchable build wrote

promptwritten by the modelwritten by the installed program

Tower of Hanoi, launched by the model

Three prompts, one attempt per size, sizes up to ten disks

A second program: check digit of a number

60 questions, final answers right

Figure 13. The model launching installed programs. For Hanoi, a launch needs the model to write the right start line, and a weaker prompt makes that rarer, with or without the program. Every run that started finished exactly. The checksum bars are the original 60 questions; three further prompt formats with 100 fresh numbers each gave 300 of 300.

How a weight is written

Everything above depends on writing a weight row that reads a chosen value on one token and exactly zero on a list of others. In the first layer this is possible because a token's input does not depend on context: it is the token's embedding, normalised. Take the token's input vector and remove from it the part that lies along each of the other tokens' vectors. What is left is a direction private to that token. Scale it so that it reads 1 on its own token. A row that should read 20 on these symbols and nothing on those is then a weighted sum of private directions.

input of symbol B input of symbol A private direction of A reads 1 on A, 0 on B A weight row is a sum of these row = 20 × private(A) − 20 × private(B) + 0 × private(C) … reads +20 on A, −20 on B,and 0 on every other reserved letter

Figure 14. The one primitive. With two tokens it is a picture: remove from A's input the part along B. The real version removes 285 other directions from each of 286 reserved tokens, in 2,560 dimensions.

Ordinary tokens are handled differently, since there are 248,000 of them. The head's keys and queries are normalised to unit length, so we add channels that read zero on tape letters and very large on everything else. An ordinary token's key and query then point almost entirely into those channels and away from the memory.

Two choices sit near the edge of the rule and should be stated. Private directions are arithmetic, but building them amounts to solving a small linear system. And for the launchable build, the directions to reserve were chosen by clearing candidates one at a time and measuring the cost on ordinary text: a search over where to write, never over what.

The rule comes from Language Models Can Rewrite Their Own Weights, which has a model edit itself with no gradients and asks that "every value" in an edit be "written by the model's own reasoning". Its edits are coarse and remove obstacles; none installs a new behaviour. Looped Weight-Space Programming runs far harder programs than ours, mazes, Sudoku and a million-move Hanoi, in networks written from nothing. What is different here is the host: the program goes into a pretrained model that keeps working, through its normalisation layers and in its existing tensors, and the model can be the one to start it.

Limits

  • The launchable build costs several times more than the patch on ordinary text, and its uninstall is exact only to rounding. All three programs run on it, and two can share one announcer, but with two the narrowest winning margin fell to 1.8 logits, so that table is close to its limit.
  • Launching depends on the prompt. Six of six with our main prompt, four of six and one of nine with two others. The model has to be taught the call, and a 4B model is easily confused about it.
  • Half precision breaks both builds. Rounded to the 16-bit format the model ships in, the patch gets 446 of 640 tokens right and the launchable build 19 of 320. They need the model loaded at full precision.
  • The output is a tape, not an answer in words. The model never converts it to moves.
  • Small scale. This build gives the tape 11 columns, so Hanoi stops at ten disks, and it writes about 14 tokens a second.
  • One model. Everything here is one 4B checkpoint whose first layer happens to have a recurrent memory. We have not tried another architecture.
  • Not written by the model. A larger model and a person wrote these edits over many attempts, with tests in the loop.
  • The same method could hide a trigger, though not quietly. A patch that ordinary evaluation barely registers is also a way to plant behaviour. These edits are trivial to find in the weights: the largest weight in the model as shipped is 0.7, and the patch contains weights of 93,000. We have not tried to make them hard to find.

Appendix: what broke along the way

A zero is not zero. The design needs some weights to read exactly zero on certain tokens. Stored as 32-bit floats they read about one part in ten million instead, and the head multiplies whatever it reads by the size of its write. On a test page we wrote in the twelve scripts, that turned rounding error into wrong predictions. The cure was to make "off" a firmly negative value, where the activation function is flat, and only for the program's own symbols. Doing it for every token switched the machine on for common English words and cut agreement with the original model to 40%.

Cost on a page we wrote in the twelve scripts, fix by fix

Average KL from the unmodified model, logarithmic scale

    Figure 15. The same 907-token page after each change to the engine. Deleting the head costs 0.0030 on this page.

    The quietest directions were the expensive ones. For the launchable build we first reserved the coordinates the network writes to least, expecting it to miss them least. Clearing those three cost 0.029 in KL, ten times more than three coordinates of median use. No weight statistic we tried predicted the cost, so we measured it. Four chosen that way cost 0.0033 together.

    Cite this work

    A paper version of this article is archived on Zenodo with the code, the patches and the measured results: doi:10.5281/zenodo.24570919.

    @misc{bourgeois2026installed,
      author    = {Bourgeois, Dylan},
      title     = {Installed, not trained: plugging programs into a model's weights},
      year      = {2026},
      publisher = {Zenodo},
      doi       = {10.5281/zenodo.24570919},
      url       = {https://doi.org/10.5281/zenodo.24570919}
    }
    

    Model: Qwen3.5-4B-Base, 32 layers, run at 32-bit precision. The patch occupies key head 5 of the first layer and its two value heads. Every figure uses measured values from the runs described.

    Footnotes

    1. One greedy and several sampled attempts per size. The prompt held worked solutions for the smaller sizes, up to four disks. ↩

    2. Three of every four layers in this model use it. Each head carries a memory matrix forward from token to token and updates it with a delta rule. ↩

    3. Low-rank adapters on every layer's MLP: six million trainable numbers, 360 gradient steps, about seven minutes. This is the only place in the project that uses gradients. ↩

    4. KL divergence measures how far one probability distribution is from another; zero means identical. Agreement is how often both models rank the same token first. ↩

    5. The residual stream is the running vector each token position carries up through the layers. Every layer reads it and adds to it. ↩