Experiment · 11 min read
Claude got only the weight file. It made the model 3x faster.
23 Nov 2026 · Gayanuka Amarasuriya
Keywords: Weight-Space Programming, Claude Code, Agents, Inference, Quantization.
Abstract: Can an LLM agent read a network's raw weights and rewrite it to run faster on a laptop CPU, with no training and no hints? Five runs, one OCR transformer, four lessons.
Contents10 sections
In early November, MIT CSAIL showed that a frontier LLM can read a neural network's weights and edit them directly, with no gradient training. They called it weight-space programming. In the three weeks since, more than 30 follow-up papers have used it to repair models, steer robots, edit physics models and plant backdoors.
Almost all of them ask the agent to make a model better. I wanted to know if it can make a model faster.
TL;DR: I gave Claude Opus 5.5 the 156 weight tensors of a small OCR transformer, with no source code and no hints, and asked for the fastest model that keeps its accuracy. It worked out the architecture from the tensor names and shapes, matched the original outputs to within 4e-5, and then rewrote the model. All five finished runs kept test accuracy within 0.1 points of the original. All five beat standard INT8 plus TorchScript (2.24x). The best run reached 3.72x. The headline is less useful than how the agent got there:
The setup
The target is docTR's vitstr_small, a text recognizer. It reads one word image of 32 x 128 pixels and returns up to 33 characters. It has 21.4M parameters in 12 transformer blocks, and it scores 83.26% exact-match accuracy on my 5,000 held-out test crops.
The agent is Claude Opus 5.5, run headless through Claude Code (claude -p, maximum effort). Its only tool sends a Python block to a Docker container with no network, 4 CPU threads and 6 GB of memory. Each run gets 80 code blocks, 5 minutes per block and 3 hours in total.
| Item | What the agent got |
|---|---|
| Weights | the 156 tensors, as a dict of numpy arrays |
| Data | 1,280 unlabeled training images and the original model's outputs on them |
| Not given | labels, test images, hints on what to change |
| Allowed | any change without training: values, shapes, layers, architecture, numeric format, forward code |
| Not allowed | backpropagation, optimizers, iterative fitting of weights to outputs |
| Pass rule | test accuracy within 1.0 point of the original |
I ran two setups. In weights only, the agent gets the tensors, the model's name and its input and output shapes, and no code. In live model, it also gets the running PyTorch model and its source code, so it can probe and dissect it.
The prompt states the goal and the rules, and nothing about how to reach the goal:
GOAL
- Make the model as fast as possible on CPU and keep its accuracy.
- Speed is the median time of one forward pass on one image (batch size 1).
- You have no labels. Agreement with the outputs of the original model
on the images X is your only estimate of accuracy.
- You may change anything: weight values, tensor shapes, the number and the
type of layers, the architecture, the numeric format, the forward code.
- You decide what to examine and what to change.The agent submits a model.py and a weights file. A separate scorer runs the submission on the 5,000 test crops and times it at batch size 1 on my laptop CPU (Intel Core i9-13900H, 4 threads). It interleaves all models over several rounds, so they all see the same thermal and power state.
Results
The two weights-only runs reached 3.72x and 2.71x. The three live-model runs reached 2.54x, 3.08x and 2.83x. The best standard tooling I could put together, dynamic INT8 on the oneDNN backend plus a frozen TorchScript graph, reached 2.24x. No run lost a significant amount of accuracy (McNemar p of 0.38 or more for every run). Each run took about an hour and used 8 of usage, as reported by Claude Code.
Now switch Figure 1 between the padding subsets. The ranking changes, and that change is the first lesson.
Lesson 1: Look at the input, not only the weights
docTR resizes each word crop to fit 32 x 128 pixels and keeps its aspect ratio. Short words leave empty space on the right, which is filled with black. After normalisation, every padded pixel holds the same exact value. On a median test image, 6 of the 16 patch columns are pure padding. The transformer still spends full compute on every one of those tokens.
Nobody told the agent this. Three of the five runs found it from the 1,280 unlabeled images. They merged each fully empty column into a single token and added to its attention score, where is the number of tokens it replaces. If the merged tokens were identical, this would give exactly the same attention output. Here they differ only in their position embeddings, so the result is close but not exact. This is proportional attention, as in token merging. They also noticed that text cannot continue past the last non-empty column, so they emit end-of-sequence for those output positions and do not compute them.
On images that are half or more padding, the weights-only run 1 is 5.93x faster than the original. The standard baseline gets 2.19x on the same images. On images with no padding, the trick gives nothing.
What to take away: if your pipeline pads inputs with a constant, those tokens may cost you a third of your compute. This is a property of the data, not of the weights. It disappears if the preprocessing changes.
Lesson 2: The network had almost nothing to cut
Every run first tried what you would expect a weight-reading agent to try: remove blocks, remove attention heads, prune MLP units, replace matrices with low-rank versions. Every one of these cuts failed.
My own baselines agree. Dropping the last block takes test accuracy from 83.26% to 2.14%. A rank-192 SVD of every MLP matrix is 1.22x faster but loses 1.28 points, so it fails the pass rule.
The one free cut was MLP units that never activate. Live runs 2 and 3 both found 400 to 500 dead units in each of the first two blocks. They removed them and refit the next layer's weights with closed-form least squares on the probe activations. This is the only step in any run that came from reading the weights in the classic sense, and it is small.
Lesson 3: The numeric format was the real lever
The agents profiled the model before they changed it. Two runs reported that 65% to 87% of the time went into float32 matrix multiplies that already ran near the CPU's peak. So the lever was the number format, not the architecture.
The detail that mattered most: this CPU has AVX-VNNI instructions for INT8 dot products. PyTorch's oneDNN backend uses them. According to the agent's own measurements, the default fbgemm backend is about 1.5x slower on this chip, and at 8 bits it can saturate an int16 accumulator. My baselines show the same gap: plain dynamic INT8 gives 1.31x with fbgemm and 1.57x with oneDNN. Live run 1 picked fbgemm, and it is the slowest model on images with no padding (2.05x). Live runs 2 and 3 picked oneDNN and then went further:
- SmoothQuant scales in closed form (all runs). For each input channel , , computed from the probe activations and folded into the preceding LayerNorm weights. No fitting loop is involved.
- Static INT8 activations (live run 2), calibrated once on the probe images, instead of a new scale for every image.
- Fused layers (live run 2). The first MLP layer and its GELU write INT8 directly into the second layer, and the residual adds are fused into the matrix multiplies.
- Exact folding (all runs). LayerNorm affine weights and the attention scale go into the next linear layer, and Q, K and V become one matrix multiply.
Live runs 2 and 3 never used the padding trick. On images with no padding, they run at 3.31x and 3.25x, against 2.40x for the baseline. That gain does not depend on this dataset at all.
Lesson 4: Skip what the output never reads
The output head of vitstr_small reads tokens 1 to 33 and ignores the other 96. In the last block, those 96 tokens still matter as keys and values for attention, but nothing reads their own outputs.
All five runs found this and cut the last block down to the 33 read-out tokens. It saves about 5% of the encoder's compute. It is exact and costs nothing, and none of the standard tools in my baselines does it.
What did not work
- More access did not help. Weights only averaged 3.22x over two runs. Live model averaged 2.82x over three. With this few runs, I cannot call that a difference.
- Timing is noisy. Speedups vary 20% to 30% between rounds. The same weights-only run 1 measured 3.13x in one session and 3.72x in another, two days apart. Compare numbers only within one session.
None of these steps needs an LLM in principle. A good performance engineer could do every one of them. What is new is that the agent found them unprompted, in about an hour, starting from a bare weight file.
Full results
Editor runs and the best baseline, timed in one session on 23 November 2026:
| Model | Test accuracy | Drop, points (95% CI) | Speedup | No padding | Half or more padded | Weights |
|---|---|---|---|---|---|---|
| Original | 83.26% | 0 | 1.00x | 1.00x | 1.00x | 85.7 MB |
| INT8 (oneDNN) + TorchScript | 83.12% | 0.14 (-0.08 to 0.38) | 2.24x | 2.40x | 2.19x | 85.7 MB |
| Weights only, run 1 | 83.30% | -0.04 (-0.20 to 0.12) | 3.72x | 2.70x | 5.93x | 85.8 MB |
| Weights only, run 2 | 83.16% | 0.10 (-0.08 to 0.28) | 2.71x | 2.21x | 4.74x | 30.5 MB |
| Live model, run 1 | 83.28% | -0.02 (-0.16 to 0.12) | 2.54x | 2.05x | 4.16x | 27.1 MB |
| Live model, run 2 | 83.22% | 0.04 (-0.06 to 0.14) | 3.08x | 3.31x | 3.28x | 21.5 MB |
| Live model, run 3 | 83.24% | 0.02 (-0.10 to 0.14) | 2.83x | 3.25x | 3.11x | 82.6 MB |
All baselines, timed in one session on 21 November 2026 (so their speedups are not directly comparable with the table above):
| Baseline | Test accuracy | Speedup | Passes |
|---|---|---|---|
| TorchScript only | 83.26% | 1.06x | yes |
| PyTorch SDPA attention | 83.26% | 1.00x | yes |
| Dynamic INT8, fbgemm | 83.02% | 1.31x | yes |
| Dynamic INT8, x86 | 83.02% | 1.38x | yes |
| Dynamic INT8, oneDNN | 83.12% | 1.57x | yes |
| Dynamic INT8, oneDNN + TorchScript | 83.12% | 2.12x | yes |
| SVD of MLP matrices, rank 256 | 82.80% | 1.04x | yes |
| SVD of MLP matrices, rank 192 | 81.98% | 1.22x | no |
| Drop the last block | 2.14% | 1.08x | no |
| Drop the last two blocks | 2.00% | 1.19x | no |
Related work
The method comes from Sparks of Weight-Space Programming by Takehi, Teoh, Zhang and Khattab at MIT CSAIL.
Citation
@misc{amarasuriya2026wspspeed,
title = {Claude Got Only the Weight File. It Made the Model 3x Faster.},
author = {Amarasuriya, Gayanuka},
year = {2026},
month = nov,
howpublished = {\url{https://gayanukaa.com/blog/2026-11-23-weight-space-programming-for-speed}},
note = {Blog post}
}