TL;DR
Self-speculative decoding accelerates LLMs by skipping layers to create a parameter-free draft model, but its performance degrades significantly when the input domain shifts. KNN-SSD solves this by using a simple K-Nearest Neighbor search on the LLM's hidden states to dynamically select the optimal skipped layers for each query. This approach delivers a robust 1.3×–1.6× speedup across diverse, real-world workloads without requiring any extra model training.
What Problem Does This Paper Address?
Speculative Decoding (SD) accelerates Large Language Model (LLM) inference by using a smaller, faster "draft" model to guess upcoming tokens, which the larger "target" model verifies in parallel. Self-Speculative Decoding (Self-SD) is a clever twist on this paradigm: instead of training a separate draft model, it simply skips some intermediate layers of the target model. It is completely parameter-free and requires zero extra training.
However, the authors uncover a major flaw in this setup: Self-SD is highly sensitive to domain shifts. A layer-skipping configuration optimized for text summarization fails miserably when given a math reasoning problem, sometimes even slowing down inference compared to standard decoding. Because real-world user queries are a unpredictable mix of tasks, a static choice of skipped layers is fundamentally sub-optimal.
Methods
The authors introduce KNN-SSD, a framework that dynamically adapts the draft model's architecture to the specific domain of each incoming query. The method operates in two phases:
- Pre-Inference Optimization: For a set of known domains, sample prompts are passed through the target LLM to extract their last hidden vector representations. The authors use K-means clustering to identify representative "anchor" vectors for each domain. Then, they run Bayesian Optimization to find the absolute best binary mask (which layers to skip and which to keep) for each specific domain.
- Inference: When a new query arrives, the model computes its last hidden vector and performs a quick K-Nearest Neighbor (KNN) search against the pre-computed anchors using cosine similarity. Once the domain is identified, the corresponding optimal skip-layer configuration is instantly applied to the LLM to act as the draft model for that specific generation step.
Datasets
The authors evaluated their approach on a diverse suite of benchmarks covering five distinct tasks:
- CNN/Daily Mail (CNN/DM) for text summarization.
- GSM8K for arithmetic reasoning.
- TinyStories for storytelling.
- WMT16 DE-EN for machine translation.
- Spider2 for complex text-to-SQL generation.
For out-of-domain generalization and fine-grained analysis, they also tested on XSUM (summarization), MATH (mathematical problem solving across 7 sub-types), and Alpaca (instruction-following).
Key Insights and Ideas
- The Hidden Layer is a Natural Classifier: One of the most compelling findings is that the last hidden layer vectors of an LLM naturally cluster cleanly by task domain without any explicit training. The authors achieved perfect classification accuracy using simple cosine similarity on these vectors.
- Dynamic Beats Static: Instead of searching for a single "one-size-fits-all" draft architecture, changing the architecture on-the-fly based on the input context preserves high token acceptance rates across shifting data streams.
- Negligible Overhead: While running a KNN search at inference time might sound slow, it only happens once per query on a small set of anchor vectors. It accounts for just ~2.5% of total generation time—a tiny price to pay for massive decoding speedups.
Key Results
- Consistent Speedups: KNN-SSD achieved a stable 1.3× to 1.6× wall-time speedup across different model families, including LLaMA-2-13B and Qwen-2.5-14B.
- Resilience to Mixed Streams: In experiments simulating real-world scenarios where tasks switch rapidly (high mix ratios), traditional Self-SD methods saw their speedups drop significantly. KNN-SSD maintained a flat, high speedup regardless of how chaotic the input stream was.
- High Acceptance Rates: Token acceptance rates remained remarkably high—over 80% for LLaMA-2 and over 99% for Qwen-2.5, proving that the dynamically selected draft models remained highly aligned with the full target models.
Limitations and Future Work
While KNN-SSD is highly effective, the authors note a couple of limitations:
- No Draft Tree Verification: The current implementation uses standard sequential drafting. Integrating advanced speculative decoding techniques like draft tree verification (which checks multiple token paths simultaneously) could push token acceptance rates and speedups even higher.
- Scale Constraints: Due to hardware limitations, the method was only validated on moderate-scale models (up to 13B/14B parameters). Testing the generalizability and overhead of KNN-SSD on massive 70B+ parameter models remains an open direction for future research.
Summary updated