2026-03-11 · 专家 · 机器学习

Compiler-First State Space Duality and Portable O(1) Autoregressive Caching for Inference

这篇论文提出了一种基于编译器优化的状态空间模型(SSM)推理方法,通过使用XLA编译器实现了O(1)状态的缓存和可移植的自动回归缓存,从而提高了推理效率。

更新于 2026-03-11。作者:Cosmo Santoni。

中文摘要

状态空间模型发布通常与融合的CUDA和Triton内核相关联,继承了对于NVIDIA硬件的硬依赖。我们展示了Mamba-2的状态空间对偶算法——对角状态结构、可分递归以及以einsum主导的静态控制流计算——可以干净利落地映射到XLA的融合和分块传递实际上优化的内容,使得自定义内核成为可选而非必需。我们在XLA下实现了完整的推理路径(预填充、缓存的自动回归解码)作为形状标准原语,而不需要手写内核,并将架构的理论O(1)状态管理作为编译在设备上的缓存,在生成过程中无需主机同步。该实现无需修改即可在CPU、NVIDIA GPU和Google Cloud TPU上运行,从单一的JAX源代码。在TPU v6e上,针对五个模型规模(130M--2.7B参数),XLA生成的代码在单流预填充(15% MFU)上达到约140 TFLOPS,在解码时达到高达64%的带宽利用率。贪婪解码在64步内与PyTorch/CUDA参考的token-for-token匹配,隐藏状态在float32舍入公差范围内一致。这种模式可以转移到任何满足相同结构条件的SSM递归,在任何具有成熟的XLA后端平台上。该实现已在https://github.com/CosmoNaught/mamba2-jax公开,并已合并到Bonsai JAX模型库中。

英文摘要

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.

解读

一句话总结

这篇论文提出了一种基于编译器优化的状态空间模型(SSM)推理方法,通过使用XLA编译器实现了O(1)状态的缓存和可移植的自动回归缓存,从而提高了推理效率。

问题1:这篇论文想要解决什么具体问题?

问题2:论文的核心创新点是什么?

问题3:实验结果如何验证了方法的有效性?

问题4:这个研究的实际应用价值是什么?

来源

机器可读索引:llms.txt