98倍更快的LLM路由无需专用GPU:Flash注意力、提示压缩与近流式处理用于vLLM语义路由
98$\times$ Faster LLM Routing Without a Dedicated GPU: Flash Attention, Prompt Compression, and Near-Streaming for the vLLM Semantic Router
AI总结:
本文提出三种优化方法,解决LLM路由的延迟和内存问题,实现98倍速度提升,使路由在共享GPU上成为可能。
摘要:
系统级路由器必须在安全分类、领域路由和PII检测中快速且操作轻量:应为每个请求添加最小延迟,同时不需要专用GPU——一种昂贵的资源更适合用于LLM推理本身。当路由器与vLLM服务实例在同一GPU上时,标准注意力的O(n²)内存使得长上下文分类(8K-32K tokens)不可能:在8K tokens时,三个并发分类器需要约4.5GB的注意力掩码内存,远超vLLM留下的内存。我们为vLLM语义路由提出了三种分阶段优化,经AMD Instinct MI300X基准测试,解决了延迟和内存问题。Stage 1:为ONNX Runtime on ROCm定制的CK Flash Attention操作符将注意力内存从O(n²)降至O(n),端到端(E2E)延迟从4,918 ms降至127 ms(38.7倍),使8K-32K tokens在SDPA OOM时可行。Stage 2:经典NLP提示压缩(TextRank、位置加权、TF-IDF和新颖性评分)将所有输入减少到约512 tokens,无需神经推理,无论原始提示长度,都将延迟和GPU内存限制在常数范围内(E2E 127 ms→62 ms,2.0倍)。Stage 3:近流式处理结合自适应分块和零拷贝JSON消除序列化开销(E2E 62 ms→50 ms,1.2倍)。累计:98倍改进(4,918 ms→50 ms),16K-token路由在108 ms内完成,且总路由GPU占用低于800 MB——足够与LLM服务共享GPU,无需专用加速器。Stage 1针对AMD ROCm(NVIDIA GPU已通过cuDNN实现FlashAttention);Stages 2和3是硬件无关的。
英文摘要:
System-level routers that intercept LLM requests for safety classification, domain routing, and PII detection must be both fast and operationally lightweight: they should add minimal latency to every request, yet not require a dedicated GPU -- an expensive resource better used for LLM inference itself. When the router co-locates on the same GPU as vLLM serving instances, standard attention's $O(n^2)$ memory makes long-context classification (8K--32K tokens) impossible: at 8K tokens, three concurrent classifiers need ${\sim}$4.5\,GB for attention masks alone, far exceeding the memory left by vLLM. We present three staged optimizations for the vLLM Semantic Router, benchmarked on AMD Instinct MI300X, that solve both the latency and the memory problem. \emph{Stage~1}: a custom CK Flash Attention operator for ONNX Runtime on ROCm reduces attention memory from $O(n^2)$ to $O(n)$ and end-to-end (E2E) latency from 4{,}918\,ms to 127\,ms (\textbf{38.7$\times$}), enabling 8K--32K tokens where SDPA OOMs. \emph{Stage~2}: classical NLP prompt compression (TextRank, position weighting, TF-IDF, and novelty scoring) reduces all inputs to ${\sim}$512 tokens without neural inference, capping both latency and GPU memory at a constant regardless of original prompt length (E2E 127$\to$62\,ms, \textbf{2.0$\times$}). \emph{Stage~3}: near-streaming body processing with adaptive chunking and zero-copy JSON eliminates serialization overhead (E2E 62$\to$50\,ms, \textbf{1.2$\times$}). Cumulatively: \textbf{98$\times$} improvement (4{,}918\,ms to 50\,ms), 16K-token routing in 108\,ms, and a total router GPU footprint under 800\,MB -- small enough to share a GPU with LLM serving and removing the need for a dedicated accelerator. Stage~1 targets AMD ROCm (NVIDIA GPUs already have FlashAttention via cuDNN); Stages~2 and~3 are hardware-agnostic.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。