Pallas: custom kernels in JAX

Pallas: custom kernels in JAX#

Most of the time, you don’t write kernels: you write jax.numpy programs, and the compiler decides how to turn them into device code. Usually it does well. But sometimes you know something the compiler doesn’t: a fusion it won’t find, a memory-access pattern it won’t discover (as in FlashAttention), or a sparsity structure it can’t exploit. Then the way to get the remaining performance is to write the kernel yourself.

Pallas is JAX’s kernel language: an extension of JAX that lets you write custom kernels for GPU and TPU, with fine-grained control over the generated code while keeping JAX tracing and the jax.numpy API. Kernels are written as functions over Refs in fast on-chip memory, launched over a grid with pl.kernel, and they compose with the rest of JAX: you can jit, vmap, and differentiate around them.

Pallas has its own extensive documentation site, which we won’t duplicate here:

pallas.jax.dev

Good entry points:

Pallas is experimental and changes frequently; see the Pallas changelog for recent developments.