arXiv(opens in a new tab)cs.CLOct 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2610.26754

TokenGate: Adapting LLMs for Fast and Memory-Efficient Prefill with Learned Token Pruning

Liana Patel, Rishabh Ranjan, Ion Stoica, Matei Zaharia, Carlos Guestrin

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Expert human readers process large inputs (e.g., code repositories and long documents) by skimming to closely read only what matters. On the other hand, language models process all input tokens through each model layer, resulting in significant processing costs for long-context inputs. We introduce TOKENGATE, a small, drop-in component that extends existing trained models to enable end-to-end learnable token pruning over long-context inputs for fast and memory-efficient prefill. To enable end-to-end learning despite the non-differentiable top-K operator for token pruning, we introduce token-gated attention, a mechanism inspired by Mixture-of-Experts that re-weights attention logits using token importance scores. Across diverse tasks, TOKENGATE achieves 1.4-11.3× faster time-to-first token (TTFT) and 1.5-3.4× lower peak memory at no accuracy degradation for prefill in transformers. Compared to the best-performing prior methods for token-pruning, TOKENGATE gives up to 6.4× faster prefill and 2× lower peak memory. TOKENGATE natively extends both standard transformers (e.g., Qwen3) and hybrid-attention models (e.g., Qwen3.5) with simple lightweight adaptation comparable to standard parameter-efficient fine-tuning. We make our code available at: https://github.com/tokengate-models/TokenGate.

1 INTRODUCTION

Long-context inputs underpin exciting recent language model deployments, where the model's ability to process vast swaths of personalized user data and live content during inference has led to transformative capabilities in deep research, large-scale document processing, coding agents, and data agents (OpenAI, 2025b; Gemini, 2025; Anthropic, 2025b;a; Anysphere, 2025; GitHub, 2025). When processing large inputs, like code or long documents, experts readers skim to closely read only what matters. Yet, transformers process every token of their input through each layer, whether or not the token bears critical information. The cost of this full read is attention compute that grows quadratically with input length, as well as MLP compute and KV-cache memory that grow linearly, making long-context prefill a key bottleneck in model serving.

Recent research proposes to address this efficiency challenge for long-context prefill through two primary approaches. First, one body of work proposes training-free token pruning, using attention-based scoring heuristics to prune token hidden states, forwarding only the highest-scoring tokens to upper layers (Jo et al., 2025; Long et al., 2025; Jin et al., 2025; Shi et al., 2024; Yang et al., 2024a; Fu et al., 2024; Chen et al., 2026; Wang et al., 2021). These methods are inexpensive to deploy, requiring no model training, but demonstrate limited speedups before degrading accuracy. Alternatively, a large body of work instead develops architectural modifications to the standard transformer architecture (Vaswani et al., 2017). These methods offer promising prefill-efficiency improvements, but are expensive to train, often requiring pre-training from scratch and substantially different hardware and software than existing ecosystems (Dehghani et al., 2018; Bae et al., 2025; Graves, 2016; Raposo et al., 2024; Ainslie et al., 2023; Kim et al., 2021; He et al., 2025; Gu & Dao,

Correspondence to: lianapat@stanford.edu, matei@berkeley.edu, guestrin@stanford.edu.

(a) LLM Prefill with TOKENGATE

(c) Token-Gated Attention

Figure

Figure

(b) Gate Module

Figure

(d) Pareto-Optimality with Varied K

2WikiMultihopQA dataset

= TOKENGATE = SlimInfer = FastKV

★ Standard prefill (full context)

Figure

Time to first token

Peak prefill memory

Figure 1: Overview of TOKENGATE. (a) Layers up to L prefill all N context tokens as usual; at layer L the gate module keeps K of them, and every layer above L processes only those K tokens. (b) The gate module scores each hidden state with a small scoring network, and a top-K selector forwards the kept hidden states together with their importance scores. (c) Token-gated attention multiplies each attention weight by the gate value gjg_j of its key, which enables end-to-end training. (d) On 2WikiMultihopQA question answering, with Qwen3-1.7B, TOKENGATE pushes the Pareto frontier of accuracy versus time-to-first-token and peak prefill memory; at 95% of the full-context accuracy it prefills 3.0×3.0\times faster and with 2.7×2.7\times less memory, outperforming the best training-free token pruning methods, like FastKV (Jo et al., 2025) and SlimInfer (Long et al., 2025).

2023; Dao & Gu, 2024). To bridge this gap, we ask the question, can we endow existing trained models with improved long-context prefill efficiency while maintaining strong accuracy?

In this work, we introduce TOKENGATE, a small, drop-in component that extends transformer-based models, enabling end-to-end trainable token pruning over long-context inputs for efficient prefill. The model forward pass using TOKENGATE decomposes into three parts, as Figure 1a shows. First, layers below the gate module perform a standard forward pass, processing all tokens through each layer. Second, tokens pass through the gate module, which produces a score for each token, retaining only the top-K for continued processing. Third, the layers above the gate module process the selected tokens with token-gated attention, a mechanism that re-weights the attention computation using the generated importance scores. TOKENGATE reduces prefill compute and memory because pruned tokens are never forwarded through the post-gate layers and these layers never generate KV cache entries.

Token pruning uses a non-differentiable top-K operator, which presents a challenge for end-to-end learning. We introduce token-gated attention to overcome this issue. Our method takes inspiration from Mixture-of-Experts (MoE) (Shazeer et al., 2017; Fedus et al., 2022), which achieve sparsity over activated model parameters by gating expert sub-networks. We use a similar form, but instead weight attention logits to achieve sparsity over processed tokens. Using this technique, we demonstrate that we can adapt existing trained models with cost similar to standard adaptation techniques. For instance, we can fine-tune existing models with TOKENGATE using simple next-token-prediction loss, with no auxiliary loss and total train time similar to supervised fine-tuning on the base model. The resulting TOKENGATE model matches or exceeds accuracy over the trained base model, while significantly reducing prefill latency and memory.

We evaluate TOKENGATE on diverse tasks, including code completion, multi-hop QA, multi-doc summarization, medical extraction, and needle-in-a-haystack, using both traditional transformer models and a recent hybrid attention one. Overall, we show the following findings (1) TOKENGATE reduces TTFT and peak prefill memory by 1.4−11.3×1.4-11.3\times and 1.5−3.4×1.5-3.4\times, respectively, at no accuracy degradation compared to the finetuned model baseline with full-context, and outperforms all training-free token pruning methods, by up to 6.4×6.4\times faster prefill (TTFT) and 2×2\times lower peak prefill memory relative to the next-best baseline, (2) TOKENGATE natively extends existing recent hybrid-attention architectures, like Qwen3.5-2B (Qwen Team, 2026), where it achieves 3.8×3.8\times lower TTFT over the full-context baseline at no accuracy degradation, and 2.1×2.1\times lower TTFT than the next best-performing token-pruning method at fixed accuracy. (3) Training models is efficient with TOKEN-GATE, incurring minimal overhead compared to standard parameter-efficient fine-tuning techniques, like LoRA (Hu et al., 2021).

Overall, we summarize our contributions as follows:

• We introduce TOKENGATE, a small, drop-in component that extends existing trained models to enable end-to-end learnable token pruning for fast and memory-efficient prefill.

• We propose token-gated attention, a mechanism for training models end-to-end despite the gate module’s non-differentiable top-K operator.

• Our systematic evaluation finds that TOKENGATE reduces TTFT and peak prefill memory by up to 6.4×6.4\times and 2×2\times, respectively, compared to the next best-performing baselines, TOKENGATE natively extends transformer-based models, including recent hybrid-attention architectures. Further, training is efficient, with total train time comparable to standard parameter-efficient fine-tuning techniques.

References (81)