Experiment · 11 min read

Claude got only the weight file. It made the model 3x faster.

23 Nov 2026 · Gayanuka Amarasuriya

0 views

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
  1. The setup
  2. Results
  3. Lesson 1: Look at the input, not only the weights
  4. Lesson 2: The network had almost nothing to cut
  5. Lesson 3: The numeric format was the real lever
  6. Lesson 4: Skip what the output never reads
  7. What did not work
  8. Full results
  9. Related work
  10. Citation

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.

ItemWhat the agent got
Weightsthe 156 tensors, as a dict of numpy arrays
Data1,280 unlabeled training images and the original model's outputs on them
Not givenlabels, test images, hints on what to change
Allowedany change without training: values, shapes, layers, architecture, numeric format, forward code
Not allowedbackpropagation, optimizers, iterative fitting of weights to outputs
Pass ruletest 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

Speedup over the original model, batch size 1, 4 CPU threads
Agent, weights onlyAgent, live modelStandard toolingOriginal
Original
1.00x
INT8 + TorchScript
2.24x
Weights only, run 1
3.72x
Weights only, run 2
2.71x
Live model, run 1
2.54x
Live model, run 2
3.08x
Live model, run 3
2.83x
0x1x2x3x4x5x6x7x
Figure 1: Median speedup per image against the original vitstr_small, timed in one session with all models interleaved over 5 rounds (3 rounds for the two padding subsets). Thin lines show the lowest and highest round. Every model stays within 0.15 points of the original test accuracy on 5,000 held-out crops. Current subset: 200 test images, mixed padding.

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 7to7 to 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 log⁡(n)\log(n) to its attention score, where nn 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.

One token per empty column
0empty patch columns per image16
Tokens per image
129 to 87
Linear layers (scale with tokens)
67%
Test images with 6+ empty columns
57%
Figure 2: Top: number of fully padded patch columns in each of the 5,000 test images (median 6 of 16). Click a bar or drag the slider. Bottom: the 8 x 16 patch grid of one image. Each empty column becomes one token whose attention score gets a +log(8) bias, so it carries the weight of the 8 tokens it replaces. Cost ratios are first-order estimates from the token count, not timings.

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.

The network had almost nothing to cut
Remove any one block (4% or more)
4%
Remove one attention head
0.4 to 8%
Remove half of one MLP
0.2 to 3.3%
Freeze non-output tokens in block 10
2.7%
Remove 1/8 of MLP in blocks 2 to 11
2.5%
Drop 10% of background tokens
1.6%
0%2%4%6%8%
Figure 4: Numbers reported by the agent in live run 2, measured as agreement lost against the original model on the 1,280 unlabeled probe images. Ranges show the spread over the blocks or heads it tried. The only free cut was MLP units that never activate, all in the first four blocks.

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 jj, sj=max⁡∣Xj∣α/max⁡∣Wj∣1−αs_j = \max|X_j|^{\alpha} / \max|W_j|^{1-\alpha}, 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.

The last block only has to finish 33 of 129 tokens
Full computationKeys and values only
token 0 (class)token 33token 128
Last block, GFLOP
0.48
Of the original last block
100%
Saved, whole encoder
0%
Figure 3: The output head reads tokens 1 to 33. In the last block, the other 96 tokens still supply keys and values, but their queries, attention output and MLP are never used. GFLOP counts are computed from the layer shapes. The change is exact and saves about 5% of the encoder's compute.

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:

ModelTest accuracyDrop, points (95% CI)SpeedupNo paddingHalf or more paddedWeights
Original83.26%01.00x1.00x1.00x85.7 MB
INT8 (oneDNN) + TorchScript83.12%0.14 (-0.08 to 0.38)2.24x2.40x2.19x85.7 MB
Weights only, run 183.30%-0.04 (-0.20 to 0.12)3.72x2.70x5.93x85.8 MB
Weights only, run 283.16%0.10 (-0.08 to 0.28)2.71x2.21x4.74x30.5 MB
Live model, run 183.28%-0.02 (-0.16 to 0.12)2.54x2.05x4.16x27.1 MB
Live model, run 283.22%0.04 (-0.06 to 0.14)3.08x3.31x3.28x21.5 MB
Live model, run 383.24%0.02 (-0.10 to 0.14)2.83x3.25x3.11x82.6 MB

All baselines, timed in one session on 21 November 2026 (so their speedups are not directly comparable with the table above):

BaselineTest accuracySpeedupPasses
TorchScript only83.26%1.06xyes
PyTorch SDPA attention83.26%1.00xyes
Dynamic INT8, fbgemm83.02%1.31xyes
Dynamic INT8, x8683.02%1.38xyes
Dynamic INT8, oneDNN83.12%1.57xyes
Dynamic INT8, oneDNN + TorchScript83.12%2.12xyes
SVD of MLP matrices, rank 25682.80%1.04xyes
SVD of MLP matrices, rank 19281.98%1.22xno
Drop the last block2.14%1.08xno
Drop the last two blocks2.00%1.19xno

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}
}
Published 23 Nov 2026
0 views