[Paper Review] Compiler-First State Space Duality and Portable $O(1)$ Autoregressive Caching for Inference
The paper presents a kernel-free, compiler-driven Mamba-2 SSD implementation using on-device cached autoregressive state, ported via XLA to CPU, NVIDIA GPUs, and TPU v6e, achieving portable O(1) caching and competitive inference latency without hand-written kernels.
State-space model releases are typically coupled to fused CUDA and Triton kernels, inheriting a hard dependency on NVIDIA hardware. We show that Mamba-2's state space duality algorithm -- diagonal state structure, chunkable recurrence, and einsum-dominated compute with static control flow -- maps cleanly onto what XLA's fusion and tiling passes actually optimise, making custom kernels optional rather than required. We implement the full inference path (prefill, cached autoregressive decoding) as shaped standard primitives under XLA, without hand-written kernels, and realise the architecture's theoretical $O(1)$ state management as a compiled on-device cache requiring no host synchronisation during generation. The implementation runs unmodified on CPU, NVIDIA GPU, and Google Cloud TPU from a single JAX source. On TPU v6e across five model scales (130M--2.7B parameters), XLA-generated code reaches approximately 140 TFLOPS on single-stream prefill ($15%$ MFU) and up to $64%$ bandwidth utilisation on decode. Greedy decoding matches the PyTorch/CUDA reference token-for-token across 64 steps, with hidden-state agreement within float32 rounding tolerance. The pattern transfers to any SSM recurrence satisfying the same structural conditions, on any platform with a mature XLA backend. The implementation is publicly available at https://github.com/CosmoNaught/mamba2-jax and merged into the Bonsai JAX model library.
Motivation & Objective
- Demonstrate that state-space duality properties map well to compiler optimizations in XLA, enabling kernel-free inference across diverse hardware.
- Realize O(1) on-device caching for autoregressive generation using a compiled control flow in JAX/XLA.
- Evaluate portability, performance, and memory across CPU, NVIDIA GPUs, and Google Cloud TPUs with multiple model scales.
Proposed method
- Explain Mamba-2 SSD algorithm and its diagonal state, chunked recurrence, and einsum-dominated compute.
- Implement complete inference path (prefill and cached autoregressive decoding) as standard XLA primitives without hand-written kernels.
- Realize an on-device O(1) cache via compiled control flow registered as a JAX PyTree.
- Evaluate across TPU v6e, NVIDIA A100, and CPU with five model sizes (130M–2.7B) and sequence lengths (128–4096).
- Compare static masking versus dynamic loops to show fusion effects and ablate precision choices (float32 decay exponentiation).

Experimental results
Research questions
- RQ1Can SSD properties be leveraged by compiler backends (XLA) to eliminate the need for custom kernels across platforms?
- RQ2How can an O(1) autoregressive cache be realized on-device for state-space models without host synchronization?
- RQ3What is the portability, performance, and memory footprint of a kernel-free Mamba-2 SSD across CPU, NVIDIA GPUs, and TPUs?
- RQ4What are the numerical correctness guarantees when using compiler-generated SSD code versus reference implementations?
Key findings
- On TPU v6e, the XLA-generated code achieves approximately 140 TFLOPS on single-stream prefill (about 15% MFU) and up to 64% bandwidth utilisation on decode.
- Greedy decoding matches the PyTorch/CUDA reference token-for-token across 64 steps with hidden-state agreement within float32 rounding tolerance.
- Caching provides O(1) per-step complexity for autoregressive decoding, with the on-device cache and compiled fori_loop avoiding host synchronization.
- The same source runs unmodified on CPU, NVIDIA GPU, and Google Cloud TPU, demonstrating strong platform portability.
- Static masking preserves fusion and outperforms a dynamic per-row masking approach in fused kernels, and decay exponentiation requires float32 precision to maintain correctness.
- Across five model scales (130M–2.7B) and sequence lengths up to 4096, decode memory bandwidth utilisation remains around 64% on TPU v6e, and prefill MFU scales with model size, highlighting device ceilings.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.