98 Faster LLM Routing Without a Dedicated GPU: Flash Attention, Prompt Compression, and Near-Streaming for the vLLM Semantic Router
Organizations: vLLM Semantic Router Project · MBZUAI · McGill University · AMD ·
Abstract
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 memory makes long-context classification (8K--32K tokens) impossible: at 8K tokens, three concurrent classifiers need 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. Stage~1: a custom CK Flash Attention operator for ONNX Runtime on ROCm reduces attention memory from to and end-to-end (E2E) latency from 4{,}918,ms to 127,ms (\textbf{38.7}), enabling 8K--32K tokens where SDPA OOMs. Stage~2: classical NLP prompt compression (TextRank, position weighting, TF-IDF, and novelty scoring) reduces all inputs to 512 tokens without neural inference, capping both latency and GPU memory at a constant regardless of original prompt length (E2E 12762,ms, \textbf{2.0}). Stage~3: near-streaming body processing with adaptive chunking and zero-copy JSON eliminates serialization overhead (E2E 6250,ms, \textbf{1.2}). Cumulatively: \textbf{98} 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. Stage1 targets AMD ROCm (NVIDIA GPUs already have FlashAttention via cuDNN); Stages2 and~3 are hardware-agnostic.
Figures & tables
| Method | Requires Neural Inf. | Compression Granularity | Attention Preserved? | Compression Latency |
|---|---|---|---|---|
| LLMLingua [ 9 ] | LLaMa-7B | Token | Yes ∗ | 2–5 s |
| LLMLingua-2 [ 10 ] | XLM-R (560M) | Token | Yes ∗ | 0.3–1 s |
| Selective Context [ 11 ] | GPT-2/LLaMa | Sentence/phrase | Partial | 1–3 s |
| RECOMP [ 12 ] | Trained encoder | Abstractive | No (rewritten) | 0.5–2 s |
| Ours | None | Sentence | Yes (U-shaped + novelty) | 19 ms |
| Strategy | Inspect? | Mutate? | Overhead | Copies |
|---|---|---|---|---|
| Pure passthrough | No | No | 0 | 0 |
| Header-only routing | No | Headers | 0 | 0 |
| Full buffering | Yes | Yes | 2–3 | |
| Ours | Adaptive | Adaptive | / ∗ | 0/1 ∗ |
| Component | Version / Spec |
|---|---|
| GPU | AMD Instinct MI300X, 192 GB HBM3 |
| GPU arch | gfx942 (CDNA 3) |
| ROCm | 7.0 |
| ONNX Runtime | 1.22.1 (ROCm wheel) |
| CK Flash Attn lib | libort_ck_flash_attn.so (192 KB) |
| Rust ort crate | 2.0.0-rc.10 (load-dynamic) |
| Tokens | Signal | GPU (ms) | CPU (ms) | Speedup |
|---|---|---|---|---|
| End-to-end routing latency (ONNX GPU+FA vs ONNX CPU) | ||||
| 500 | (all) | 22 | 803 | 36.5 |
| 2,000 | (all) | 31 | 1,773 | 57.2 |
| 8,000 | (all) | 127 | 4,918 | 38.7 |
| Per-signal extraction latency | ||||
| 500 | Jailbreak | 14.2 | 779.8 | 54.9 |
| Seq Length | SDPA (ms) | FA (ms) | Speedup |
|---|---|---|---|
| 512 | 19 | 19 | 1.0 |
| 1,024 | 26 | 23 | 1.1 |
| 2,048 | 51 | 32 | 1.6 |
| 4,096 | 167 | 51 | 3.3 |
| 8,192 | OOM | 105 | — |
| 16,384 | OOM | 259 | — |
| Tokens | Signal | No Compression | Compressed |
|---|---|---|---|
| 500 | Jailbreak | 10.1 ms | 9.3 ms |
| 2,000 | Jailbreak | 18.0 ms | 11.1 ms |
| 8,000 | Jailbreak | 45.3 ms | 10.5 ms |
| 16,000 | Jailbreak | 126.6 ms | 10.4 ms |
| 16,000 | Domain | 85.3 ms | 7.1 ms |
| 16,000 | PII | 84.6 ms | 6.2 ms |
| Input Tokens | Output Tokens | Ratio | Latency (ms) |
|---|---|---|---|
| 2,000 | 510 | 25.1% | 2 |
| 4,000 | 511 | 12.7% | 4 |
| 8,000 | 512 | 6.4% | 9 |
| 16,000 | 512 | 3.2% | 19 |
| Configuration | Tokens | E2E (ms) | Stage Speedup | Cumulative |
| ONNX CPU, BUFFERED (baseline) | 8K | 4,918 | — | 1.0 |
| Candle CPU, BUFFERED | 8K | 1,818 | 2.7 | 2.7 |
| ONNX GPU (SDPA), BUFFERED | 8K | OOM | — | — |
| Stage 1: GPU + CK Flash Attention | ||||
| ONNX GPU (FA), BUFFERED | 8K | 127 | 38.7 | 38.7 |
| Stage 2: + Prompt Compression (8K 512 tokens) | ||||
| Tokens | BUFFERED (ms) | STREAMED (ms) | Reduction |
|---|---|---|---|
| 500 | 12 | 11 | 8.3% |
| 2,000 | 15 | 14 | 6.7% |
| 8,000 | 30 | 20 | 33.3% |
| 16,000 | 61 | 31 | 49.2% |
| Original Tokens | Mode | C=1 | C=10 | C=20 |
|---|---|---|---|---|
| Raw FA classifier latency (median ms, no compression) | ||||
| 512 | FA only | 19 | 77 | 142 |
| 2,048 | FA only | 32 | 141 | 275 |
| 8,192 | FA only | 105 | 601 | 1,058 |
| 16,384 | FA only | 259 | 1,567 | 3,089 |
| 32,768 | FA only | 756 | 5,406 | 9,872 |
| Metric | Original | Compressed |
|---|---|---|
| Domain classification (correct domain, ) | ||
| Overall | 53.1% | 61.2% |
| PII detection (when PII signal embedded, ) | ||
| PII detected | 78.5% | 92.4% |
| Jailbreak detection (when signal embedded, ) | ||
| Jailbreak detected | 70.8% | 56.6% |
| Configuration | Latency (ms) | req/s |
|---|---|---|
| ONNX CPU, 8K (baseline) | 4,918 | 0.2 |
| GPU+FA, 500 tok | 22 | 45.5 |
| GPU+FA, 8K tok | 127 | 7.9 |
| GPU+FA+comp+stream, 500 tok | 17 | 58.8 |
| GPU+FA+comp+stream, 8K tok | 50 | 20.0 |
| GPU+FA+comp+stream, 16K tok | 108 | 9.3 |
| Router | Model | GPU Mem. | Ded. GPU? |
|---|---|---|---|
| RouteLLM (MF) | Mat. factorization | 0 (CPU) | No |
| RouteLLM (BERT) | 0.3B classifier | 0.6 GB | Yes |
| RouteLLM (Causal) | 8B LLM | 16 GB | Yes |
| NVIDIA Blueprint | BERT/CLIP + Triton | 1–2 GB | Yes |
| R2-Router | Reasoning LLM | 16+ GB | Yes |
| Ours | 3 mmBERT-32K | 0.8 GB | No |
| Router Config. | GPU Mem. | GPU | $/yr/node |
|---|---|---|---|
| SDPA, 8K, C=1 | 5 GB | L4 | $3,500 |
| SDPA, 16K, C=1 | 19 GB | A10G | $8,800 |
| SDPA, 32K, C=1 | 73 GB | A100 80G | $10,100 |
| RouteLLM (Causal) | 16 GB | A10G | $8,800 |
| R2-Router | 16+ GB | A10G | $8,800 |
| Ours (co-located) | 0.8 GB | None | $0 |
LLM Routing
Large language model routing selects models, tools, experts, or inference strategies to balance answer quality, cost, latency, and deployment constraints.
See all 349 papers