Stateful Transformers 实现流式推理 5.9 倍加速
Attention Once Is All You Need: Efficient Streaming Inference with Stateful Transformers
流式推理场景(如实时数据监控、金融交易、对话系统)的开发者终于有了降低延迟的可行方案——把预填充移出关键路径,查询延迟与上下文大小解耦。做高吞吐低延迟推理服务的团队值得关注这个新范式。
传统 Transformer 推理引擎在流式工作负载中,每次查询都需要 O(n) 的预填充成本,随着上下文增长成本急剧上升。
本文提出基于状态会话的数据驱动计算模型,通过持久化 KV 缓存增量更新,将预填充移出关键路径,使查询延迟降至 O(|q|),与累积上下文大小无关。Flash Queries 机制利用数据到达间的空闲 GPU 周期预评估注册问题并缓存答案,这在无状态引擎中无法实现。
多租户连续批处理调度器支持数十个状态会话在单 GPU 上共存,同时保持完整二次自注意力。在流式市场数据基准测试中,参考实现相比 vLLM、SGLang、TensorRT-LLM、llama.
cpp 等传统引擎实现最高 5.9 倍加速,且查询延迟不随上下文增长而增加。
Attention Once Is All You Need: Efficient Streaming Inference with Stateful Transformers
Conventional transformer inference engines are request-driven, paying an O(n) prefill cost on every query. In streaming workloads, where data arrives continuously and queries probe an ever-growing context, this cost is prohibitive. We introduce a data-driven computational model centred on stateful sessions: a persistent KV cache advanced incrementally as new data arrives, so prefill is moved off the critical path and query latency becomes O(|q|), independent of accumulated context size. Building on this, Flash Queries reclaim idle GPU cycles between data arrivals to pre-evaluate registered questions and return cached answers before the user asks, a pattern that is structurally impossible in stateless engines because they discard intermediate state between requests. A multi-tenant continuous-batching scheduler with cell-budget admission and prefix-aware grouped prefill lets dozens of stateful sessions coexist on a single GPU while preserving full quadratic self-attention. On streaming market-data benchmarks the reference implementation achieves up to 5.9x speedup over conventional inference engines (vLLM, SGLang, TensorRT-LLM, llama.cpp), holding query latency constant as accumulated context grows.
This report is categorized under AITOP's "Papers" desk. Key entities and technical topics under continuous tracking include inference optimization, streaming inference, KV cache, Flash Queries.
Source attribution: curated from arXiv cs.LG (@Victor Norgren).