Faster In-Context Learning for LLMs via N-Gram Trie Speculative Decoding
Jinglin Chen, Qiwei Li, Zuchao Li, Baoyuan Qi, Liu Guoming, Haojun Ai, Hai Zhao, Ping Wang
Abstract
As a crucial method in prompt engineering, In-Context Learning (ICL) enhances the generalization and knowledge utilization capabilities of Large Language Models (LLMs) (Dong et al., 2024). However, the lengthy retrieved contexts and limited token throughput in autoregressive models significantly constrain reasoning speed. To address this challenge, we propose N-Gram Trie Speculative Decoding, a novel approach that leverages the overlap between context and model output. This method constructs an n-gram trie from the context to generate drafts, accelerating token generation for LLMs. We evaluate our approach on summarization, Retrieval-Augmented Generation (RAG), and context-based Question Answering (QA) tasks. Experimental results on Vicuna-7B, Llama2-7B-Chat, and Llama3-8B-Instruct demonstrate substantial speed improvements without compromising accuracy. Compared with various strong baselines, our method achieves the highest mean speedup, showcasing its effectiveness and efficiency.
BibTeX
@inproceedings{emnlp2025_fasterincontextl,
title = {Faster In-Context Learning for LLMs via N-Gram Trie Speculative Decoding},
author = {Jinglin Chen and Qiwei Li and Zuchao Li and Baoyuan Qi and Liu Guoming and Haojun Ai and Hai Zhao and Ping Wang},
booktitle = {EMNLP 2025},
year = {2025}
}