为TPU设计高效灵活的注意力计算内核,提升大模型推理性能。
Ragged Paged Attention: A High-Performance and Flexible LLM Inference Kernel for TPU

- 采用细粒度分块与自定义流水线,支持动态不规则序列处理。
- 解码阶段内存带宽利用率最高达86%,预填充阶段模型浮点利用率73%。
- 适配生产环境,适用于追求低成本高效率的LLM部署团队。
大型语言模型(LLM)部署正转向成本更低的加速器如谷歌的张量处理单元(TPU),在性能和总体拥有成本(TCO)之间寻求平衡。然而,现有LLM推理内核与服务系统仍以GPU为中心,缺乏针对TPU架构高效映射的方法,尤其在现代服务中常见的动态、不规则执行模式下。本文提出一种名为Ragged Paged Attention(RPA)的高性能、灵活的TPU注意力内核,基于Pallas和Mosaic实现。RPA通过三项关键技术解决该问题:(1) 细粒度分块,实现对不规则内存的高效动态切片;(2) 自定义软件流水线,将键值缓存更新与注意力计算融合;(3) 分布式感知编译策略,为解码、预填充及混合工作负载生成专用内核。在TPU7x上对Llama 3 8B进行评估,RPA在解码阶段达到最高86%的内存带宽利用率(MBU),在预填充阶段实现73%的模型浮点运算利用率(MFU)。RPA已集成至vLLM和SGLang,成为生产级TPU推理的骨干,并为内核设计提供了实用指导。
原文摘要 · Abstract (English)
Large Language Model (LLM) deployment is increasingly shifting to cost-efficient accelerators like Google's Tensor Processing Units (TPUs), prioritizing both performance and total cost of ownership (TCO). However, existing LLM inference kernels and serving systems remain largely GPU-centric, and there is no well-established approach for efficiently mapping LLM workloads onto TPU architectures--particularly under the dynamic and ragged execution patterns common in modern serving. In this paper, we present Ragged Paged Attention (RPA), a high-performance and flexible attention kernel for TPUs, implemented using Pallas and Mosaic. RPA addresses these challenges through three key techniques: (1) fine-grained tiling to enable efficient dynamic slicing over ragged memory, (2) a custom software pipeline that fuses KV cache updates with attention computation, and (3) a distribution-aware compilation strategy that generates specialized kernels for decode, prefill, and mixed workloads. Evaluated on Llama 3 8B on TPU7x, RPA achieves up to 86% memory bandwidth utilization (MBU) in decode and 73% model FLOPs utilization (MFU) in prefill. Integrated as the primary TPU backend in vLLM and SGLang, RPA provides a production-grade foundation for efficient TPU inference and offers practical insights into kernel design.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。