NewsCrawler.org

TokenGate from Stanford and UC Berkeley Speeds Up Long-Context LLM Prefill Up to 11.3x

TokenGate from Stanford and UC Berkeley Speeds Up Long-Context LLM Prefill Up to 11.3x
Image: Reddit

Researchers from Stanford and UC Berkeley released TokenGate, a drop-in module that adds learned token pruning to pretrained LLMs during long-context prefill[1]. A small MLP gate plus LoRA[2] (r=16) is attached to Qwen3-1.7B or Qwen3.5-2B, so only the tokens that matter receive full processing instead of every token passing through every layer. The team reports 1.4x to 11.3x faster time-to-first-token (TTFT[3]) with no accuracy loss and 1.5x to 3.4x lower peak prefill memory; timings use one A100 at batch size 1, and code and checkpoints are on GitHub under Apache-2.0.

The forward pass splits into three phases: layers below the gate layer process all N tokens as usual, an MLP scores each token from its post-attention residual, and a top-K selector keeps the highest-scoring tokens for the layers above, which never create KV entries[4] for the pruned ones; only the document part of the prompt is prunable, the question never is. Because top-K selection is not differentiable, TokenGate borrows the Mixture-of-Experts router trick: each kept token's score becomes a bias on attention logits above the gate, giving gradients a path back to the scorer. Training uses plain next-token loss, with each step averaging a full-context and a random-budget loss, so one trained gate works across budgets.

On five benchmarks (RepoBench-P, 2WikiMultihopQA, MultiNews, BioDEX and NIAH) TokenGate is Pareto-optimal against six baselines on the same LoRA backbone, beating the next-best baseline by up to 6.4x on TTFT and up to 2.1x on memory. A gate trained at 16k reaches 12.8x speedup at 32k and 13.0x at 64k and 128k, with memory savings near 3.43x. It also works on hybrid Qwen3.5-2B, which mixes Gated DeltaNet and full-attention layers: on NIAH 32k, gating layer 3 matched full-prefill accuracy at 3.8x faster prefill, while FastKV can only prune attention layers. Deployment requires Python 3.10+ and CUDA PyTorch 2.9+, with an optional FlashAttention-2 key-bias kernel that costs 1.0x to 1.1x a plain call.

Read the original marktechpost.comDiscussion

Sources

  • marktechpost.com

    Researchers from Stanford and UC Berkeley Introduce TokenGate: Token-Gated Attention Makes Long-Context Prefill Up to 11.3x Faster

    47 comments

Published: First seen: Читать по-русски

Open as a page