Stock jax.lax.approx_max_k beats hand-written Pallas top-k kernels by ~11x on TPU v5e

petrusenko_max · x · 2026-11-23

The author released tpu-retrieval-bench, an open-source benchmark for exact top-k embedding retrieval on TPU comparing XLA, blockwise, and hand-written Pallas kernels (plus a float64 NumPy oracle). The counterintuitive result: stock jax.lax.approxmaxk beat his hand-written Pallas top-k kernels by 11x on a TPU v5e, and his exact fused kernel only beat XLA at batch 1024.

Benchmarks throughput and p99 tail latency across 8 variants (numpyref, jittopk, blockwisetopk, pallasfusedbucket, pallasfusedtopk, pallasscoretopk, scoreonly, selectonly) at N=1M, D=128, k=10, bf16. The core question: when does a hand-written Pallas kernel beat stock XLA, and when is XLA already fast enough? Includes spec, methodology docs, fuzz tests, and results, Apache-2.0 licensed.

Original post →

More from Infra

Infra channel →