Research note
We tried a published agent-optimization method on a laptop: 3.66 times faster on one task, 1.19 on the other
We ran NVIDIA's published agent-optimization method with Claude Code on a laptop. An attention kernel got 3.66x faster in 3 tries; LLM decoding 1.19x.
The method here is not ours. Agentic Variation Operators, published by researchers at NVIDIA in 2026, uses a coding agent as an optimizer: give it a benchmark and a correctness check, and let it try new versions of a piece of code until the number improves. We built a small version of it and ran it with Claude Code on a laptop, to see what it takes to make it work outside a research lab. On one task it made a GPU attention kernel 3.66 times faster in three attempts. On the other it made a small language model generate text 1.19 times faster over 17 attempts, and along the way it found a likely reason the larger gain we expected was not available on that model.
This follows our study of 312,000 pull requests, which looked at how coding agents change day-to-day engineering work. This post is narrower: two tasks, one machine, one day. It shows how much the result depends on the checks around the agent.
The short version
- With a fixed benchmark and a strict correctness gate, the agent turned a slow attention routine into a fused GPU kernel that ran 3.66 times faster than the original at the worst of three test sizes, and up to 7.74 times faster at the largest.
- On a text-generation task, it reached 1.19 times faster. The gain came from keeping the GPU busy; the planned technique never passed.
- The planned technique, speculative decoding, failed the correctness gate six times. The agent's own probe suggests why: on this model's design, checking several tokens at once does not leave the model in the same state as checking them one at a time.
- If you try this, build the benchmark and the correctness check first. They decided every outcome here.
How the loop works
The setup is simple. There is one file the agent may change, a benchmark it may read but not edit, and a correctness check that runs on inputs the benchmark never times. Each round, the agent proposes a change, runs it, and the loop scores the result. The change is kept only if it is still correct and at least as fast as the best version so far, with a 2% allowance for measurement noise. Otherwise it is thrown away. Every attempt is recorded so later rounds can see past failures.
A separate supervisor joins in when progress stalls and suggests new directions.
All of that design comes from the Agentic Variation Operators paper. The paper also chose the first kind of target we used, an attention kernel. What is ours: a small reimplementation that works with an off-the-shelf coding agent, a different machine and software stack, the second task, and the lessons from running it.
How we tested it
Both tasks ran on one Apple M4 Pro machine using MLX, Apple's machine learning framework. Each round was a fresh Claude Code run capped at about $3.
Speed was measured as a ratio against a frozen copy of the original code, timed side by side in the same process. That choice mattered. The original attention code measured 14.5 GB/s on an idle machine and 7.1 GB/s under load, so raw speed would have accepted or rejected changes based on what else the machine was doing. Timing against a reference cut the run-to-run swing from 8.3% to 0.2%. Each task's score was the minimum across three test configurations, so a version that won on one and lost on another did not count.
Task 1: an attention kernel. Attention is the part of a language model that looks back over everything generated so far. This version adds a "soft cap" step that the fast built-in routine cannot handle, so the starting code used slow, separate operations that wrote every intermediate result to memory. Correctness was checked against a high-precision reference on odd shapes the benchmark never times.
Task 2: faster text generation. The target was Qwen3.5-2B, with Qwen3.5-0.8B available as a helper. Output had to match the original token for token. Speculative decoding was the obvious lever: a small, fast model guesses the next few tokens and the big model checks all the guesses in one pass, keeping the ones it agrees with. The standard library refuses to do this on Qwen3.5, because 18 of its 24 layers keep a running summary instead of a per-token record, and a running summary cannot simply be cut back when a guess is wrong.
Results
The clear win. The agent tried three versions. The first two failed the correctness check, with errors around 0.13 against a tolerance of about 0.02. The third passed. It was a single fused GPU kernel that reads the cached data once, keeps intermediate values on the chip, shares each piece of cached data across the four query heads that use it, and splits long inputs across many parallel workers. Its own note says it also fixed a bug in how the kernel's threads were launched. Scores: 3.66x at 4,000 tokens of context, 6.47x at 16,000 and 7.74x at 32,000. At 32,000 tokens it moved 171 GB/s, about 70% of the machine's measured memory ceiling of 244 GB/s. The run used about $9 of agent time.
The modest result. Over 17 attempts the loop kept 9, rejected 7 and discarded 1 that changed nothing. Of the 9 kept, only 4 were real improvements; the other 5 were within the 2% noise allowance. Six of the 7 rejections failed correctness, five of them in exactly the same place: token 59 of one test prompt. Every kept version ignored the helper model. The final 1.19x came from removing a wait. The original code paused for the GPU after every token; the kept versions queue up the next step while the GPU is still working on the current one. The final version generated about 172 tokens per second.
The discovery. Near the end, the agent wrote a small test: run five tokens through the model at once, then the same five one at a time, and compare. The internal state of the running-summary layers differed, by as much as 0.75 in one part, and even the model's top choice for the first token changed. Speculative decoding depends on that one-pass check giving the same answer as going token by token. On this model, as run here, it did not, which would explain the failure at token 59: small differences built up over rounds until a choice flipped.
What the agent got wrong
Three times, the supervisor blamed the failure on a bug in restoring saved state. The first time it called that "almost certainly" the cause; the last time it said the headroom was large. The agent kept trying variations of the same fix. Each of those attempts cost about $3 and roughly 25 minutes. It found the likely cause only after it built a small reproduction. Six of the nine kept versions had no description, so later rounds could not easily tell what had been tried. The text-generation run spent about $50, its full budget.
What this does not show
Our speedups cannot be compared with the paper's. The paper started from libraries that were already heavily tuned, on data-centre GPUs, and reports gains of up to 3.5% and 10.5% over them after seven days of unattended search. We started from a slow routine on a laptop, where there was far more room to improve. A 3.66 times gain over a slow starting point is a much easier result than a few percent over the best existing code.
This is two tasks on one machine, each run once. We did not rerun either search, so we do not know how often the agent would find the 3.66x kernel again, or how quickly. The attention run's records end after three attempts and do not say why it stopped.
The finding about batched checking is the agent's own probe, written at the end of the run. We have not confirmed whether it is a property of this model's design or of the library's code for processing several tokens at once. A different implementation might make speculative decoding work.
Cost figures come from the agent runs themselves and can undercount runs that timed out.
When this approach is not worth it
It worked where the benchmark was stable, the correctness check was strict and ran on unseen inputs, and the gap to the hardware's limit was large. Without a trustworthy check, the loop will happily keep a fast wrong answer. If your measurement swings more than the gains you hope for, the loop will keep noise. And when the main idea is blocked by something the agent has to discover, expect to pay for many failed attempts before anyone learns why.
What this has to do with measuring work
The loop only worked because someone had defined, in advance, what "better" meant and how to check that the work was still correct. That is the same problem every team has when it hands work to an agent, and it is the problem Lighty AI works on.
Chamlis, our dashboard for how engineering teams adopt AI agents, reads the checks around a repository: tests and required checks, review, and guardrails. Our study of 312,000 pull requests found that agents raise output per developer and that review becomes the constraint. This experiment shows the same thing at small scale. The agent supplied the attempts. The benchmark and the correctness gate decided which ones counted.
Questions
Can a coding agent optimize code by itself?
In our test, Claude Code made a GPU attention kernel 3.66 times faster in three attempts when given a fixed benchmark and a strict correctness check. On a harder text-generation task it reached 1.19 times faster over 17 attempts.
Why did speculative decoding not speed up Qwen3.5?
Qwen3.5 keeps a running summary in 18 of its 24 layers, which cannot simply be rolled back. The agent also found that feeding five tokens at once gave a different internal state than feeding them one at a time, so checking guesses in one pass could not guarantee identical output; all six speculative attempts failed correctness.
How much does it cost to let a coding agent optimize a kernel?
In our runs each attempt was capped at about $3. The attention kernel run cost about $9 for three attempts, and the text-generation run used its full budget of about $50 over 17 attempts.
What do you need before using an AI agent to optimize performance?
A benchmark that does not swing with machine load and a correctness check on inputs the benchmark never times. Timing against a frozen copy of the original cut our run-to-run swing from 8.3% to 0.2%.
Two optimization searches run once each on 2026-08-22 on one Apple M4 Pro machine, with Claude Code proposing changes and an automated gate keeping only correct versions at least as fast as the best so far (2% noise allowance); speed is the ratio to a frozen copy of the original, timed side by side, taking the minimum across three configurations.
More from the blog
- AI coding agents raise output per developer by about 26%. Time to merge hides it.
- Screen capture samples a few desks for a few weeks, and the costliest workflow problems we found needed every record
- AI reasoning models still apply familiar rules where they do not fit, though some famous failures shrink when the test is audited