TL;DR
SHADOWPREFILL eliminates the "switch tax" in agentic LLM routing—where switching between models (e.g., from a small model to a large one) normally destroys prefix cache benefits. By proactively warming up the alternative model's cache using idle GPU capacity and latency slack from normal traffic, it reduces switch-call latency by up to 21% and token costs by up to 46% with virtually no impact on existing service levels.
What Problem Does This Paper Address?
Modern AI agents don't just make one call; they engage in loops—planning, using tools, and reasoning. To save money, developers use per-step routers that send easy tasks to small, cheap models and hard tasks to large, expensive ones.
However, there is a hidden cost: the Model Switch Tax. LLMs rely on KV (Key-Value) caches to remember conversation history. Because these caches are model-specific, switching from Model A to Model B means Model B has no memory of the session. It must "prefill" the entire history from scratch. In long-context scenarios like coding agents, this "cold switch" can make calls take 3x longer and forfeits the deep discounts (often 90%) that providers offer for cached input tokens.
Methods
The authors introduce SHADOWPREFILL, a system that keeps the "next" model warm in the background.
- Shadow Prefilling: While the chosen model (e.g., a small model) is generating a response, SHADOWPREFILL proactively prefills that same context onto the other model’s instance.
- Harvesting Idle Capacity: Instead of requiring extra GPUs, it "harvests" spare cycles. Even busy GPUs have "SLO slack"—gaps in time where they are waiting on memory-bound decoding. SHADOWPREFILL inserts small "shadow chunks" into these gaps without delaying "normal" user traffic.
- Incremental Streaming: As the active model generates new tokens, they are streamed immediately to the shadow model's cache.
- Host-Memory Spill Tier: For massive contexts (100K+ tokens) that exceed GPU memory (HBM), the system spills the shadow cache to host DRAM and reloads it over PCIe when needed. This is significantly faster than recomputing the cache.
- Safety Mechanisms: Shadow work is strictly lowest-priority. If a real request arrives, the shadow work is instantly preempted to ensure no Service Level Objective (SLO) regressions for standard users.
Datasets
The system was evaluated using a mix of routing benchmarks and real-world traces:
- Routing Benchmarks: xRouteBench, FusionBench, and Router-R1.
- Agentic Traces: SWE-bench (software engineering trajectories) and a production coding-agent trace from GitHub Copilot (GHCP-coding).
- Background Traffic: One week of production LLM inference traces from Azure (text and multimodal) were replayed to simulate realistic "normal traffic" for the GPUs to harvest from.
Key Insights and Ideas
- The "Slack" is a Goldmine: The authors found that even at peak load, LLM decode iterations often leave 69–79% of their latency budget unused because they are memory-bound. This provides a massive, free playground for background tasks like shadow prefilling.
- Lossless is Better: Unlike recent research attempting to "translate" KV caches between different models (which is approximate and requires retraining), SHADOWPREFILL computes the exact KV cache on the target model, ensuring perfect accuracy.
- Disaggregation Synergy: In clusters where prefill and decoding are handled by separate machines (PD-disaggregation), prefill instances are often idle, making SHADOWPREFILL even more effective.
Key Results
- Latency Reduction: Across 24 model pairs, SHADOWPREFILL cut switch-call latency by 8.5–21.4% and slashed Time-To-First-Token (TTFT) by 44–47%.
- Cost Savings: By maintaining high prefix hit rates, it reduced routed token costs by 22.5–46.1%.
- Minimal Overhead: The system achieves these gains with only a 0.4% increase in energy per request and zero violations of normal traffic SLOs.
- Efficiency: It captures roughly 52% of the latency gains that would be possible if model switches were theoretically "free" (an oracle baseline), all without adding extra GPUs.
Limitations and Future Work
- Multi-Model Scaling: While highly effective for pairs of models, the "waste" (unused shadow work) increases as the number of candidate models grows, since the system must guess which model the router will pick next.
- Large Model Bottlenecks: For extremely large models (e.g., >50B parameters), the time spent decoding tokens begins to outweigh the time saved by prefilling, leading to diminishing returns for cache warming.
- Predictive Routing: Future work could involve tighter integration with the router's internal logic to better predict the next model and reduce speculative work.
Summary updated