ForgeStencil: AI That Optimizes Industrial Software
On August 4, 2026, a Chinese AI lab called ModelBest — you might know them as 面壁智能, the team behind the MiniCPM series of small language models — open-sourced something completely different from their usual LLM releases. It’s called ForgeStencil, and it’s an AI system that automatically optimizes Stencil computations in real industrial and scientific software.
I’ll explain what Stencil computations are in a moment, but the headline numbers first: ForgeStencil was tested on over 100 real applications spanning oil and gas simulation, electromagnetics, medical imaging, computational fluid dynamics, climate modeling, astrophysics, materials science, and HPC benchmarks. It delivered a median end-to-end speedup of 1.41x and a geometric mean speedup of 2.05x. Zero human intervention. From optimization idea to deployed patch, automatically.
If you work in high-performance computing, you know how significant those numbers are. A 1.41x speedup on production HPC code, achieved without a human expert spending weeks hand-tuning CUDA kernels, is the kind of result that makes computational scientists sit up.
What Stencil computations are and why they matter
Stencil computations are a pattern where each element in a grid is updated based on values from its neighboring elements. Think of a weather simulation: to compute what happens at a specific point in the atmosphere, you need to know what’s happening at the surrounding points. You apply a “stencil” — a fixed pattern of neighboring cells — to every point in the grid, repeatedly, across thousands of timesteps.
This pattern shows up everywhere in scientific computing. Heat diffusion, wave propagation, fluid dynamics, image processing, convolutional neural networks — they all rely on Stencil computations. A huge fraction of the world’s supercomputing cycles are spent running Stencil loops.
Optimizing Stencil code is hard. You need to understand memory access patterns, cache hierarchies, vectorization, and GPU thread organization. The optimal implementation depends on the specific Stencil shape, the grid dimensions, the hardware, and even the compiler version. A human expert might spend weeks optimizing a single Stencil kernel for a specific problem, and the result might not transfer to a slightly different Stencil on slightly different hardware.
This is exactly the kind of problem where AI agents should help. The search space is large but well-defined. The objective is clear — minimize execution time. The feedback loop — compile, run, measure — is fast and deterministic. And the potential impact is enormous: every HPC center in the world runs Stencil computations daily.
How ForgeStencil works: two agents, one loop
ForgeStencil uses two cooperating LLM agents that together form a closed optimization loop. The architecture is clean and worth understanding even if you never touch Stencil code.
The Kernel Agent handles the low-level optimization. Its job: given a Stencil pattern and a target hardware platform, research optimization strategies, generate CUDA or C++ implementations, compile them, and profile the results. It operates in a Plan → Code → Profile loop. If the generated kernel is slower than the baseline, it analyzes the profiling data, adjusts the strategy, and tries again. If it’s faster, it passes the kernel to the App Agent.
The App Agent handles integration. Its job: locate the Stencil hotspot in the target application’s source code — which could be hundreds of thousands of lines across multiple files — replace the original implementation with the optimized kernel, verify correctness by running the application’s test suite, and if everything passes, produce a patch. It operates in a Hotspot → Forge → Verify → Integrate loop.
What makes this work is that the two agents have different skills and different context windows. The Kernel Agent needs to understand GPU architecture and optimization techniques. The App Agent needs to understand large codebases, build systems, and testing infrastructure. Splitting them means each agent can be specialized without the context window problems you’d get from trying to cram both responsibilities into one prompt.
The whole system is Apache 2.0 licensed, with both agents’ orchestration code and prompts published in the GitHub repo. You can inspect exactly how the Kernel Agent decides which optimization to try next, or how the App Agent locates Stencil hotspots in unfamiliar codebases.
Results that actually matter
The 1.41x median speedup is impressive, but I want to dig into why these numbers are more credible than most AI-for-code benchmarks.
ForgeStencil was tested on real applications — not synthetic benchmarks, not toy examples. The 100+ validated applications include production codes used in oil reservoir simulation, electromagnetic field solvers, medical image reconstruction, climate models, and astrophysics simulations. These are codes that have already been optimized by human experts, sometimes over decades. Finding additional speedup in code that domain experts have already tuned is genuinely hard.
The geometric mean of 2.05x suggests the distribution has a long tail of cases where ForgeStencil found dramatic improvements. A geometric mean that’s significantly higher than the median usually means a few applications got very large speedups while most got moderate ones. That pattern — some big wins, many small wins — is what you’d expect from an automated optimizer exploring a space that humans have already roughly covered.
The fact that this required zero human intervention is both the headline and the caveat. It’s impressive that an AI system can find and deploy optimizations autonomously. It also means nobody was checking whether the “optimized” results were actually correct beyond the application’s existing test suite. For scientific computing, where a subtle numerical bug can invalidate months of simulation results, this matters. ForgeStencil’s verification is only as good as the tests the application already has.
The technical choices that make it work
There are a few design decisions in ForgeStencil that I think are worth calling out because they’re applicable beyond Stencil optimization.
First, the iterative profiling loop. The Kernel Agent doesn’t try to predict which optimization will work — it tries, measures, and adapts. This is the right approach for compiler optimization in general. Static prediction of performance on modern hardware is extremely difficult because cache behavior, branch prediction, and instruction scheduling interact in ways that even experienced engineers can’t reliably forecast. Run it, time it, learn from the result. The LLM’s role is strategy generation, not performance modeling.
Second, the separation of concerns between Kernel and App agents. This is a pattern I expect to see more of in AI-for-code systems. One agent focuses on a narrow, deep problem (GPU kernel optimization). Another focuses on a broad, shallow problem (understanding and modifying a large codebase). Neither agent needs to be good at the other’s job, and the interface between them — an optimized kernel file — is well-defined.
Third, the use of the application’s own test suite for verification. This is pragmatic. Building a formal verification system for arbitrary scientific software is essentially impossible. Running the existing tests and checking that they still pass is the best available proxy for correctness. It’s not perfect — tests can pass while producing subtly wrong numerical results — but it’s the standard that human developers use when optimizing HPC code.
Limitations and where it falls short
ForgeStencil works on Stencil computations. That’s a specific, well-defined category of code pattern. It won’t help you optimize graph algorithms, sparse linear algebra, or irregular memory access patterns. The two-agent architecture is designed around the Stencil optimization workflow, and generalizing it to other optimization domains would require significant rework.
The verification approach — relying on existing test suites — means ForgeStencil is only as trustworthy as the tests the application ships with. Many scientific codes have incomplete test coverage, especially for numerical edge cases. If your simulation produces slightly different results after ForgeStencil’s optimization, you might not catch it unless you have tests that check for that specific numerical tolerance.
The system also requires a build environment that the agents can interact with programmatically. If your HPC code requires a specific module system, a queue-based job scheduler, or proprietary compilers, getting ForgeStencil to work might involve significant setup. The published results were on applications that already had clean, automated build and test pipelines — that’s not universal in scientific computing.
And while “zero human intervention” is the pitch, the reality is that deploying an optimized kernel into a production scientific workflow still requires human judgment. Is a 1.2x speedup worth the risk of introducing a subtle bug into a simulation that runs for six months? That’s not a question an AI agent can answer, and ForgeStencil doesn’t try to.
What this means for AI-assisted software optimization
ForgeStencil isn’t the first attempt at using AI for compiler optimization. ML-guided optimization has been a research topic for years, and tools like LLVM’s ML-based inliner have been in production for a while. What’s different here is the level of autonomy and the scope of impact.
Traditional ML-guided optimization works at the compiler flag level — should we inline this function? Should we unroll this loop? — and produces small, incremental improvements. ForgeStencil operates at the algorithm level, generating entirely new implementations of computational kernels. The gap between “tweak a compiler flag” and “write a new CUDA kernel from scratch” is enormous, and ForgeStencil crosses it.
The fact that this came from ModelBest rather than a traditional HPC vendor is also worth noting. The MiniCPM team has been focused on making small models practical, and ForgeStencil feels like a natural extension of that philosophy. Instead of building a massive model that understands all of software engineering, they built two specialized agents that understand Stencil optimization deeply and general software engineering shallowly. That’s a more practical approach than trying to make one model good at everything.
Should you use it?
If you work on HPC applications that spend significant time in Stencil computations — and if you don’t know whether your application does, profile it first — ForgeStencil is worth trying. The setup cost is low for applications with clean build systems. The potential upside — a 1.4x median speedup on code that domain experts have already optimized — is unusual for any automated tool.
If your HPC code has good test coverage, the verification risk is manageable. Run the test suite before and after optimization. Compare outputs numerically, not just pass/fail. If everything checks out, you’ve gotten free performance with very little effort.
If your application is safety-critical or produces results that inform high-stakes decisions — medical treatment planning, structural engineering, climate policy — I’d wait. The technology is too new, the failure modes aren’t well-characterized, and the consequences of a subtle numerical bug in these domains are severe. Let the research community validate ForgeStencil on a wider range of applications before trusting it with anything that affects human lives.
For everyone else in the middle — academic research groups, industrial R&D teams, anyone running simulations where a wrong result is embarrassing but not catastrophic — ForgeStencil is one of the more practical AI-for-code tools I’ve seen this year. The dual-agent architecture, the measurement-driven optimization loop, and the Apache 2.0 license all point in the right direction. It’s the kind of AI application that makes life better for computational scientists without pretending to replace them.