⚙ SGLang Diffusion Is Retiring torch.compile, With Help From an AI Agent
After testing 35 diffusion model presets on H100 and H200 GPUs, SGLang Diffusion found that eager execution now usually matches or outperforms torch.compile.
Zhihu contributor BBuf argues that this is more than a benchmark result. Agent-written optimizations and Breakable CUDA Graphs can now replace the two main benefits that torch.compile once provided.
1️⃣ The “seven sins” are three production failures
torch.compile can fuse kernels and reduce Python overhead. But in production diffusion serving, BBuf found that its operational cost often outweighed those gains.
🔹 Slow and unpredictable
Compilation may take several minutes, and complex models can take more than half an hour. Performance also changes unpredictably across compiler modes, models, and GPU generations.
An optimization that works on one GPU may become a regression on another.
🔹 Hostile to manual optimization
A custom fused kernel may accelerate eager execution but slow down the compiled model. Graph breaks or broader compiler fusion can erase the improvement.
Developers then have to debug both their kernels and the compiler’s changing graph decisions.
🔹 Opaque and difficult to maintain
Compiled traces are hard to map back to Python calls. Generated kernels are also difficult to inspect, benchmark independently, or modify.
Over time, engineers are pulled into compiler-specific fusion rules and workarounds instead of optimizing the actual model.
2️⃣ The current benchmark changed the calculation
In SGLang Diffusion’s latest H100 and H200 tests, torch.compile was usually slower than eager execution or roughly tied with it.
Compile jobs taking longer than three minutes were stopped. Several models also encountered timeouts or runtime failures.
Some models had previously benefited from compilation. But after explicit kernel optimization, most of those gaps disappeared.
For models dominated by launch overhead, eager execution plus Breakable CUDA Graphs could match or beat the compiled path.
3️⃣ An Agent replaced the hidden optimizations
The team did not build an elaborate multi-agent system.
They used Fable with a simple optimization flow and two Kernel Design Agent skills. The Agent profiled the VAE and model components, identified bottlenecks, implemented explicit optimizations, and repeatedly checked correctness and performance.
Within two weeks, this workflow optimized more than 30 diffusion models. Their eager paths reached or surpassed the performance previously provided by torch.compile.
The crucial difference is ownership: these optimizations now exist as visible, testable, and maintainable code.
4️⃣ Breakable CUDA Graph replaced the other benefit
Kernel fusion is only one reason to use torch.compile. The other is reducing framework overhead through graph execution.
SGLang previously relied on compiler-assisted Piecewise CUDA Graphs. After dealing with substantial compiler complexity, it developed Breakable CUDA Graph, which captures reusable execution paths while allowing controlled graph breaks.
SGLang Diffusion now uses the same approach. It is easier to integrate into real serving systems and can outperform the compiled path on overhead-heavy models.
5️⃣ The deeper shift is from compiler magic to Agent-owned code
A general compiler applies hidden transformations at runtime. An Agent can instead inspect the workload, reproduce useful transformations as source code, and validate them on the target hardware.
This makes performance work easier to profile, review, debug, and adapt.
BBuf’s claim is specifically about diffusion serving, not every PyTorch workload. But within that scope, the conclusion is blunt:
If Agents can reproduce the useful kernel optimizations, while CUDA Graph techniques remove framework overhead, torch.compile no longer has a unique role.
🔗 Full Reading:
🔗 Performance results:
🔗 Kernel Design Agents:
🔗 SGLang:
🔗 Agent optimization skills:
#
SGLang# #
PyTorch# #
CUDA# #
AIInfra# #
DiffusionModels# #
AIAgents#