AI-generated CUDA kernels push past PyTorch in GPU tests
Terminator GPU By What The Future Newsroom · June 2, 2025 · 4 min read

AI-generated CUDA kernels push past PyTorch in GPU tests

A Stanford team showed that large language models can generate CUDA-C kernels that outperform PyTorch in several GPU-heavy machine learning benchmarks. The gains were strongest in operations like layer normalization, Conv2D, softmax, and composite image-processing steps, but FP16 matrix multiplication and Flash Attention remained difficult.

A Stanford team has shown that large language models can produce CUDA-C kernels that beat PyTorch in several GPU-heavy machine learning benchmarks. The result points to a practical role for AI in low-level performance work: not replacing machine learning frameworks outright, but generating specialized code where speed matters.

“AI-generated low-level GPU code improving ML performance mildly points toward more powerful AI systems, without clear danger or social degradation.”Why it scores Terminator

The work focused on compact programs that run directly on Nvidia GPUs. These kernels handle core operations such as matrix multiplications and image processing, which makes them central to many AI workloads.

Why CUDA kernels matter for AI performance

PyTorch, developed in part by Meta, is one of the standard tools for machine learning. It gives developers ready-made GPU operations, so teams can build and run AI systems without writing every low-level routine themselves.

That convenience matters. But the Stanford experiments show that, in some cases, a general-purpose framework routine can be beaten by a narrower, task-specific CUDA-C kernel generated by a language model.

The source article describes several areas where AI-generated kernels ran faster than PyTorch's built-in code. One kernel improved layer normalization by a factor of 4.8. Layer normalization is a step that standardizes neural network values, so speeding it up can matter inside larger model pipelines.

Other gains appeared in image convolution, also called Conv2D, the softmax function, and a composite operation that combines convolution, ReLU activation, and max-pooling. In plain terms, these are not decorative pieces of an AI system. They are the kinds of operations that appear repeatedly in machine learning workloads.

How KernelBench turned optimization into a search problem

The research used a benchmark called KernelBench. In that setting, a language model tries to replace selected PyTorch operators with its own CUDA kernels, and the replacement code is judged on two requirements: it must be correct, and it must run faster.

The team worked with OpenAI o3 and Gemini 2.5 Pro. Both models used parallel optimization strategies across multiple rounds. Instead of changing one kernel step by step in a narrow sequence, the approach broadened the search.

The process had two important features:

  • Optimization ideas were described in everyday language.
  • Multiple code versions were generated from each idea at the same time.
  • The variants were run in parallel, and only the fastest versions continued into the next round.

That branching process gave the system more chances to discover a strong implementation. The best kernels used familiar GPU optimization techniques, including more efficient memory access, overlapping arithmetic with memory operations, reducing data precision such as moving from FP32 to FP16, improving use of GPU compute units, and simplifying loop structures.

The important point is not that the models invented performance engineering from nothing. The source shows something more concrete: language models were able to search through possible implementations and arrive at CUDA programming techniques that are normally associated with developers who have years of GPU optimization experience.

Conv2D shows how the code improved over iterations

One example in the source article tracks an AI-generated Conv2D kernel over 13 iterations. It began at 20 percent of PyTorch's speed and improved to nearly 180 percent of PyTorch's speed.

Conv2D is a fundamental image-processing operation. It combines input images with filter matrices, making it a useful test case for GPU-heavy machine learning code.

The stronger Conv2D version did not come from a single simple tweak. The improvements included converting the convolution into a matrix multiplication that used the GPU's specialized tensor cores. The kernel also used double buffering, which helps overlap computation and memory access, and it precomputed memory indices in shared memory so data could be retrieved faster.

This is where the research becomes especially interesting for machine learning infrastructure. The generated kernels were not merely shorter alternatives to PyTorch calls. In the strongest examples, the search process assembled sophisticated CUDA choices into working code and then kept the versions that performed best.

Where AI-generated kernels still fall short

The results were not uniformly better than PyTorch. The Stanford team found that AI-generated kernels struggled with newer AI tasks that rely on lower-precision data types such as FP16.

In one test, an FP16 matrix multiplication kernel reached only 52 percent of PyTorch's speed. Flash Attention was a bigger challenge. For that memory-intensive technique used in large language models, the generated kernel ran at just 9 percent of PyTorch's pace.

Those weak results matter because they show the limits of the approach. A language model can search for fast code, but some operations are still difficult to match against the highly tuned routines already present in established frameworks.

At the same time, the researchers emphasize that the method is meant to work alongside existing training methods rather than replace them. The search process creates synthetic data, and that data can then help train future models. In that sense, the output has two uses: faster runtime code when the generated kernel succeeds, and training material that can improve later systems.

What this suggests for AI-assisted systems work

The broader implication is that parallel search with strong language models can produce useful system components. The source article connects the Stanford findings with other work, including DeepMind's AlphaEvolve and the Deep Think feature of Gemini 2.5 Pro.

For developers, the near-term lesson is practical. AI-generated CUDA kernels may be most useful where the target operation is well defined, correctness can be tested, and many candidate implementations can be benchmarked quickly.

PyTorch remains a central framework for machine learning, and the source does not suggest that generated kernels replace it. Instead, the research points to a complementary path: use PyTorch as the stable baseline, then let language models search for faster specialized kernels in places where performance is worth the extra validation.

That makes the Stanford work less about a single benchmark win and more about a workflow. If models can propose many CUDA variants, run them, measure them, and refine the winners, GPU optimization becomes a broader search process. The strongest results show real speedups; the weaker FP16 and Flash Attention cases show why careful testing remains essential.

AIGPUPyTorchCUDAMachine Learning
← Back to the wire

Read next