TL;DR
SWIFT (On-the-Fly Self-Speculative Decoding) is a "plug-and-play" acceleration method for Large Language Models (LLMs) that requires zero additional training or auxiliary models. By adaptively skipping intermediate layers to create a temporary "draft" model during inference, it achieves 1.3× to 1.6× speedups across various tasks while perfectly preserving the model's original output quality.
The Challenge of LLM Inference
Generating text with LLMs is notoriously slow because it happens one token at a time through autoregressive decoding. Speculative Decoding (SD) has emerged as a popular fix: a small, fast "draft" model predicts several future tokens, and the large "target" model verifies them all at once in parallel.
However, traditional SD has a major deployment hurdle. It usually requires a separate, smaller model (which might not exist for every LLM) or extensive fine-tuning to teach the target model how to "skip" its own layers (Self-Speculative Decoding). Furthermore, these methods are often "static"—a draft configuration optimized for summarizing news might fail miserably when asked to write Python code. The authors of SWIFT set out to create a method that is both model-agnostic and task-adaptive without the overhead of offline training.
The SWIFT Approach
SWIFT introduces a novel sparsity-based drafting approach that operates entirely on the fly. It eliminates the need for external draft models by leveraging the target LLM's own architecture.
During inference, SWIFT operates in two distinct phases:
- Context-Based Layer Set Optimization: Instead of using a pre-trained draft model, SWIFT treats the target LLM's own layers as a menu. It starts by skipping layers uniformly. As the model generates the first few tokens of a response, SWIFT uses those tokens as "ground truth" to test different layer-skipping configurations. Using a combination of Random Search and Bayesian Optimization, it quickly identifies which specific layers can be skipped for the current task to maximize speed without losing accuracy.
- Confidence-Aware Inference Acceleration: Once the optimal "sparse" version of the model is found, it enters the acceleration phase. SWIFT uses two clever tricks here:
- Early-stopping Drafting: If the draft model’s confidence score for a token drops below a threshold, it stops drafting immediately to avoid wasting computation on likely-wrong guesses.
- Dynamic Verification: It adjusts the number of candidate tokens it checks in parallel based on how "sure" the draft model is, further optimizing the balance between speed and verification cost.
Crucially, because it reuses the target model's KV cache, the computational overhead is minimal.
Key Insights: Sparsity and Task Adaptation
One of the most surprising findings in this research is that LLMs are inherently sparse. Simply skipping half the layers of a model like LLaMA-2-13B in a uniform pattern still yields a 1.2× speedup with high token acceptance. The "knowledge" is distributed such that a hollowed-out version of the model is still a remarkably good guesser.
Furthermore, the authors realized that sparsity is task-specific. The optimal layers to skip for a storytelling task are completely different from those for a mathematical reasoning task. A static draft model acts as a bottleneck, whereas SWIFT's adaptive approach acts as a turbocharger. Because this optimization happens on-the-fly (taking about 2 minutes and accounting for only 0.8% of total inference latency), it provides a 180× reduction in optimization time compared to previous state-of-the-art self-speculative methods.
Key Results
The researchers evaluated SWIFT across a diverse array of standard benchmarks, including Text Generation (CNN/Daily Mail, TinyStories), Reasoning (GSM8K), Code Generation (HumanEval), and Translation (WMT16 DE-EN).
- Consistent Speedups: SWIFT achieved a 1.3× to 1.6× wall-clock speedup across the LLaMA-2, CodeLLaMA, Yi, and DeepSeek-Coder families.
- High Fidelity: In greedy decoding settings, the token acceptance rate remained between 98% and 100%, meaning the draft model is almost perfectly aligned with the full model.
- Scaling Law: The authors observed that larger models (e.g., 70B vs 13B) actually exhibit more layer sparsity, suggesting that SWIFT will become even more effective as LLMs continue to grow in size.
- Robustness to Domain Shift: Unlike previous methods that slow down when the input topic changes, SWIFT's adaptive nature allows it to maintain high performance even when switching between wildly different tasks in a single data stream.
Limitations and Future Work
While highly effective, SWIFT does require a short "warm-up" optimization phase at the start of a sequence or batch. Its benefits are therefore most pronounced for longer generations or continuous data streams.
Additionally, SWIFT currently focuses on layer-skipping, which is orthogonal to other methods like Jacobi-based decoding (e.g., Lookahead). A promising future direction is integrating these techniques to push speedups toward 2.0× or beyond. Finally, while tested up to 70B parameters, SWIFT's behavior on "frontier" models (175B+ or Mixture-of-Experts architectures) remains an exciting open area for investigation.
Summary updated