ChatPaper.aiChatPaper

Batch Speculatieve Decoding Goed Toegepast

Batch Speculative Decoding Done Right

October 26, 2025
Auteurs: Ranran Haoran Zhang, Soumik Dey, Ashirbad Mishra, Hansi Wu, Binbin Li, Rui Zhang
cs.AI

Samenvatting

Speculatieve decodering versnelt LLM-inferentie door een klein draft-model te gebruiken om meerdere tokens voor te stellen die een doelmodel parallel verifieert. Het uitbreiden van dit concept naar batches is essentieel voor productie-inferentie, maar introduceert het 'ragged tensor'-probleem: sequenties in dezelfde batch accepteren verschillende aantallen draft-tokens, wat rechtsuitlijning verbreekt en positie-ID's, aandachtmaskers en KV-cache-toestand corrumpeert. Wij tonen aan dat verschillende bestaande batch-implementaties output-equivalentie schenden - de fundamentele eis dat speculatieve decodering identieke tokenreeksen moet produceren als standaard autoregressieve generatie. Deze schendingen treden precies op door onjuiste afhandeling van het ragged tensor-probleem. Als antwoord hierop (1) karakteriseren wij de synchronisatievereisten die correctheid garanderen, (2) presenteren wij een correctheid-gerichte batch-speculatieve decodering EQSPEC die heruitlijning blootstelt als 40% van de overhead, en (3) introduceren wij EXSPEC, dat een glijdende pool van sequenties onderhoudt en dynamisch groepen met gelijke lengte vormt, om de heruitlijningsoverhead te verminderen terwijl per-sequentie speculatieve snelheidswinst behouden blijft. Op de SpecBench-dataset, over Vicuna-7B/68M, Qwen3-8B/0.6B en GLM-4-9B/0.6B doel/draft-paren, behaalt onze aanpak tot 3x doorvoerverbetering bij batchgrootte 8 vergeleken met batchgrootte 1, met efficiënte schaalbaarheid tot batchgrootte 8, terwijl 95% output-equivalentie behouden blijft. Onze methode vereist geen aangepaste kernels en integreert naadloos met bestaande inferentiestacks. Onze code is beschikbaar op https://github.com/eBay/spec_dec.
English
Speculative decoding speeds up LLM inference by using a small draft model to propose multiple tokens that a target model verifies in parallel. Extending this idea to batches is essential for production serving, but it introduces the ragged tensor problem: sequences in the same batch accept different numbers of draft tokens, breaking right-alignment and corrupting position IDs, attention masks, and KV-cache state. We show that several existing batch implementations violate output equivalence-the fundamental requirement that speculative decoding must produce identical token sequences to standard autoregressive generation. These violations occur precisely due to improper handling of the ragged tensor problem. In response, we (1) characterize the synchronization requirements that guarantee correctness, (2) present a correctness-first batch speculative decoding EQSPEC that exposes realignment as consuming 40% of overhead, and (3) introduce EXSPEC, which maintains a sliding pool of sequences and dynamically forms same-length groups, to reduce the realignment overhead while preserving per-sequence speculative speedups. On the SpecBench dataset, across Vicuna-7B/68M, Qwen3-8B/0.6B, and GLM-4-9B/0.6B target/draft pairs, our approach achieves up to 3times throughput improvement at batch size 8 compared to batch size 1, with efficient scaling through batch size 8, while maintaining 95% output equivalence. Our method requires no custom kernels and integrates cleanly with existing inference stacks. Our code is available at https://github.com/eBay/spec_dec.
PDF231December 1, 2025