Together AIExplainer
Last year we built megakernels. This year we deleted them: The road to Together Compiler
Summary
Together Compiler uses AI agents to rewrite and fuse GPU kernels in a model’s forward pass, achieving 2,118 tokens per second on Llama 3.2 1B on B200, 28% faster than hand-written megakernels. The team previously built megakernels that executed an entire forward pass in a single fused kernel but found them difficult to productionize, supporting only one model and batch size. They discovered that combining CUDA Graphs and PDL on top of default Torch Inductor kernels recovered 98% of megakernel performance without writing custom kernels. Further multi-kernel and agent-loop techniques beat the old megakernels by up to 1.7x on H100, achieving over 1,100 TPS for Llama 1B. The post details investigations into Torch Compile’s limitations, including 607 tuning flags and unpredictable interactions, motivating the development of Together Compiler’s agent-driven optimization.
Context
The increasing heterogeneity of AI inference workloads, with new model architectures, varying batch sizes and sequence lengths, and diverse hardware, creates a need for optimization frameworks that can adapt. Hand-written megakernels achieved high performance but were difficult to productionize, supporting only one model and batch size.
Approach / What changed
Together Compiler uses AI agents to rewrite and fuse the GPU kernels in a model’s forward pass, performing continual compilation for AI inference. It combines CUDA Graphs, PDL, and multi-kernel agent loops to optimize performance across varying workloads.
Takeaways
Torch Compile’s heuristics and 607 tuning flags can lead to unpredictable performance; a freezing flag improved throughput 10-26% at large batch sizes but caused a 49% slowdown at batch size 1.
Combining CUDA Graphs and PDL on top of default Torch Inductor kernels recovered 98% of megakernel performance without writing custom kernels.
Together Compiler’s agent-driven approach beat hand-written megakernels by 28% on B200, achieving 2,118 vs 1,649 tokens/s on Llama 3.2 1B.
FAQ
Why were megakernels difficult to productionize?
After months of effort, the megakernels supported only one model, one batch size, and one customer, making them impractical for the heterogeneous inference workloads the team needed to serve.
How does Together Compiler achieve better performance than megakernels?
Together Compiler uses AI agents to dynamically rewrite and fuse GPU kernels. With multi-kernel and agent-loop techniques, it beat old megakernels by up to 1.7x on H100 and achieved 2,118 tokens/s on Llama 3.2 1B on B200, a 28% improvement over hand-written megakernels.
What limitations of Torch Compile motivated Together Compiler?
Torch Compile's heuristics and 607 tuning flags lead to unpredictable performance. For example, a freezing flag improved throughput 10-26% at large batch sizes but caused a 49% slowdown at batch size 1. Its greedy fusion algorithm also leaves performance on the table.
Source and freshness
- Source
- together.ai
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.