TokenGate: Adapting LLMs for Fast and Memory-Efficient Prefill with Learned Token Pruning
Organizations: Stanford University · UC Berkeley
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 - faster time-to-first token (TTFT) and - 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 faster prefill and 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.
Figures & tables
Appendix figures & tables11 assets
Supplementary material from the paper’s appendix.
Appendix
| Hyperparameter | Value |
|---|---|
| Base model | Qwen3-1.7B, bf16 |
| LoRA | , on query and value projections, all layers |
| Optimizer | AdamW; Muon ( Jordan et al., 2024 ) for the gate matrices ( TokenGate only) |
| Learning rate | , linear warmup over 1000 steps, then constant |
| Weight decay | |
| Gradient clipping | global norm |
| Full train time | Per-step time | |||||
|---|---|---|---|---|---|---|
| Dataset | SFT | Ours | Ratio | SFT | Ours | Ratio |
| Repo | 1.7h | 1.1h | 0.50s | 0.64s | ||
| 2Wiki | 3.8h | 4.0h | 0.34s | 0.43s | ||
| MNews | 1.3h | 1.8h | 0.21s | 0.27s | ||
| BioDEX | 1.2h | 1.0h | 0.23s | 0.30s | ||
| NIAH | 2.8h | 1.0h | 0.99s | 1.24s | ||
| NIAH 16k | NIAH 32k | NIAH 64k | NIAH 128k | |
|---|---|---|---|---|
| TTFT speedup | ||||
| Peak memory reduction |
| Dataset | What is kept | Failure mode |
|---|---|---|
| RepoBench-P | code syntax rather than identifiers: commas and empty argument lists “()” dominate, line breaks are avoided, and kept tokens are isolated rather than spans | wrong line, as with the full context |
| 2WikiMultihopQA | entities and dates: names and years are over-kept and function words avoided; on the shown prompt, the answer phrase (“Film Award for …Director”) | a different award at small budgets, exact at the shown one; multi-hop answers need the largest budgets to match the full context |
| MultiNews | mostly function words and scattered event words (“charged”, “president”); names and places are under-kept | right events, but wrong name, occupation and place, consistent with the under-kept names |
| BioDEX | terms of the diagnosis and outcome (“septic shock”, “failure”) and the connectives of lists (“and”, “or”); numbers are almost never kept | misses reactions, but so does the full-context model, which bounds the score |
| NIAH 16k | the needle sentence as one contiguous span, plus rare subwords elsewhere (“-haired”, “Lisp”, “.html”) | none: exact at every budget |
Token Pruning
Token pruning removes redundant tokens from transformer inputs or intermediate representations to reduce computation, memory use, and inference time.
See all 54 papers