WeightCode: Installing New Capabilities into Neural Networks via Weight-Space Programming
Organizations: University of Macau · National University of Singapore · The Chinese University of Hong Kong · Sun Yat-sen University ·
Abstract
Neural networks encode learned capabilities in their weights, yet extending those capabilities with explicit task knowledge remains a fundamental challenge. Here we show that Weight-Space Programming (WSP), in which executable programs read, construct or modify a network's weights directly, can install new capabilities within trained neural networks. WeightCode, a WSP framework, uses a frozen language model to write executable weight programs that install new computations into trained neural networks using task knowledge and their existing weights, without gradient-based training. Once installed, the new capabilities run independently of the language model. Given a grammar or eight demonstrations, weight programs enable previously unseen command compositions (0% to 99.8% exact match) and a new pickup action (0% to 98.4% success), while preserving the original command and navigation capabilities. On ImageNet, four weight programs achieve net gains of 8.84-17.62 points while preserving clean accuracy, outperforming the best of eight fine-tuning methods under matched examples, checks, and retention constraints. In a Vision Transformer, causal interventions show that installed noise-correction gates drive robustness gains, while their selective activation preserves clean accuracy. Rerun on five independently trained Vision Transformers without further language model calls, ten weight programs retain 83-110% of their source-network gains on average, whereas copying their fixed weight edits yields negligible gains. Six programs written for an already edited network add 5.23-14.50 points of contrast robustness while retaining the previously installed noise gain. Together, these results establish WSP as a new route to acquiring and accumulating capabilities in trained neural networks through reusable weight programs.
Figures & tables
Appendix figures & tables21 assets
Supplementary material from the paper’s appendix.
Appendix
| Network and new condition | Task knowledge given to the LLM | Checks and retention rule | References | Selection and test sets |
|---|---|---|---|---|
| ViT-Lite and ResNet-18; Gaussian noise or contrast reduction (CIFAR-10-C, severity 5) | 64 labeled images of the condition (16 the network misclassifies, 48 at random) and 64 labeled clean images, with the network’s predictions; on the ViT-Lite also the lower levels of Sec. A.5 | and on 4,000 check images; | eight fine-tuning methods, 8 configurations each; eleven fixed references (label fits, Tent, BN adaptation, SAR) | 4,000 images per condition; official CIFAR-10 and CIFAR-10-C test files |
| Successive updates: ResNet-20 with Gaussian noise, defocus, snow and contrast in turn; ViT-Lite with Gaussian noise and contrast in either order | per round, 64 labeled images of the new condition and the code of the earlier programs; in one ViT-Lite arm also the list of entries round 1 changed | checks report every condition so far; stream clean change of 4,000, each earlier condition per round | ResNet-20: four fine-tuning streams re-selecting among 8 configurations each round, and fixed reference streams; ViT-Lite: criteria fixed in advance ( Sec. A.9 ) | as above |
| SCAN Transformer; add primitive ( jump ) or around right | the interpretation grammar, 64 old commands with answers and the network’s predictions, and on add primitive the training row of jump | on a third of the official test commands, on 1,000 old commands; | fine-tuning on the given rows; fine-tuning on commands generated from the grammar | a second third and 1,000 old commands; the last third and 1,000 old commands |
| BabyAI policy; pick up | 8 demonstrations of the new mission (observation, instruction and expert action at each step) and 64 old steps, with the policy’s action logits | rollouts of 500 new-mission and 500 old-mission episodes; | the eight fine-tuning methods and behavior cloning of parts of the policy; full behavior cloning from 16 to 256 demonstrations | 1,000 episodes per mission; 1,000 further episodes per mission |
| ResNet-18 on ImageNet (1,000 classes); Gaussian noise (severity 3) or contrast reduction (severity 4) of ImageNet-C | as for CIFAR-10, from held-out validation images | as for CIFAR-10, on 4,000 validation images each | eight fine-tuning methods; eleven fixed references (label fits, Tent, BN adaptation) | 4,000 validation images per condition; the other 38,000 validation images |
| Weight program (WeightCode) | Other route from the same information | |||||||
|---|---|---|---|---|---|---|---|---|
| Setting | Given | new, base | new, after | old | weights | route | new | old |
| SCAN, add primitive | grammar, 64 old commands, the jump row | 0.0% | 99.8% | 0.0 | 257 | grammar-generated fine-tuning | 99.6% | 0.0 |
| SCAN, around right | grammar, 64 old commands | 17.6% | 89.6% | 0.3 | 25,056 | grammar-generated fine-tuning | 100.0% | 0.1 |
| BabyAI, pick up | 8 demonstrations, 64 old steps | 0.0% | 98.4% | +0.4 | 21,482 | behavior cloning, embeddings and head | 1.1% | 0.6 |
| Weight program (WeightCode) | Fine-tuning, best of 8 | Fixed refs. | Weights | |||||
| Network | Condition | gain | clean | net gain | kept | no bound | kept | changed |
| ImageNet, 1,000 classes, corruptions of ImageNet-C at severity 3 (noise) and 4 (contrast) | ||||||||
| ResNet-18 | Gaussian noise | +10.72 | 0.25 | +10.47 | +8.67 | – | +8.84 | 2,152,928 |
| ResNet-18 | contrast reduction | +9.31 | 0.47 | +8.84 | +3.38 | – | +6.00 | 33,176 |
| CIFAR-10, corruptions of CIFAR-10-C at severity 5 | ||||||||
| ViT-Lite | Gaussian noise | +32.68 | +0.11 | +32.79 | +22.78 | +29.11 ( 1.98) | +16.48 | 3,846 |
| Gaussian noise | Contrast reduction | |||||||
| gain | clean | net gain | gain | clean | net gain | |||
| Weight program (WeightCode) | +32.68 | +0.11 | +32.79 | +17.45 | 0.94 | +16.51 | ||
| Fine-tuning, kept by the same rule | best of 8 methods | +23.41 | 0.63 | +22.78 | +8.23 | 0.34 | +7.89 | |
| best tuned recipe | +21.76 | 0.42 | +21.34 | +7.90 | 0.32 | +7.58 | ||
| with an estimated corruption model | unchanged network | +10.83 | 0.83 | +10.00 | ||||
| with the true corruption model | unchanged network | +11.00 | 0.77 | +10.23 | ||||
| Weight program (WeightCode) | Fine-tuning, best of 8 | Fixed refs. | Weights | |||||
| Network | Condition | gain | clean | net gain | kept | no bound | kept | changed |
| ImageNet, 1,000 classes, corruptions of ImageNet-C at severity 3 (noise) and 4 (contrast) | ||||||||
| ResNet-18 | Gaussian noise | +10.23 | 0.10 | +10.13 | +8.70 | – | +8.00 | 2,152,928 |
| ResNet-18 | contrast reduction | +9.68 | 1.13 | +8.55 | +3.40 | – | +5.33 | 33,176 |
| CIFAR-10, corruptions of CIFAR-10-C at severity 5 | ||||||||
| ViT-Lite | Gaussian noise | +31.62 | +0.12 | +31.75 | +22.90 | +30.50 ( 1.43) | +16.08 | 3,846 |
| Gaussian noise | Contrast reduction | |||||||
| gain | clean | net gain | gain | clean | net gain | |||
| Weight program (WeightCode) | +31.62 | +0.12 | +31.75 | +17.93 | +0.05 | +17.98 | ||
| Fine-tuning, kept by the same rule | best of 8 methods | +23.52 | 0.62 | +22.90 | +8.65 | +0.00 | +8.65 | |
| best tuned recipe | +22.32 | 0.43 | +21.90 | +8.62 | +0.07 | +8.70 | ||
| with an estimated corruption model | unchanged network | +11.58 | 0.18 | +11.40 | ||||
| with the true corruption model | unchanged network | +11.85 | 0.15 | +11.70 | ||||
| On its own network | Rerun on the five other networks | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Condition | Network | Session | gain | clean | net | FT kept | criterion | checks | US$ | share | clean | copied |
| Gaussian | seed 100 | 1 | +32.68 | +0.11 | +32.79 | +22.78 | met | 6 | 9.92 | 0.87 | 5 of 5 | 0.10 † |
| seed 100 | 2 | +12.73 | 0.53 | +12.20 | +22.78 | missed | 8 | 8.36 | 0.98 | 5 of 5 | +0.01 † | |
| seed 100 | 3 | +30.80 | +0.03 | +30.83 | +22.78 | met | 8 | 8.75 | 0.91 | 5 of 5 | 0.16 † | |
| seed 101 | +30.85 | 0.27 | +30.58 | +16.31 | met | 5 | 7.81 | 0.85 | 5 of 5 | 0.34 † | ||
| seed 102 | +18.35 | 0.38 | +17.97 | +10.32 | missed | 6 | 8.74 | 0.98 | 5 of 5 | 0.45 † | ||
| Test set | Selection | ImageNetV2 | |||
| gain | clean | net gain | net gain | clean | |
| Gaussian noise, severity 3; criterion: gain 7.0, net gain +9.84 | |||||
| Program, session 1 | +10.72 | 0.25 | +10.47 | +10.13 | 0.37 |
| Program, session 2 | +18.02 | 0.40 | +17.62 | +16.38 | 0.45 |
| Fine-tuning, kept | +9.45 | 0.78 | +8.67 | +8.70 | 0.77 |
| Best fixed reference | +9.44 | 0.60 | +8.84 | +8.00 | – |
| Network, condition, information | What the program writes | Weights |
|---|---|---|
| ViT-Lite, Gaussian noise, labeled * | frees two little-used MLP units in each of blocks 2, 4 and 6 and rewrites them as ramp gates that subtract the measured noise offset from tokens above the clean range | 3,846 |
| ViT-Lite, Gaussian noise, condition labels withheld | estimates the noise strength from the images’ excess neighbor-difference energy and chains saturating gates in the least-used MLP units of blocks 2 to 4 and the last block, each triggered by a flag the previous gate writes | 19,724 |
| ViT-Lite, Gaussian noise, name only | gives the 16 block-0 MLP units most driven by noise twin units that cancel the mean the noise induces through the GELU | 24,848 |
| ViT-Lite, contrast reduction, labeled * | raises the zero-mean part of the patch-embedding filters by a factor of 1.45 and adds a gated rank-6 correction in eight freed units of block 2 | 16,648 |
| ResNet-18 (CIFAR-10), Gaussian noise, labeled | estimates the noise level from the images’ high-frequency energy, applies a Wiener shrinkage to each convolution in forward order and shifts the following BatchNorm means to keep clean pre-activations; no gate | 1,718,057 |
| ResNet-18 (CIFAR-10), contrast reduction, labeled | raises the zero-mean part of the stem convolution by 35% and adds gates on a whitened low-contrast direction in two late residual blocks | 37,192 |
| Gaussian | contrast | |
| Weight program (WeightCode) | +31.75 | +17.98 |
| Ablations of the written program | ||
| block-2 gate removed | +10.05 | – |
| gates held open (clean 5.03) | +19.43 | – |
| two random units of the block (mean of 5) | +31.86 | – |
| Alternatives with the same examples, checks and rule | ||
| reused | mean gain | share | clean | |
|---|---|---|---|---|
| Gaussian | program | +28.57 | 0.87 | 0.19 to +0.07 |
| FT recipe | +20.79 | 0.89 | 0.85 to 0.31 | |
| FT re-selected | +10.44 | 0.45 | ||
| Contrast | program | +16.04 | 0.92 | 1.10 to 0.47 |
| FT recipe | +8.09 | 0.98 | 0.55 to 0.15 | |
| FT re-selected | +6.57 | 0.80 |
| reused | mean gain | share | clean | |
|---|---|---|---|---|
| Gaussian | program | +28.14 | 0.89 | 0.07 to 0.00 |
| FT recipe | +20.71 | 0.88 | 0.95 to 0.50 | |
| FT re-selected | +10.33 | 0.44 | ||
| Contrast | program | +17.14 | 0.96 | 1.20 to 0.65 |
| FT recipe | +8.91 | 1.03 | 0.47 to +0.18 | |
| FT re-selected | +7.19 | 0.83 |
| Order | Edit log | added | earlier | clean | met |
|---|---|---|---|---|---|
| Gaussian first | none (first) | +9.12 | 0.17 | 0.25 | missed |
| none | +12.42 | 0.02 | 0.02 | met | |
| none | +14.50 | +0.01 | 0.21 | met | |
| log | +5.23 | 0.09 | +0.15 | missed | |
| log | +12.80 | +0.23 | 1.47 | met | |
| log | +13.42 | 0.01 | 0.80 | met |
| Stream score after round | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| Gauss. | defocus | snow | contrast | |
| Programs, one per round | 2.34 | 8.22 | 8.64 | 8.95 |
| Best fine-tuning stream | 1.48 | 3.63 | 4.56 | 5.15 |
| Stream score after round | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| Gauss. | defocus | snow | contrast | |
| Programs, one per round | 2.31 | 8.06 | 8.90 | 8.97 |
| Best fine-tuning stream | 1.18 | 3.54 | 4.35 | 4.97 |