Accelerating LLM Inference via Vector Index Based Output Embeddings

Martin Loretz, Sepp Hochreiter

TL;DR

This paper introduces a way to significantly speed up LLM inference on CPUs by replacing the final, massive "vocabulary layer" with a fast vector search index (HNSW). By treating token selection as a retrieval problem rather than a dense matrix multiplication, the authors achieve up to an 82% end-to-end speedup for small models with minimal impact on text quality.

What Problem Does This Paper Address?

In modern LLMs, the "output projection"—the final step where the model's internal representation is mapped to a probability distribution over thousands of possible words—is a major bottleneck. This is especially true for "compact" models (like Gemma 3 or Llama 3.2) that have small neural backbones but massive multilingual vocabularies (often 100k to 250k tokens).

During autoregressive decoding (generating text one word at a time), the system must stream the entire output embedding matrix from memory just to pick the top few most likely tokens. In low-latency, "batch-size-one" scenarios (like running a chatbot locally on a laptop or phone), this process is limited by memory bandwidth rather than raw computing power. The authors aim to bypass this "memory wall" by avoiding the full matrix multiplication entirely.

Methods

The authors reformulate the output projection as a Maximum Inner Product Search (MIPS) problem. Instead of calculating the score for every single word in the dictionary, they use a Hierarchical Navigable Small World (HNSW) index.

Key technical details include:

  • Vector Indexing: The rows of the output embedding matrix are stored in an HNSW graph. During inference, the model’s final hidden state acts as a "query" to find the nearest neighbors (the most likely tokens) in the graph.
  • Drop-in Integration: To keep the method compatible with existing software, the retrieved scores are "scattered" back into a sparse tensor. This allows standard sampling techniques like Top-P or Min-P to function as usual.
  • Safety Net: Because approximate searches might occasionally miss a critical token, the authors explicitly compute logits for a small set of "special" tokens (punctuation, structural words, etc.) to ensure they are always considered.
  • Tunable Accuracy: The parameter ef (search depth) allows users to trade off a bit of speed for higher retrieval accuracy.

Datasets

The researchers evaluated their method using:

  • Wikipedia: A subset of 20,000 tokens was used to measure "Recall@2" (how often the index correctly identifies the top two tokens compared to the exact mathematical baseline).
  • AlpacaEval: Used to assess the quality of the generated text. They employed GPT-5 Nano as an automated judge to perform pairwise comparisons between the original model and their optimized version.

Key Insights and Ideas

  • The "Tail Wagging the Dog": In very small models, the output embedding matrix can account for over 60% of the total parameters. Optimizing this single layer provides a disproportionately large boost to overall performance.
  • Retrieval vs. Calculation: The "aha moment" is realizing that we don't actually need the full probability distribution for 250,000 words; we only need the top few. Approximate Nearest Neighbor (ANN) algorithms, usually reserved for vector databases, are perfectly suited for this.
  • Post-Training Viability: Unlike previous methods (like Adaptive Softmax) that require changing the model's architecture before training, this approach can be applied to existing, pre-trained models as a "drop-in" replacement.

Key Results

  • Layer Speedup: The HNSW-based output head is up to 12x faster than the standard dense projection for Gemma models at batch size one.
  • End-to-End Throughput: For the Gemma 3 270M model, the total system speedup reached 82%. Even for larger 1B+ parameter models, speedups remained significant (around 20-40%).
  • High Fidelity: At a search depth of ef=200, the system achieved >99% recall. In quality testing (AlpacaEval), the win rates were near 50%, meaning the AI judge could rarely distinguish between the "approximate" fast version and the "exact" slow version.
  • Efficiency Crossover: The method is most effective at small batch sizes. As the batch size increases (above 32), the overhead of the graph search begins to outweigh the benefits of reduced memory loading.

Limitations and Future Work

  • CPU-Centric: The current implementation is optimized for CPUs. HNSW is fundamentally a sequential graph-traversal algorithm, making it difficult to implement efficiently on highly parallel GPUs.
  • Batch Size Scaling: The benefits diminish as batch sizes grow because the number of unique tokens to be retrieved across the batch eventually forces the system to load a large portion of the matrix anyway.
  • Quantization: The authors note that their approach is orthogonal to weight quantization (like 4-bit or 8-bit weights). Future work will look at combining these two techniques for even greater efficiency.
  • GPU Indices: The authors suggest exploring GPU-friendly indices (like CAGRA) to bring these gains to server-side hardware.

Summary updated

BibTeX
@inproceedings{loretz2026accelerating,
  author = {Martin Loretz and Sepp Hochreiter},
  title = {{Accelerating LLM Inference via Vector Index Based Output Embeddings}},
  booktitle = {AdaptFM @ ICML},
  year = {2026},
  url = {https://openreview.net/forum?id=nYQVHA4prY},
}
Figure