KnapSpec: Self-Speculative Decoding via Adaptive Layer Selection as a Knapsack Problem
Organizations: School of Electrical Engineering, KAIST, Daejeon, South Korea · Department of Computer Science, University of California, Santa Barbara, CA, USA
Abstract
Self-speculative decoding (SSD) accelerates LLM inference by skipping layers to create an efficient draft model, yet existing methods often rely on static heuristics that ignore the dynamic computational overhead of attention in long-context scenarios. We propose KnapSpec, a training-free framework that reformulates draft model selection as a knapsack problem to maximize tokens-per-time throughput. By decoupling Attention and MLP layers and modeling their hardware-specific latencies as functions of context length, KnapSpec adaptively identifies optimal draft configurations on the fly via a parallel dynamic programming algorithm. Furthermore, we provide the first rigorous theoretical analysis establishing cosine similarity between hidden states as a mathematically sound proxy for the token acceptance rate. This foundation allows our method to maintain high drafting faithfulness while navigating the shifting bottlenecks of real-world hardware. Our experiments on Qwen3 and Llama3 demonstrate that KnapSpec consistently outperforms state-of-the-art SSD baselines, achieving up to 1.47x wall-clock speedup across various benchmarks. Our plug-and-play approach ensures high-speed inference for long sequences without requiring additional training or compromising the target model's output distribution.
Figures & tables
| Methods | Training-Free | Attn/MLP Separable | Adaptive Search | Context-Length Aware | Search Strategy |
| LayerSkip ( Elhoushi et al., 2024 ) | ✗ | ✗ | ✗ | ✗ | Static Early-Exit |
| Kangaroo ( Liu et al., 2024 ) | ✗ | ✗ | ✗ | ✗ | Fixed Sub-network |
| DEL ( Zarch et al., 2025 ) | ✗ | ✗ | ✓ | ✗ | Dynamic Early-Exit |
| ASD ( Metel et al., 2024 ) | ✓ | ✓ | ✓ | ✗ | Rule-based Pruning |
| Draft & Verify ( Zhang et al., 2024 ) | ✓ | ✓ | ✗ | ✗ | Bayesian Optimization |
| SWIFT ( Xia et al., 2025 ) | ✓ | ✓ | ✗ | ✗ | Bayesian Optimization + Random Search |
| Methods | Reasoning Tasks (Long-context Generation) | Summarization Tasks (Long-context Input) | |||||||||||||||||
| AIME24 | AIME25 | MMLU-Pro | GovReport | PG19 | BookSum | ||||||||||||||
| TPT | Speedup | TPT | Speedup | TPT | Speedup | TPT | Speedup | TPT | Speedup | TPT | Speedup | ||||||||
| Qwen3-32B ( layers) | Llama3.1-70B ( layers) | ||||||||||||||||||
| AR | 19.65 | 1.00 | 19.72 | 1.00 | 23.15 | 1.00 | 6.75 | 1.00 | 6.90 | 1.00 | 4.76 | 1.00 | |||||||
| DEL | 19.69 | 0.85 | 0% | 19.95 | 0.88 | 2.8% | 23.20 | 0.87 | 0% | 6.62 | 0.87 | 0.1% | 6.99 | 0.87 | 1.3% | 4.84 | 0.87 | 0.0% | |
| SWIFT | 20.38 | 1.23 | 84.6% | 20.73 | 1.22 | 80.4% | 21.75 | 0.90 | 46.8% | 8.62 | 1.33 | 91.6% | 6.12 | 0.98 | 61.9% | 3.76 | 0.84 | 49.3% | |
| Methods | Reasoning Tasks (Qwen3-8B) | Summarization Tasks (Llama3.1-8B) | |||||||||||||||||
| AIME24 | AIME25 | MMLU-Pro | GovReport | PG19 | BookSum | ||||||||||||||
| TPT | Speedup | TPT | Speedup | TPT | Speedup | TPT | Speedup | TPT | Speedup | TPT | Speedup | ||||||||
| AR | 31.87 | 1.00 | 32.58 | 1.00 | 33.52 | 1.00 | 19.71 | 1.00 | 20.64 | 1.00 | 14.02 | 1.00 | |||||||
| DEL | 31.29 | 0.86 | 0.0% | 37.89 | 0.82 | 0.0% | 25.58 | 0.83 | 22.2% | 20.01 | 0.63 | 0.0% | 20.64 | 0.67 | 0.1% | 13.91 | 0.69 | 0.0% | |
| SWIFT | 24.46 | 1.03 | 73.3% | 27.15 | 1.02 | 78.1% | 20.72 | 1.11 | 89.3% | 16.28 | 0.87 | 48.2% | 14.38 | 0.52 | 24.7% | 12.78 | 0.47 | 22.4% | |
| CLaSp | 24.08 | 1.06 | 83.1% | 27.62 | 1.07 | 91.6% | 24.68 | 1.09 | 91.4% | 16.98 | 1.07 | 86.0% | 15.83 | 1.02 | 82.3% | 9.03 | 1.02 | 78.0% | |
Appendix figures & tables3 assets
Supplementary material from the paper’s appendix.
Appendix
| Hardware | Model | ( ) | Speedup | ||
| RTX 6000 Pro | Llama-3.1-8B | 0.279 | 0.735 | 0.279 | 1.27 |
| Llama-3.2-3B | 0.161 | 0.720 | 0.255 | 1.25 | |
| RTX A6000 | Llama-3.1-8B | 0.520 | 0.942 | 0.216 | 1.28 |
| Llama-3.2-3B | 0.248 | 0.855 | 0.186 | 1.24 | |
| RTX 4090 | Llama-3.1-8B | 0.386 | 0.766 | 0.167 | O.O.M. |
| Llama-3.2-3B | 0.180 | 0.724 | 0.140 | 1.26 |
LLM Inference Acceleration
LLM inference acceleration develops algorithms and systems that reduce language-model latency, memory use, and serving cost while preserving output quality.
See all 1,090 papers