CODA: Rewriting Transformer Blocks as GEMM-Epilogue Programs
TL;DR Highlight
CODA fuses norm and activation ops into GEMM epilogues so they run on-chip.
Who Should Read
An ML infrastructure developer whose Transformer training is memory-bound and who is exploring kernel optimization or LLM-generated kernels.
Core Mechanics
- Memory-bound ops eat training time
- Normalization, activations, residual updates, and reductions do little arithmetic.
- They keep moving large intermediate tensors through global memory, which makes them a bottleneck.
- Process outputs while the GEMM tile is on chip
- CODA expresses these ops as GEMM plus epilogue (post-processing right after the matmul) programs.
- Ops that were separate framework kernels run before the tile is written to memory.
- Fixed GEMM, composable epilogues
- The mainloop is fixed, and you compose epilogue primitives for scaling, reductions, pairwise transforms, and accumulation.
- The goal is to preserve the performance structure of expert-written GEMMs.
- Covers nearly all non-attention compute
- It can express most non-attention computation in the forward and backward pass of a standard Transformer block.
- Human- and LLM-written kernels both perform well
- Across representative Transformer workloads, both human-authored and LLM-authored CODA kernels achieve high performance.
Community Reactions
- Opinion: not a new performance ceiling
- One view was that Triton can already do this, and epilogue fusion itself is not new.
- The real takeaway was a design shift for LLM-driven codegen.
- Opinion: restricted APIs suit LLMs
- A commenter said LLMs are weak at low-level optimization but good at high-level composition.
- They expected restricted, composable APIs to become the norm in agentic development.
- Explanation of the RMSNorm scale trick
- A commenter explained that a row-wise scale can be moved after the next projection with the same result.
- They said compilers like torch.compile cannot assume a global row-wise reduction between GEMMs commutes, so this was not done before.
- Opinion: execution feedback closes the gap
- One view was that synthesis alone is hard, but run, profile, and patch loops close the gap fast.
How to Apply
- Find memory-bound ops in your training profile
- Run the PyTorch profiler on a training step today and check the time share of norm, activation, and residual kernels.
- Mark large ones as candidates for fusion right after a GEMM.
- Give LLM kernel prompts a fixed primitive list
- When asking an LLM for kernels, give an allowed operation list instead of free-form writing.
- Limit it to compositions of scaling, reduction, pairwise, and accumulation.
- Add a run-and-profile loop to generated kernels
- Automatically run correctness tests and performance measurements on generated kernels.
- Feed the results back to the LLM to fix them.
Try It
# Paste into Claude or ChatGPT (simplified version of the paper's method: design a kernel with restricted primitives)
I want to fuse the following Transformer block ops using a GEMM+epilogue approach.
Target ops: {{list of ops such as RMSNorm, activation, residual}}
Rules:
1. Do not change the GEMM mainloop.
2. Compose post-processing only from four primitives: scaling, reduction, pairwise transform, accumulation.
3. First check whether the ops can be algebraically reordered so they run before the GEMM output tile is written to memory.
4. State the conditions under which reordering is valid. Example: the scale has only row-wise interactions.
5. Write the final result as a sequence of primitive calls.Terminology
Related Papers
A Beginner's Guide to Local AI with Inkling, Qwen, and Unsloth
Install Unsloth Desktop, load a quantized Qwen model, and share a private ChatGPT-like AI on your home LAN.
Muru – AI-assisted Rust server for Python apps by mod_WSGI's creator
mod_wsgi's creator is building Muru, an AI-assisted Rust ASGI/WSGI server, documenting it in public
87% of the Anthropic power will come from gas and 11% from coal in 2028
Analysis of Anthropic's contracted data centers: 87% gas, 11% coal power in 2028
Anthropic’s Nasdaq debut
Anthropic listed on Nasdaq and closed its first day below its opening price.
OpenAI still has a WebRTC Problem
WebRTC drops late audio, hurting voice AI; MoQ retransmits and buffers instead
Gemini 4 Neon
Gemini 4 Neon cuts cost per task 32% versus Carbon, at $3 input and $15 output per million tokens
AI is killing All About Berlin
After Google AI Overviews, a Berlin guide site lost 70-75% of its traffic.
Not Everything Needs an LLM
PostHog used small decision models to skip 98.7% of expensive LLM calls