KnapSpec: Self-Speculative Decoding via Adaptive Layer Selection as a Knapsack Problem

Fuente: arXiv
Gespeichert in:
Bibliographische Detailangaben
Hauptverfasser: Cha, Seongjin, Kim, Gyuwan, Han, Dongsu, Yang, Tao, Han, Insu
Format: Preprint
Veröffentlicht: 2026
Schlagworte:
Online-Zugang:
Tags: Tag hinzufügen
Keine Tags, Fügen Sie den ersten Tag hinzu!
_version_ 1866918352799137792
author Cha, Seongjin
Kim, Gyuwan
Han, Dongsu
Yang, Tao
Han, Insu
author_facet Cha, Seongjin
Kim, Gyuwan
Han, Dongsu
Yang, Tao
Han, Insu
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2602_20217
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle KnapSpec: Self-Speculative Decoding via Adaptive Layer Selection as a Knapsack Problem
Cha, Seongjin
Kim, Gyuwan
Han, Dongsu
Yang, Tao
Han, Insu
Machine Learning
Artificial Intelligence
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.
title KnapSpec: Self-Speculative Decoding via Adaptive Layer Selection as a Knapsack Problem
topic Machine Learning
Artificial Intelligence
url https://arxiv.org/abs/2602.20217