Command Palette
Search for a command to run...
Language Models Can Rewrite Their Own Weights
Language Models Can Rewrite Their Own Weights
Abstract
A language model is trained once and frozen. Making it better takes another training run, or a prompt, a harness or extra computation at inference that is gone once the task ends. We show a third way: to our knowledge for the first time, a language model rewrites its own weights by its own reasoning and becomes better, with no gradients and no training. We call this self-rewriting: the model is its own optimizer. In earlier work, a frontier model edited a much smaller one; here an open 27B model, given its weights, its graded answers and the ability to run itself, diagnoses its own failure and rewrites the weights behind it. It surpasses itself: its own edit makes it 6.6 points more accurate on problems it never saw. It keeps getting better: it tests its edits on practice problems and submits only what works, each edit improving on the last, and over eight consecutive sessions its accuracy only rises. It repairs a damaged copy of itself, like a broken robot that fixes itself without being rebuilt: the copy solves almost nothing, yet with no retraining and without ever reading the original weights, the model brings it back to over 80% of the original accuracy on image tasks it never saw. And the ability emerges with scale: in one model family, the smaller models make no edit or break themselves, and only the largest improves and repairs itself. Unlike test-time scaling, self-rewriting writes its gain into the weights, at no cost per answer; unlike training, it runs only forward passes, as serving does. The wall between training and inference is a limit of our tools, not a property of intelligence. We believe self-rewriting is a necessary step toward recursive self-improvement: a model that, like a human, does not separate training from inference could keep upgrading itself for life, with no larger model, no harness or prompt engineering, and no preor post-training.
One-sentence Summary
Researchers at UIUC and collaborators show that an open 27B language model can self-rewrite its own weights through its own reasoning, acting as its own optimizer without gradients or training, improving accuracy by 6.6 points on unseen problems, repairing a damaged copy to over 80% of original accuracy, and exhibiting this capability only at scale.
Key Contributions
- Self-rewriting is introduced, in which a 27B open model inspects its hidden states and weights, diagnoses its own failures, and edits its weights without gradients or training. A resulting edit improves accuracy by 6.6 points on 490 unseen problems in a paired test.
- Self-repair is demonstrated, where the model finds and corrects a corrupted matrix in a damaged copy without retraining or reading the original weights, restoring the copy to 83% of base accuracy on unseen image tasks. In one model family, only the largest model improves and repairs itself while smaller models fail or damage themselves.
- Iterative self-improvement uses self-tests and rollbacks: the model evaluates candidate edits on practice problems, keeps only edits that work, and withdraws failed edits. Over eight sessions it ends with higher accuracy while adding no cost per later answer.
Introduction
Language models are typically trained once, frozen, and deployed; improving them afterward normally requires large-scale training infrastructure, while user interaction can change only prompts, whose effects disappear when the task changes. Prior self-improvement work has rewritten prompts or agent code, left weight changes to optimizers or gradient-based training on model outputs, or relied on a stronger model to edit a smaller model, and fault repair has generally depended on engineer-designed procedures. The authors introduce self-rewriting, in which a language model diagnoses its own failures and edits its own weights through reasoning alone, without gradients, optimizers, or a training pipeline. They show that a 27B open model can test edits against its unedited self and keep only beneficial changes, improving accuracy by 6.6 points on 490 unseen problems and repairing a corrupted copy of itself; the ability emerges with scale, since smaller models either fail to edit or break themselves.
Method
The authors introduce a method termed Self-Rewriting, in which a model improves its own weights through reasoning alone, acting as its own optimizer without gradient descent or external training infrastructure.
Problem Definition Let Mθ denote a model with weights θ=(Wk)k∈K. For every token at every layer, the model computes a hidden state vector, updated through attention and MLP output matrices. Given a problem x, the model generates a response y under fixed settings π (prompt, sampling, and a token budget L). A response is graded g(x,y)=1 if the thinking concludes within L tokens and the final answer matches the reference, and 0 otherwise. The accuracy on a task distribution D is defined as:
Acc(θ;D)=Ex∼DEy∼Mθ(⋅∣x;π)[g(x,y)]An edit Δ replaces a subset of tensors in θ with tensors of the same shape, producing θ⊕Δ. Self-rewriting tasks the model with writing an edit Δ^ such that Acc(θ⊕Δ^;Dtest)>Acc(θ;Dtest), where Dtest is a held-out set. Crucially, no gradients with respect to θ are computed, and no optimizer acts on θ; every value in Δ^ is written by the model's own reasoning.
The Session Framework The model modifies its weights through a session of turns. As shown in the framework diagram, the editor Mϕ is the model itself (ϕ=θ). Its base weights remain static, and the current edit applies only to the specific runs it requests.
Before the first turn, a starting diagnosis answers N0 practice problems to report failure modes, such as accuracy, token limit exhaustion, or repetition. At each turn, the model writes a rationale and selects one action:
- Code: Runs Python on a CPU within a session that maintains variables and allows reading or replacing weight tensors. A helper function computes W−αuu⊤W, weakening the projection of a matrix W along a unit direction u of the hidden state by a fraction α.
- Generate: Answers practice problems using the unedited weights, the edited weights, or both.
- Read: Returns the hidden states of the weights on chosen texts.
The session operates under strict constraints: it allows B=20 forward passes and C=200 code runs. The environment disables gradients, refuses optimizer calls, and lacks GPU or network access. Edits to input embeddings, final normalization, and output layers are prohibited, as are edits that merely rescale a tensor.
Paired Test and Evaluation When the Generate action runs both weight sets, the unedited and edited models answer the same problems with identical seeds, forming pairs. For m problems with n answers each, the test reports the mean difference δ^ and standard error:
δ^=m1i=1∑mdi,SE(δ^)=m(m−1)1i=1∑m(di−δ^)2,di=n1j=1∑n(gij1−gij0)where gij0 and gij1 are the grades without and with the edit. Before submission, the framework tests the edit on reserved practice problems unseen during the session, and the model decides whether to submit or withdraw the edit.
Damaged Copy and Repair Process To evaluate self-repair, the authors construct a damaged copy θ~ where a block R of consecutive rows in the MLP output matrix W of one layer is overwritten with noise:
W~r,:∼N(0,(λσ)2I)for r∈R,∣R∣=8,λ=200The undamaged model acts as the editor, receiving only the damaged copy's weights and diagnosis. It is informed that some values are corrupted but not their location or nature.
The following figure illustrates the step-by-step process of a repair session. The model begins by diagnosing symptoms (e.g., high token cutoff rates), reads hidden states to locate anomalies (e.g., activation explosion), attempts edits like clipping outliers, evaluates them via paired tests, and iteratively refines the repair until a final edit is submitted.
Experiment
The study evaluates Qwen3.5 models from 2B to 27B on self-editing and on repairing a copy whose MLP output matrix rows are corrupted with noise. The 27B model diagnoses the damage by measuring activation and weight statistics, identifies the corrupted layer, and applies a conservative clipping rule that restores performance, even transferring to unseen image tasks despite being found on text problems only. In self-editing, the same model tests and refines a small change that improves its accuracy on held-out problems, while smaller models either fail to edit or harm themselves. Overall, the results indicate that reliable self-repair and self-improvement emerge only at larger scale and depend on measurement-driven debugging rather than random edits.
The 27B model found that a damaged copy failed mainly because one MLP output matrix contained an extreme weight outlier, and it repaired the copy by clipping a very small fraction of weights in that matrix and nearby matrices, recovering partial held-out accuracy from total failure. For its own weights, it located a hidden-state direction separating answers that finish from those that run out of tokens, then removed a small component of that direction from two layer-8 output matrices, yielding significant improvements on both its own task and held-out performance. Smaller models either made no edit or harmed themselves, while only the 27B model made and kept a beneficial change. Repairing the damaged copy by clipping rare extreme weights restored held-out accuracy from zero to a partial recovery. For its own weights, subtracting a small component along the discovered hidden-state direction led to small but significant accuracy gains on both the model's own task and a held-out evaluation.
Across model sizes, only the 27B model improves itself on its own task and on held-out problems, while the 2B model makes no edit and the 4B and 9B models break themselves. The 27B model also repairs a noise-damaged copy of itself, recovering held-out accuracy without retraining or restoring the original weights. The 27B model's self-edit is significantly better than the base model on both its own tests and held-out problems. Smaller models fail at self-editing: 2B makes no edit, and 4B and 9B edits leave the models broken or unable to answer held-out problems. The 27B model repairs a corrupted copy from near zero accuracy to more than half of the base model's held-out accuracy, using its own values rather than restored weights.
Self-rewriting is the only route that changes weights without training, is chosen by the model itself, inspects its own internals, and adds no extra cost per input. Other self-improvement routes either do not change weights or rely on an optimizer, while existing weight-editing routes are driven by researchers or a stronger model rather than by the model being edited. In scaled experiments, smaller models fail to edit or harm themselves, while only the largest tested model improves itself and repairs damaged weights. Self-rewriting uniquely satisfies all five properties: it changes weights, needs no training, is chosen by the model itself, looks inside itself, and adds no extra cost per input. Prompt and agent-code rewriting and inference-time self-refinement leave weights unchanged, while training on the model's own outputs changes weights only through an optimizer. Model editing, direction ablation, and weight editing by a stronger model change weights but are not chosen by the model itself and do not look inside itself. Under the same task and tools, smaller models either make no edit or degrade themselves; only the largest tested model improves itself and repairs a damaged copy.
Experiments tested whether language models can inspect and edit their own weights without training, comparing multiple model sizes on self-improvement and repair of a damaged copy. The 27B model recovered a corrupted copy from near zero held-out accuracy by clipping rare extreme weight outliers, and improved itself by subtracting a small component along a discovered hidden-state direction from two output matrices, yielding gains on its own task and held-out problems. Smaller models either made no edit or degraded themselves, and the analysis identifies self-rewriting as the only route that changes weights without training while remaining chosen by the model itself and adding no per-input cost.