2026-11-26 15:39 UTC

Municipal Robotics publishes Tang, a compiler for deriving GPU kernels

state: seedheat: mediumuncertainty: mediumrelevance: highgpu-compilers kernel-optimization ai-infrastructureCam PedersenMunicipal Robotics

What is this?

Municipal Robotics, in a research article by Cam Pedersen published November 11, 2026, presents Tang, a Rust-based tensor compiler that aims to derive GPU kernels from a compact intermediate representation of affine tensor views and reduction comprehensions, rather than requiring a hand-written kernel for each operator, chip and shape. The article reports shared compiler infrastructure targeting WGSL, CUDA, Metal, OpenCL, GLSL and C, alongside differentiation, schedule search and a Lean-checked subset of its algebraic rewrites. Its extensive, self-reported evaluation shows promising but workload-dependent results: Tang beats PyTorch’s faster modes on one RTX 3090 transformer-block forward case at sequence length 512, and its derived MoE layer on an H200 ties or beats hand-written kernels at larger batches but loses at small batches. The authors also document major gaps: derived attention trails specialized implementations, the H200 prefill comparison is about 12× behind vLLM, some precision schedules miss tolerances, and the proposed time floor is loose on H200. The supplied evidence is chiefly the authors’ article; the Hacker News item is a link to it, not independent validation. A web result points to Tang’s project site, but supplies no additional performance evidence.

Why it matters

Tang tackles a costly, specialist part of AI infrastructure: turning model computation into fast, hardware-specific GPU kernels. If its approach scales, more model developers could express computation once and rely on the compiler to derive and check implementations across chips, potentially reducing kernel-maintenance work and widening hardware access. The evidence supports an ambitious research prototype with notable results in selected cases, not a general replacement for hand-tuned kernels or established serving stacks; the authors’ own benchmarks show substantial performance and numerical limitations.

Current assessment

New first-party development: Municipal Robotics’ Cam Pedersen published the Tang research article on November 11, 2026; the linked Hacker News post appeared November 12. Tang represents tensor programs using affine views and monoid comprehensions, then applies rewrites, differentiation, scheduling and target-specific lowering. The authors say the same graph can target six backends and describe verification against an f64 interpreter plus Lean proofs for a subset of rewrites; these are properties and results reported in their article, not independently confirmed here. Performance is mixed and shape-dependent. On an idle RTX 3090, the authors report a transformer-block forward pass at sequence length 512 of 0.331 ms versus 0.396 ms for PyTorch captured in a CUDA graph with TF32, but Tang loses at sequence length 128 and ties the forward-plus-backward comparison. In their H200 tests, derived MoE layers are 18% slower than the engine’s hand-written kernels at batch 1, 7% slower at batch 4, tied at 8 and 5% faster at 64; the derived decode step is reported 5–12% faster from 16 to 48 concurrent streams, with accuracy checks and a 48-stream agreement gate missed by both paths under the stated strict threshold. Important caveats: Tang’s attention is slower than specialized FlashAttention baselines in the reported tests; the authors say their derived prefill path remains about 12× slower than vLLM in a comparison with different weight formats, and note that two measurement paths for their own engine are unreconciled. Some precision/error predictions can be substantially inaccurate, a fused CUDA backward misses an f32 tolerance, and the proposed performance floor is loose on H200 and does not yet explain the gap. The results are detailed but come from one company’s article; independent reproduction, broader workloads and evidence of adoption are absent from the supplied sources. Track as a significant compiler/infrastructure research release, not as evidence that general-purpose kernel derivation has already matched production specialists.

Measured heat

now 0 pts/hpeak 0 pts/hcomments 0/hpeers p10momentum: steady2 platformsage 386h
points/hour across evidence · reading as of 2026-11-27 02:23:58.509736+11:00 · deterministic, not a model opinion

How the heat travelled

11-10 13:00⭐ origin echo-reconstructedThe original primary source is Cam Pedersen’s research article, “Don't Write Kernels, Derive Them: Chasing the Speed of Light: Kernels from
Cam Pedersen on blog (echo) · attributed from hn.story.50456374
—
11-11 17:59first on hacker news · published · +29.0hTang, a compiler that derives GPU kernels and bounds how fast they can run
ecto
—
11-11 17:59amplified on hacker news 👑hn.story.50456374
ecto
peak 2 · 0 comments · 103% of case engagement
11-11 18:20our radar first saw it · +29.4hdiscovery anchor: hn.story.50456374—
pace: p26 vs 1845 stories at the 336h mark (now 386h old) — ahead of adap-delegated-authority-protocol-draft (2.0x), behind abmaze-protein-fitness-agent-benchmark (0.7x)

Evidence (2) — ⭐ canonical anchor

sourceobjectauthorscorecomments
🟧 hnTang, a compiler that derives GPU kernels and bounds how fast they can run
Retrieved article excerpt

Open article · Retrieved 2026-11-11T18:21:58.113046+00:00

## Abstract

Every fast model today runs on kernels someone wrote by hand, one per operator, per chip and per fusion. Each one freezes choices about what to fuse, where data lives and how threads share work, and those choices are right for one shape on one device. We think kernels should be derived instead.

tang’s tensor IR is built from two constructs. *Views* are affine maps from an iteration space to tensor coordinates. *Comprehensions* are reductions under a monoid whose body is a scalar expression graph. Everything else is either a rewrite or a schedule. Fusion is one substitution rule. We do not write a flash attention kernel. The compiler derives its schedule by recognizing online softmax as a monoid. Gradients of comprehensions are comprehensions, so the same passes derive and optimize the backward pass. That includes a flash-style attention backward that writes no  intermediates on the three GPU backends we measured (on CUDA through a fused kernel that computes in bf16 and so misses an f32 tolerance, and on WGSL and Metal at a cost we report). The recent superoptimizers we discuss derive only the forward. Precision and thread mapping are schedule fields that cannot change the math (precision changes only rounding, which an emulator budgets with known failure modes), chosen per kernel by measurement on the device.

One graph lowers to WGSL, CUDA tensor cores, Metal simdgroup matrices, OpenCL, GLSL and C, from a datacenter GPU and a desktop GPU and a laptop down to a humanoid robot’s phone-class SoC. On an idle RTX 3090 a derived transformer block’s forward pass at sequence length 512 is 1.2× faster than PyTorch captured in a CUDA graph with TF32; at length 128 PyTorch is 1.2× faster, and forward plus backward ties. Qwen3-8B decodes as a single IR graph at 148.7 tok/s, tied with llama.cpp at short context and at 92% of it at 4k. We wrote no kernel for any one operator. A short list of emitters is keyed on the shape of a graph rather than on an operator: CUDA’s flash kernel (the online-softmax monoid), the fused Hopper attention backward, the narrow GEMV (matrix–vector product) stage, the integer tensor-core stage and the chunked scan plan. Derived attention is not uniformly fast. At  the forward trails FlashAttention-2 at every size we tested, and on the RTX 3090 no tensor-core forward is generated at , which makes it about 150× slower than FlashAttention-2 there. We then derive the kernels of a hand-tuned engine that serves an 80B mixture-of-experts model on one H200. With the work made equal, the derived MoE expert layer is 18% slower than the engine’s hand kernels at batch 1 and 7% slower at batch 4, ties at 8 and is 5% faster at 64. Inside the model, where the derived path runs only from 16 window rows up, a decode step takes 5–12% less time at 16 to 48 concurrent streams over five interleaved rounds on one H200, though the derived path misses the engine’s 48-stream agreement gate, 98.93% against a 99% bar. The derived head-dim-256 attention and gated-delta scan cut the engine’s own time to first token at 44k tokens from 8.33 s to 5.54 s, but vLLM on the FP8 checkpoint reaches first token about 12× faster than the engine, so this is a gain over our own baseline, not over the state of the art. At  the derived attention runs at 0.43–0.54 of FlashAttention-3′s speed forward and 0.22–0.40 backward.

Finally, we ask how far a kernel is from the fastest any implementation could be. For a comprehension over affine views, the least memory traffic and the tile that attains it are the primal and dual of one linear program, and we prove weak duality in Lean for arrays indexed by subsets of the loop coordinates, along with the soundness of the core rewrites. A time floor built on that bound, with launch cost measured on both GPUs and DRAM latency measured on the H200 and assumed on the RTX 3090, never exceeds the measured time on the 24 GEMV-class and epilogue kernels we validated on two GPUs. On the RTX 3090 it reaches 0.76–0.93 of measured time on the large kernels. On the H200 it reaches only 0.05–0.66 (median 0.38), and we have no validated term for the gap. Inside the schedule space, a two-level version of the program picks the tile the M4 Max autotuner picks, but only for register capacities between 4096 and 8192 words, and the traffic-optimal tile does not win on time. In a timed race of every candidate tile on the M4 Max and the RTX 3090, no candidate ran faster than the floor. A per-tile estimate built on it picks a tile within 2.5% of the fastest on seven of eight kernels and loses the eighth by 1.27×.

## 1 Introduction

A modern model has a few dozen distinct operators. A modern framework has thousands of kernels. Every (operator, backend) pair needs one. So does every fusion that pays, such as attention with its softmax, a matmul with its bias and activation, or a norm with the projection after it. FlashAttention [1](https://muni.works/research/tang#loc-46) is the best-known case. Its large speedup came from rewriting one operator by hand so its  score matrix never reaches memory. Its backward pass took a second hand-written kernel. Hopper took a third [2](https://muni.works/research/tang#loc-47), and Blackwell’s FP4 tensor cores are taking a fourth.

Each hand kernel is a separate copy of the same arithmetic, and each one freezes a schedule that was right for one shape on one device. We measured how often that schedule is wrong: the fastest schedule changes with the size, the chip and even between runs on the same machine (§7.1). The winning schedule is a property of the graph, the chip and the size, not of the operator.

Our thesis is that **a kernel is a theorem, not a program**. Every fast kernel we know of is a claim of the form “this comprehension, reassociated under this monoid and placed in this memory, equals the naive one over the reals.” Such a claim can be derived, checked and searched. It does not need to be written. It can also be bounded: the least traffic any box-tiled schedule of a comprehension can move, and the tile that moves it, are dual solutions of one linear program. A theorem fixes what is computed. How fast it runs is still a schedule, and §11 lists the schedules tang does not yet have. If that is right, the kernel library should be replaced by an algebra small enough to reason about, together with a search over its schedules. [Figure 1](https://muni.works/research/tang#fig-one) shows one graph under the schedules that the field knows by name.

Fig 1 One causal attention graph (, , f32) under four schedules, lowered to CUDA on an idle RTX 3090. Only where  and  live, and where kernels end, differ. Checkpointing and flash are points in this space, and the search lands on the flash placement: 18× faster than as written and 40× faster than checkpointing. Every point is checked against the f64 interpreter at this size, with tolerance ; flash and the searched schedule use TF32 tensor cores. “Traffic” is the compiler’s model of DRAM bytes, one pass per buffer, and “rel. error” is the largest error over the largest reference value. Times are medians of 7 samples.

The traffic column is not the time column. Checkpointing moves a third of the naive schedule’s traffic and is 2.2× slower. The score contraction  accounts for more than the whole difference: 7.12 ms against 1.51 ms, with the same arithmetic and the same output. The naive schedule writes  in its own small transpose kernel, so a warp’s 32 lanes then read 32 adjacent floats. Checkpointing folds the transpose into the reader’s view, so each lane reads its own row of . Nsight shows the same 67.6 M L1 requests carrying 5.4 GB in one case and 35.5 GB in the other. The output is exact to , so the lowering is correct but loses coalescing, and a traffic model that counts DRAM bytes once per buffer cannot see it. Flash, which also has the least traffic, wins.

The backward tells a less flattering story. tang’s fused attention backward kernel computes in bf16 tensor cores even when the graph is f32. On this graph its gradients miss the experiment’s tolerance of , measured as max error over max reference against the f64 interpreter (error  in ), so the search rejects it. Without the fused kernel the searched placement passes at  in 1.91 ms, against 0.74 ms for the failing fused version. The search also rejected one placement whose output was simply wrong, at error 7.0; that bug is caught by the check but not yet explained.

We propose writing the model once, as math, and letting the compiler derive every kernel. That works only if the IR is small enough to reason about and expressive enough that nothing important falls outside it. tang is a `no_std` Rust library that started as a geometry and physics math crate. Its `tang-expr` crate traces Rust closures into scalar expression graphs that it can differentiate, simplify and compile, and its tensor IR uses those graphs as its body language. The IR has two constructs.

- **Views**: affine index maps that express broadcast, transpose, slicing, striding, padding and per-head column selection without touching memory.
- **Comprehensions**: , where `body` is a scalar expression graph and  is a monoid.

Contributions:

1. **Kernels from rewrites.** Fusion, flash attention, logsumexp and Welford variance are instances of a small set of rewrites (§2).
2. **Derived backward passes.** Reverse-mode differentiation maps comprehensions to comprehensions, including the online-softmax monoid. A proof procedure removes the stabilizing max’s gradient, and with nested contractions this yields an attention backward with no  tensors (§3).
3. **Precision as a schedule.** An emulating interpreter checks a format choice against an error budget before it runs, with failure modes we report (§4).
4. **One graph, six targets.** Lowerings from shared emitters, measured against hand kernels, PyTorch and the bandwidth limit on four chips (§5, §7).
5. **A production engine, derived.** Top- routing as one monoid, integer tensor-core and narrow GEMV schedules, a segmented-sum gather backward, chunked scans, and Hopper attention schedules. With them, derived kernels replace hand kernels in an 80B MoE engine on an H200, faster in some regimes and slower in others, which we report (§8, §11). A whole derived decode step matches the hand engine on Qwen3-8B and trails it by 13–35% on the 80B MoE.
6. **The speed of light.** The traffic lower bound and the optimal tile are dual solutions of one linear program read off a kernel’s views, with weak duality in Lean. A time floor built on it never exceeds measured time on 24 GEMV-class and epilogue kernels on two GPUs; it is close on the large kernels of the RTX 3090 and loose on the H200 (§9).

## 2 The IR

### 2.1 Views

A view maps a point of an iteration space to a source tensor’s coordinates with one affine form per source dimension, . Broadcast is a zero form, transpose a permutation, slice an offset, stride a coefficient. A form with two terms expresses “head  reads columns “. Views compose by substitution. They are the only way a comprehension reads its inputs, so every layout decision is a view and every view can be analyzed.

A view may be *guarded*, so that an out-of-range read returns the monoid’s identity (zero for sum,  for max) rather than raising a shape error. Padded, dilated and transposed (polyphase) convolutions and overlap-add are guarded reads, with no padding operator. The adjoint of a guarded read is itself a guarded read, not a scatter. For ,  reads  through the same guard, so out-of-range (padding) terms never reach .

Grouped-query attention’s  is not affine. The IR expresses heads as two dimensions, , and the views do the rest. Dimensions can be fixed or symbolic (`Dim::Sym("seq")`). Construction, rewriting and differentiation work with symbols, and `bind` makes them concrete for scheduling and lowering.

A view may also *gather*. One source coordinate is then data, read from an index tensor that is a sibling ar
ecto20
🟧 echo.blog ⭐The original primary source is Cam Pedersen’s research article, “Don't Write Kernels, Derive Them: Chasing the Speed of Light: Kernels from Cam Pedersen——

Interpretation history

Decision trace