Quick Answer: Weight-space programming means changing a model's weights directly instead of training it. In a recent MIT CSAIL experiment, an agent fixed looping in Qwen3.5-0.8B by changing 0.016% of its weights. Choosing which weights to change, and by how much, is a linear program. Two LP solves reproduce the agent's result while changing eight times fewer weights.
Last week, MIT CSAIL published Sparks of Weight-Space Programming. Given only a game's rules, an agent called Astra wrote the weights of a small network from scratch, and those weights beat networks trained with PPO for 100 million steps. No gradients, no training loop. Looking at Astra's math-editing run, though, I noticed most of its search was a linear program solved by trial and error. As Nathan Barry's write-up shows, the problem fits an LP cleanly, and the fix gets much cheaper.
Why small reasoning models get stuck in thinking loops
Small reasoning models often fail the same way. They repeat the same few lines instead of finishing their reasoning. Qwen3.5-0.8B is especially prone to this, and its model card says so. On MATH-500, 93% of the base model's answers hit the 32,768-token limit without ever producing a final answer.
That's the real bottleneck. The model often has the ability to solve the problem, but the loop blocks it. Astra's edit lifted MATH-500 accuracy from 7.9% to 48.1%, and IFEval from 21% to 62%, because the fix works anywhere the model loops. The share of answers hitting the token limit fell from 93% to 33.1%.
The limit is worth knowing. On Gemma 3 270M, which rarely loops, Astra couldn't meaningfully improve math ability. The authors' explanation fits: editing weights can remove an obstacle that hides an ability, but it can't add an ability the model lacks.
Finding the loop direction in the residual stream
Transformers use residual connections. Each layer adds its output to its input rather than replacing it. Follow one token through the network and you get a single vector, the residual stream, which every layer adds to. In this model it has 1,024 dimensions.
When the model loops, the residual stream drifts in a consistent direction. Astra found that direction in a simple way. It wrote four pairs of short texts, each a piece of productive reasoning and a looping version of the same reasoning. It recorded each token's residual stream vector at one layer, averaged the looping vectors, averaged the productive ones, and took the normalized difference. That gives the loop direction $u$.
Finding $u$ took about 15 minutes of Astra's roughly 10 hours of work. The rest went to a harder question.
Editing the weights with a rank-1 change
Each MLP ends with a matrix $W$, called down_proj. It maps the MLP's 3,584-dimensional hidden activation $h$ into the 1,024-dimensional residual stream:
$$x \leftarrow x + Wh, \qquad Wh = \sum_j h_j , w_j$$
The output is a weighted sum of the columns $w_j$ of $W$. The weights fix what those columns are. The activations $h_j$ set how much each one is added at each token.
Each column has a component along the loop direction, $u^\top w_j$. That's how much the column pushes the model toward looping whenever it's active. Astra's edit subtracts a multiple of that component:
$$w_j \to w_j - \alpha , (u^\top w_j) , u$$
At $\alpha = 1$, the loop component is gone. At $\alpha = 6$, it's flipped, so a column that once pushed toward looping now pushes away from it. Here's the key observation: every edited column changes by a multiple of the same vector $u$. The whole edit is one direction plus one number per column. That makes it a rank-1 change, $\Delta W = u,v^\top$, which adds $(v \cdot h_t),u$ to the residual stream at each token.
So the real question is what $v$ should be: which columns to edit, and how large $\alpha$ should be.
Where the agent's eight hours went
The paper released Astra's full logs, which makes it possible to see the search. Astra had a Python kernel with the weights loaded and a budget of 50 forward passes. It used them to test candidate edits on fresh training problems.
Its tuning was systematic but slow:
- Edit every column in layers 15 and 19 with $\alpha = 1$: accuracy rose from about 9% to 33%.
- Increase to $\alpha = 2$ and $\alpha = 3$: accuracy reached 43% and 48%.
- Run a random direction as a control: accuracy stayed at 12.5%, so the direction matters.
- Keep only the top 64 columns per layer and push to $\alpha = 6$: accuracy reached 55%.
Most of the time went into that final stage. Astra spent about 8 hours choosing $v$. The edit was frozen after about 10 hours, and the last 17 forward passes re-tested it without changing anything.
Choosing the edit is a linear program
Astra was searching for a $v$ that pushes looping tokens away from $u$ while barely touching productive ones. The push at token $t$ is $v \cdot h_t$, which is linear in $v$. That means both goals become linear constraints. That's the whole trick.
Labeling the training data is the first step. Tokens deep inside a loop count as looping. Tokens well before any loop starts count as productive. The author recorded their activations $h_t$ at layers 15 and 19. Then the LP is:
- Looping tokens: require $v \cdot h_t \le -\delta$, pushing each one at least $\delta$ away from $u$.
- Productive tokens: require $|v \cdot h_t| \le \varepsilon$, leaving each one almost untouched.
- Objective: minimize the L1 norm $\sum_j |v_j|$.
No $v$ satisfies every constraint exactly, so each constraint gets a penalized slack variable. The L1 objective is the clever part. Its feasible ball is a diamond, and when it grows until it touches the feasible region, it usually touches a corner, where most coordinates are exactly zero. Sparsity isn't a separate step. The solver picks the columns and the amounts together.
To get exactly eight columns per layer, the author keeps the eight with the largest effect and re-solves with the rest fixed at zero. Off-the-shelf HiGHS took over 20 minutes per solve on these constraints. The author wrote a GPU solver based on PDHG, the algorithm behind PDLP, which gets within 0.2% of the optimum in about a minute. That replaces Astra's eight-hour search with a couple of solves.
Here's where it gets interesting: the LP doesn't need the exact columns Astra picked. Only 3 of its layer-15 columns and 1 of its layer-19 columns overlap with Astra's 64. Many sparse solutions work, as long as they add up to enough total push along $u$.
Results: the LP matches the agent with 8× fewer changes
The author tested two LP edits on the same layers. One uses Astra's loop direction. The other uses a heuristic direction, found by labeling tokens with a simple repetition detector, so no LLM is involved. The LP's settings were tuned on a separate 128-problem dev set, and every reported number comes from data the fitting never saw.
| Edit | Changed weights | GSM8K test | MATH-500 |
|---|---|---|---|
| Base model | 0 | 14.1 | 7.0 |
| Astra's edit | 130,188 | 68.2 | 50.9 |
| LP, Astra's direction | 16,291 | 69.6 | 51.7 |
| LP, heuristic direction | 16,271 | 65.4 | 47.8 |
With Astra's direction, the LP matches Astra's edit within noise while changing about 8× fewer weights. On IFEval it scores 59.7 against Astra's 61.9. With the heuristic direction, the LP gets roughly 93% of the way there.
Two caveats. First, the search matters. Reusing Astra's recipe on the heuristic direction without searching again scores 44.5 on the dev set, while the LP scores 54.7. Second, the direction matters too. A random direction of the same size scores 10.2, against 10.9 for the base model. Sparse, cheap, and correct beats sparse and random.
A steering vector does the same job, and what that means
The common assumption is that a loop edit must target loop-like tokens specifically, which is what the per-token constraints are for. The data says otherwise. A loop isn't recognizable from activations until it's well underway, so on the dev set, pushing only on loop-like tokens did no better than pushing on every token. The LP's layer-15 columns are active on 89% of tokens, and their push barely varies from token to token. The edit is close to a constant push along $u$.
A constant push doesn't need a weight edit. You can add it at inference time as a steering vector, a fixed vector added to the residual stream at every token. The author added the LP edit's average push to the unedited model at layers 15 and 19:
- At 0.5× the average push, MATH-500 reached 51.6 on the dev set's loop-fixing measure, and the loops came back.
- At 1×, the steering vector recovered essentially the full fix: 57.8 on the dev set and 50.8 on MATH-500.
- At 2×, the loops stopped, but the reasoning fell apart: 31.2.
The window is narrow. The only real difference between the two approaches is delivery. The LP edit is an ordinary checkpoint. The steering vector needs extra code at inference time.
The write-up is clear about the limits. This is one model. The LP still depends on Astra's chosen layers, and the best results use Astra's direction. The heuristic direction gets most of the way without an LLM, not all of it. Loops also turned out to be fixable with a near-constant push, so the per-token constraints didn't matter much. A behavior that should change some tokens and leave others alone would be a better test of them. Removing loops is also only one behavior. Refusal and sycophancy have been steered with single residual directions too, but this post doesn't test them, so treat that as a hypothesis.
Frequently Asked Questions
What is weight-space programming?
Weight-space programming means writing or editing a neural network's weights directly, instead of training it with gradient descent. In the MIT CSAIL work, an agent called Astra reasoned about what the weights compute and produced working networks without a training loop. In this follow-up, it changed only 0.016% of Qwen3.5-0.8B's weights to stop it from looping.
How do you stop thinking loops in a small reasoning model?
Find a residual stream direction associated with looping by comparing activations on looping and productive text. Then subtract a scaled component of that direction from the weights of the MLP down-projection layers that write to it. Choosing which columns to edit is the hard part, and a sparse L1-minimizing linear program can handle it in about a minute of solver time.
Why does a loop edit work on some models but not others?
The edit can only remove an obstacle the model already has the ability to overcome. Qwen3.5-0.8B loops on 93% of MATH-500 answers, so removing the loop unlocks reasoning it already had. Gemma 3 270M rarely loops, so there was little to remove, and Astra couldn't meaningfully improve its math results.
Is a steering vector the same as a weight edit?
Nearly, for this behavior. Adding the LP edit's average push as a fixed vector at inference time recovered almost the whole fix at 1× strength. The window is narrow, though: half the strength brings the loops back, and double the strength breaks reasoning. A weight edit ships as a normal checkpoint, which is why many teams would choose it.
Weight-space programming doesn't have to be a trial-and-error search. If you're editing a model to change one behavior, start by finding the direction, then write the choice of weights as a linear program with a sparsity objective. Try it on one layer this week and check the changed-weight count against a full-edit baseline. Pass this to anyone spending hours tuning a weight edit by hand.