Skip to main content
QUICK REVIEW

[论文解读] Compiler-First State Space Duality and Portable $O(1)$ Autoregressive Caching for Inference

Cosmo Santoni|arXiv (Cornell University)|Mar 10, 2026
Parallel Computing and Optimization TechniquesComputer Science被引用 0
一句话总结

该论文提出一种基于内核-free、编译器驱动的 Mamba-2 SSD 实现,利用设备端缓存自回归状态,通过 XLA 移植到 CPU、NVIDIA GPU 及 TPU v6e,在不使用手写内核的情况下实现可移植的 O(1) 缓存和具有竞争力的推理延迟。

ABSTRACT

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.

研究动机与目标

  • 证明状态空间对偶性属性在 XLA 的编译优化中能够很好映射,从而在多平台实现无内核推理。
  • 利用 JAX/XLA 的编译控制流实现自回归生成的设备端 O(1) 缓存。
  • 在 CPU、NVIDIA GPU 和 Google Cloud TPU(多模型规模)上评估可移植性、性能和内存占用。

提出的方法

  • 解释 Mamba-2 SSD 算法及其对角线状态、分块递归以及 einsum 主导的计算。
  • 将完整推理路径(预填充和缓存自回归解码)实现为标准 XLA 基元,而不使用手写内核。
  • 通过编译后的控制流注册为 JAX PyTree,在设备端实现 O(1) 缓存。
  • 在 TPU v6e、NVIDIA A100 和 CPU 上测试五种模型规模(130M–2.7B)和序列长度(128–4096)。
  • 比较静态掩码与动态循环以展示融合效果并消融精度选择(float32 指数衰减)。
Figure 1: Autoregressive generation on Cloud TPU v6e across five model scales and six sequence lengths. (a) Speedup from caching. (b) Generation latency: cached (solid) grows linearly, non-cached (dashed) grows quadratically. (c) Per-step throughput: cached throughput is flat regardless of sequence
Figure 1: Autoregressive generation on Cloud TPU v6e across five model scales and six sequence lengths. (a) Speedup from caching. (b) Generation latency: cached (solid) grows linearly, non-cached (dashed) grows quadratically. (c) Per-step throughput: cached throughput is flat regardless of sequence

实验结果

研究问题

  • RQ1编译后端(XLA)是否能够利用 SSD 属性在各个平台上消除对自定义内核的需求?
  • RQ2如何在不进行主机端同步的情况下,在设备端为状态空间模型实现 O(1) 自回归缓存?
  • RQ3无内核的 Mamba-2 SSD 在 CPU、NVIDIA GPU 以及 Google Cloud TPU 上的可移植性、性能和内存占用如何?
  • RQ4使用编译器生成的 SSD 代码与参考实现相比的数值正确性保证有哪些?

主要发现

  • 在 TPU v6e 上,XLA 生成的代码在单流预填充阶段实现了大约 140 TFLOPS(约 15% MFU),解码阶段带宽利用率高达 64%。
  • 贪婪解码在 64 步下与 PyTorch/CUDA 参考逐字逐词匹配,隐藏状态在 float32 舍入容差内一致。
  • 缓存为自回归解码提供 O(1) 的每步复杂度,设备端缓存和 fori_loop 编译避免了主机端同步。
  • 相同源码在 CPU、NVIDIA GPU 和 Google Cloud TPU 上未修改地运行,展示了强大的平台可移植性。
  • 静态掩码保持融合效果并优于在融合内核中使用的动态逐行掩码方法,且衰减指数需要 float32 精度以维持正确性。
  • 在五种模型规模(130M–2.7B)和最长序列长度 4096 的场景下,解码内存带宽在 TPU v6e 上保持约 64% 的利用率,预填充 MFU 随模型规模增长,凸显设备上限。
Figure 2: Peak memory during autoregressive generation on Cloud TPU v6e. Cached decoding (solid) is constant; non-cached (dashed) grows linearly. At sequence length 4096, the 2.7B non-cached path consumes over 16 GB versus a constant 10.9 GB cached.
Figure 2: Peak memory during autoregressive generation on Cloud TPU v6e. Cached decoding (solid) is constant; non-cached (dashed) grows linearly. At sequence length 4096, the 2.7B non-cached path consumes over 16 GB versus a constant 10.9 GB cached.

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。