WeightCode: frozen LLM writes programs that edit weights directly, beating fine-tuning on 64 images

WeightCode: Installing New Capabilities into Neural Networks via Weight-Space Programming

Bo Li, Taoyong Cui, Bob Zhang, Mengran Li, Chengyang Zhang, Yang Zhang, Pheng Ann Heng, Wanli Ouyang, Zhenfei Yin, Yingcheng Wu, Ling Yang

cs.LG, cs.AI

2026-11-19

A frozen LLM writes executable programs that edit trained networks' weights directly, no gradients: SCAN 0→99.8%, and 64 ImageNet images beat eight fine-tuning methods.

What problem this solves

Adding a capability to a trained network normally means fine-tuning: labeled data plus gradients. The pain points are familiar. With few labels the update either fails to learn or wrecks clean accuracy, and what survives is just a bag of numbers. Copy that numerical edit to an independently trained network of the same architecture and it does almost nothing, because different trainings place related functions in different weight coordinates. Model editing handles local behavior fixes; task arithmetic requires a shared pretrained starting point. Neither turns task knowledge into new computation.

WeightCode restates the problem: have an executable program read the weights. A frozen LLM writes a weight program that takes the network's weights W and task knowledge I (a rule, demonstrations, or labeled examples) and returns W′ = p(W, I). No gradients anywhere, and once installed the capability runs without the LLM. Concurrent work had already shown that LLMs can read and write small-network weights; the contribution here is that the program is kept, rerunnable on other networks, and extendable by later programs.

Method

A session runs in a Python kernel where the LLM can read the weights, run the forward pass and inspect I, alternating between inspection, writing candidates and evaluation. Each session gets at most 8 checks; a check reports two counts on a held-out split: new-condition inputs fixed minus broken, and the same count on old inputs. The retention rule caps old-input loss at 20 of 4,000 clean check images. Programs execute in a sandbox with NumPy only, no network access, and may change at most 20% of the weights.

What the kept programs write matters more than the plumbing: they reuse computation the network already has. On SCAN, the program moves the embedding of jump to the centroid of walk, look and run and adds one output row, so the compositional machinery the Transformer already owns carries the new verb, at a total of 257 weights. On the ViT, the noise program finds MLP units that are nearly idle on clean images, folds their mean output into the bias to free them, and rewrites them as a gate that opens only when a token's projection along a measured noise direction leaves the clean range, then subtracts the measured shift. The correction is conditional, so clean inputs barely trigger it. That is why clean accuracy survives.

Three operations define reuse. Copying adds ΔW unchanged to another network. Rerunning executes the same code on a new network, which remeasures and relocates, with no LLM call. Succession writes a new program for an already-edited network, with checks that also cover the earlier condition.

Results

SettingProgramBaseline
SCAN unseen verb compositions (exact match)0→99.8%, 257 weightsgrammar-data training: 99.6%, 152,718 weights
SCAN around-right17.6%→89.6%, −0.3 on old commandsfine-tuning net gain ≤ +2.61 (selection split)
BabyAI pickup success0→98.4%, 8 demosbehavior cloning ≤1.1%
ImageNet noise (net gain)+10.47 / +17.62best of 8 fine-tuning methods: +8.67
ImageNet contrast (net gain)+8.84 / +14.26best fine-tuning: +3.38
ViT-Lite noise, CIFAR-10+32.79best fine-tuning: +22.78

The eight fine-tuning baselines (full, last-layer, LayerNorm-only, LoRA at two ranks, LwF, L2-SP and more) get the same examples, the same checks and the same retention rule, alongside 11 fixed references including Tent, BN adaptation and SAR. The data-efficiency gap is the sharpest result: under the same retention rule, full fine-tuning needs 4,096 labeled corrupted images to match what the program achieves with 64. With condition labels withheld and only the network's own predictions supplied, the program still reaches +34.43. Remove access to weight values while keeping parameter names, shapes and forward code, and the gain falls to +10.78, so the LLM is genuinely reading the weights.

The mechanism claims come with causal evidence. Removing the block-2 gate drops net gain from +31.75 to +10.05, and removing all three gates returns the network to its original accuracy; the gate opens on 99.5% of noisy tokens and 0.5% of clean ones. On reuse, rerunning the same programs on five independently trained ViT-Lites keeps 83–110% of source gains on average, while copying the fixed edits yields −1.42 to +0.01; the same noise program places its gates in different blocks on different networks, which is exactly why rerunning works. For succession, six contrast programs written after the noise program add +5.23 to +14.50 points while the installed noise gain moves by at most 0.23. The counterfactual is instructive: a contrast program written for the original network, rerun on the edited one, frees the units holding the noise gate and loses 26.6 points of noise accuracy.

Why it matters

The few-label, must-not-break-what-works regime is where fine-tuning hurts most, and WeightCode wins there while making every capability a piece of code that can be read, causally probed and rerun. Interpretability comes for free. A session costs US$5–13 and 30–130 minutes; rerunning takes minutes with no LLM call. The long-term pitch is capability libraries: abilities accumulated as inspectable procedures instead of untransferable numbers.

It is a proof of concept on small networks, and the paper says so.

Limitations

Terms

Source

Related papers

All paper explainers