Weight-Space Programming, Step by Step
When can we fix a model directly, what happens to its other abilities, and can programming give fine-tuning a better starting point? A detailed, interactive walk-through on the recorded data.
- Written by
- Puneet Bajaj
- Published
- Reading time
- 13 min read
When a model does not behave the way we want, we usually fine-tune it. We collect examples of the behaviour we want, define a loss function and let gradient descent figure out what needs to change in the model.
But what if we already know what needs to change? Do we still need the model to learn it?
In Sparks of Weight-Space Programming, the researchers demonstrated another way of changing a model: give a capable LLM access to a smaller model’s weights and let it write the changes directly, without gradient descent. Coming from a software engineering background, I found this particularly interesting. We might be able to investigate why a model behaves a certain way and write a fix rather than teach it the desired behaviour from examples.
I wanted to see when this would work better than fine-tuning. One of the programmed models went from answering 21.1% of a set of factual questions correctly to answering all of them. On general knowledge, however, the same model dropped from 59.6% to 22.2%. Another edit that got fewer of the facts right gave us a much better starting point for training.
The first experiment raised a different question
I started with a problem I had been working on: predicting how real people would answer survey questions. I used the Twin-2K-500 dataset and compared weight-space programming (WSP) with LoRA fine-tuning on Qwen2.5-1.5B-Instruct.
The first programmed edit improved accuracy from 30.9% to 32.8%, while LoRA reached 42.8%. But there was a simpler approach that did better than both. We could ignore who the person was and predict the most common training answer to each question. That got 47.1%.
A later programmer reached 45.0% by constructing a circuit that approximated population answer frequencies. It improved the model’s ability to predict survey answers without making use of the individual. If that was the behaviour we wanted, there was little reason to put the answer frequencies inside a model in the first place. A statistical table already did it better.
This made me think about the different things we expect a model to learn during fine-tuning. A model might already know something but use that knowledge incorrectly. We might have new information that we can write down as a table. Or we might need the model to learn a relationship between inputs and outputs that we cannot readily specify ourselves.
To compare these cases, I used four tasks with the same five-option answer format: ordinary sentiment classification, sentiment with reversed labels, survey prediction and facts about invented people. The programmer could inspect and modify the weights, with a budget of 50 recorded forward passes of up to 512 examples each. The brief allowed explicit tables built from training labels, but prohibited gradient training, label-fitted solvers and access to the test set. LoRA, by comparison, learnt rank-16 updates to the model’s attention and MLP projections using gradient descent. Its default budget was 4,000 training presentations.
The visual below shows where a few of the resulting edits were made. The important difference is that the programmer could choose which parts of the network to change, whereas the LoRA configuration made adapters available throughout all 28 layers.
Can we fix what the model already knows?
Consider a movie review that is clearly positive. A sentiment classifier should normally select the positive label. Now suppose we reverse the expected answers: positive becomes negative, very positive becomes very negative, and neutral remains neutral. We leave the prompt exactly as it was. Only the correct answer in our evaluation changes.
Qwen’s accuracy dropped from 44.9% on ordinary sentiment classification to 4.0% on this mirrored task. A linear probe of its activations suggested that much of the information needed to answer correctly was still there. The challenge was to get the model to use it differently.
All four completed programming attempts on Qwen independently arrived at the same main fix: swap the input embedding rows for the tokens representing ‘negative’ and ‘positive’ (with their leading spaces). Each row contains 1,536 numbers, so the swap changes 3,072 entries in a model with around 1.54 billion parameters. There is no gradient training involved.
The swap alone raised test accuracy to 46.2%. Swapping two unrelated words instead left it at 4.0%. We also repeated the experiment on SmolLM2-1.7B, where the same two-word swap improved accuracy from 11.4% to 38.6%.
Try the actual test reviews below. Notice what happens when the model was confidently wrong about the expected polarity, and then try a neutral review.
The edit is not a complete solution. The model still struggles to recognise neutral sentiment, and changing two embeddings does not improve its understanding of all five categories. This is more apparent when we go back to ordinary sentiment classification.
On that task, the best programmed edit reached 48.0%, while LoRA reached 59.0%. Even when I reduced LoRA’s training pool to 256 distinct reviews, it achieved 54.2% (with the same number of training steps). A small correction that worked so well when the labels were reversed was not enough to improve the original classifier. Here, the model needed a better mapping from a review to one of the five sentiment categories.
What if there is nothing to redirect?
Reversing sentiment is convenient because the model already has some knowledge of sentiment. What happens if we give it information it could not have seen during pre-training?
I generated 300 fictional people and assigned each a random birth city, profession and hobby. That gave us 900 facts. The training and test questions referred to the same facts, but used different wording. The correct fact was not included in the question as context; the model had to recall it from its weights and choose the right option.
The base model scored 21.1%. With the default 4,000 training presentations, LoRA reached just 22.2%. Three independent Fable programming runs, however, got all 900 test questions right.
The programmers had access to the training labels, so they did not need to discover the facts. They wrote the supplied table into the weights, along with the computation needed to look up an answer. I had expected programming to be most useful when a model already knew something. Here it had managed to store entirely new information, but it did so in a very different way from gradient training.
Then I tested the rest of the model. One of the perfect fact-recall circuits took Qwen’s MMLU accuracy (a general-knowledge benchmark) from 59.6% to 22.2%. Its next-token accuracy on WikiText-2 fell from 45.9% to zero. The pattern repeated on SmolLM2: perfect fact recall, but MMLU fell from 48.8% to 22.6%.
A 100% score on the target task was hiding a much more serious failure. The programmer had found a way to answer our questions that no longer relied on much of what made the original model useful.
Can we store the facts without bypassing the model?
The lookup circuit was built largely in the first two layers. It gathered the tokens making up a person’s name, identified which option matched the stored fact and wrote a strong signal for that option’s letter. That signal dominated the computation that followed.
Another programmer, Opus, approached the problem differently. Instead of building its own question-answering circuit, it tried to write a representation of the relevant fact into the model’s existing computation. The model would then use its own ability to connect that information to the available options. The final edit repurposed 900 MLP neurons in layer 8, one for each person-attribute pair.
I refer to the former as a bypass edit and the latter as a through edit. Follow the same input through both below. The example is particularly useful because the lookup circuit gets it right and the memory edit does not, even though the memory edit is much better at preserving the model’s general behaviour.
The Opus memory edit recalled 76.9% of the facts. MMLU remained at 59.6%, and next-token accuracy was 45.6%, close to the original 45.9%. It was not the most accurate way of storing the facts, but it left the model in a much more useful state.
How the programmer arrived at the memory edit
It is worth looking at how that edit was developed. The first version wrote all three attributes into the representation of the last token of a person’s name. That reached 50.8% on the development set. When the programmer injected only the requested attribute in a diagnostic experiment on 512 training questions, accuracy reached 93.0% under one configuration. Adding unrelated random vectors of comparable magnitude brought performance back down, suggesting that writing too much at one position was part of the problem.
The programmer then tried distributing the attributes across different name-token positions. Several candidates were evaluated; the best measured development accuracy was 73.0%. That was the edit it selected, and the subsequent held-out test evaluation gave 76.9%.
There was still a question about what we had asked the programmers to optimise. The original brief did not explicitly require them to preserve general ability. When I added a preservation requirement on the survey task, the programmer chose a gated attention edit rather than a bypass circuit. Survey accuracy reached 35.2%, a smaller improvement than before, but accuracy on an unrelated sentiment task stayed at 42.2%, compared with 42.3% for the base model. On fictional facts, the preservation run failed to find an edit that both stored the facts effectively and met the preservation criterion.
So preserving other abilities is not something I would leave implicit in a programming brief. It changes the problem we ask the agent to solve, and sometimes comes at the cost of target accuracy.
Maybe we should program before we train
By this point, I was less interested in whether weight-space programming could beat LoRA. The two methods had run into different problems. Programming could write a specific correction or a table directly into the weights, but it did not do as well when the model needed to improve a more general mapping. LoRA could learn that mapping, but on some tasks it struggled under the default training budget.
What if we first made the change that we knew how to make, and then let gradient descent learn the rest?
To understand why the starting point might matter, look at the training losses on mirrored sentiment. When a model assigns equal probability to each of the five answer letters, its cross-entropy loss is about 1.609 (the natural logarithm of five). The unedited model started out confidently wrong. Two of the three LoRA runs stayed near the uniform-prediction reference throughout the available training budget. The runs that began from the programmed edit were already at a much lower loss by the first logged point.
The curves below are actual logged training losses. Switch between tasks or include the longer runs to see what happens when LoRA is given more training presentations.
On mirrored sentiment, LoRA trained on top of the programmed Qwen edit reached 57.3-58.5% across all three seeds, compared with 49.3%, 23.9% and 27.7% when it started from the unedited model. A hand-written version of the two-row swap worked just as well as the full programmer edit once LoRA was applied. On SmolLM2, the combined approach reached 55.9-56.6% on all three seeds, whereas ordinary LoRA remained near chance at the same budget.
The facts experiment showed an even larger difference. Instead of using the perfect but destructive lookup circuit, I started LoRA from the Opus memory edit. With 4,000 training presentations, the combined model reached 99.0-99.7% across three seeds, while MMLU remained between 58.0% and 59.6%.
| Starting point | Training presentations | Fact test accuracy |
|---|---|---|
| Unedited model | 4,000 | 22.2% |
| Unedited model | 40,500 | 98.8% |
| Programmed memory edit | 4,000 | 99.0-99.7% |
Ordinary LoRA was eventually able to learn the facts too, given 40,500 presentations. On mirrored sentiment, increasing its budget to 12,000 presentations allowed all three Qwen runs to reach 58.1-61.2%. The starting edit appears to save training rather than raise the eventual ceiling. We did not test intermediate presentation budgets at the default learning rate on facts, nor between 4,000 and 12,000 on mirrored sentiment, so we do not know the minimum required budget. We also did not try longer LoRA runs on SmolLM2.
There is an important distinction between training presentations and unique examples. In the facts experiment both approaches saw the same 900 facts; LoRA alone needed to see the training examples more times in the configurations we tested. Programming has its own cost as well. It takes agent tokens, GPU evaluations and time to investigate the weights. Fewer gradient steps do not automatically mean a cheaper process overall.
Where I think this becomes useful
When we fix a problem in software, we generally try to work out which part of the system is responsible. If we know the required change, we can write it. When working with models, we often start with fine-tuning even when we might be able to identify part of the problem first.
I don’t think weight-space programming should replace fine-tuning. What interests me more is the possibility of using it to give fine-tuning a better starting point. A programmer might find a way to redirect knowledge the model already has or write information into a part of the network that can use it. Gradient descent can then improve the behaviour without having to learn the entire change from scratch.
These experiments were on two small model families, with a few tasks and limited runs per task. The tasks also differ in ways other than how much knowledge is already in the model. We don’t yet know how well the approach transfers to larger models or more complex behaviours. What the results do suggest is that before we change a model, we need to ask two questions: what does it actually need to learn, and what do we need it to keep doing afterwards?
This is the detailed, interactive follow-up to What If We Programmed Models Instead of Training Them?, which covers the same findings more briefly. Both accompany my working paper, Compile, Learn, or Both? When Weight-Space Programming Helps, What It Breaks, and Why Combining It with LoRA Matters. The study includes 20 completed programmer runs, 18 independently audited; one protocol-violating run is excluded from the main comparison. The full experimental protocol, code, individual results and audits are available in the research repository. The figures use the recorded data from version 1.1.2; the network-flow visual is schematic. Read the paper on Zenodo.