FlashHead: Efficient Drop-In Replacement for the Classification Head in Language Model Inference

Wilhelm Tranheden, Shahnawaz Ahmed, Devdatt Dubhashi, Jonna Matthiesen, Hannes von Essen

TL;DR

FlashHead is a training-free, "drop-in" replacement for the final classification head in Large Language Models (LLMs) that delivers up to a 1.75x model-level speedup with virtually no loss in accuracy. By reframing the massive final matrix multiplication as an efficient retrieval problem, it removes a major compute and memory bottleneck for running small language models on consumer hardware.

What Problem Does This Paper Address?

As we move toward Small Language Models (SLMs) designed to run on phones and laptops, we’ve hit a weird architectural wall: the "Classification Head Bottleneck."

In a standard transformer, the final layer (the head) multiplies a hidden vector by a massive embedding matrix to decide which word comes next. As vocabulary sizes balloon (often over 128k tokens), this single layer can account for up to 60% of a model's total parameters and 50% of the inference compute. While researchers have spent years quantizing and optimizing the transformer "body," they usually leave the head alone because compressing it typically destroys accuracy. FlashHead aims to fix this without requiring any expensive retraining or fine-tuning.

Methods

FlashHead replaces the standard dense matrix multiplication with a two-stage retrieval process inspired by Information Retrieval (IR) principles. Its architecture rests on four pillars:

  1. Equal-Sized Clustering: Using a variant of spherical K-means, the authors partition the vocabulary into clusters of exactly the same size. This is a "hardware-first" design choice; equal sizes allow the clusters to be stored in compact, predictable tensors, making memory access much faster on GPUs.
  2. Efficient Multi-Probing: Instead of just looking at the single most likely cluster, FlashHead scores hundreds or thousands of clusters in parallel. This "wide" search ensures that the model doesn't miss the correct token even if it's semantically "far" from the cluster center.
  3. Probabilistic Probe Sampling: To support creative, open-ended generation (stochastic decoding), FlashHead introduces a multinomial sampling step at the cluster level. It samples clusters first, then tokens within those clusters, bridging the gap between retrieval and probabilistic sampling.
  4. Selective Quantization: The first stage (finding the right clusters) is performed using low-bit (INT4) math. Because the second stage (scoring tokens within those clusters) uses higher precision to refine the results, the system is incredibly robust to quantization errors.

Datasets

The authors evaluated FlashHead across a wide battery of standard benchmarks to ensure "head-level fidelity":

  • Reasoning & Knowledge: MMLU-Pro, HellaSwag, BoolQ, BBH, GSM8K.
  • Instruction Following: IFEval, AlpacaEval.
  • Multilingual/Logic: XNLI, MATH-Hard.
  • Models Tested: Llama-3.2 (1B, 3B), Llama-3.1 (8B), Qwen-3 (1.7B), and Gemma-3 (270M, 1B).

Key Insights and Ideas

  • The Head is a Retrieval Problem: The core "aha" moment is realizing that we don't need to score 128,000 tokens every single time. Most tokens are irrelevant in a given context. By treating the head as a search task, we can ignore 95%+ of the vocabulary for every token generated.
  • Hardware Symmetry Matters: Previous attempts at this used "ragged" clusters (different sizes), which are a nightmare for GPU kernels. Enforcing equal-sized clusters allows for simple modular arithmetic to find token indices, which is why FlashHead actually sees real-world speedups where others only saw theoretical ones.
  • Synergy over Isolation: The authors emphasize that their four innovations are synergistic. For example, multi-probing makes the system robust enough to handle the "noise" introduced by INT4 quantization in the first stage.

Key Results

  • Speed: On an NVIDIA RTX 3500 Ada (a laptop-class GPU), FlashHead achieved a 1.75x end-to-end speedup for Llama-3.2-1B using INT4. The head-only latency was reduced by nearly 5x (from 1.94ms to 0.40ms).
  • Accuracy: Across almost all benchmarks, FlashHead matched the baseline model's performance within rounding error. In "Top-k Containment" tests (checking if the original top tokens are still in FlashHead's top list), it achieved near-perfect scores (1.00 for Alpaca and MATH-Hard).
  • Scaling: The benefits hold even as models grow. Even at the 8B parameter scale, where the GPU is usually saturated, FlashHead still provided a 1.13x speedup.

Limitations and Future Work

  • Monte Carlo Evaluation: Because FlashHead doesn't calculate scores for every single token in the vocabulary, it cannot provide a "closed-form" probability distribution. For research evaluations that require exact log-likelihoods (like HellaSwag), the authors had to use Monte Carlo simulations, which are slow.
  • Training Integration: Currently, FlashHead is a post-training "drop-in." The authors suggest that integrating this retrieval-based logic during training could lead to even more efficient models designed from the ground up for this type of inference.
  • Beyond Text: The paper focuses on Language Models, but the authors note that this could potentially be adapted for multimodal models or other high-vocabulary tasks.

Summary updated

Abstract

Language models are increasingly adopting smaller architectures optimized for consumer devices. In this setting, inference efficiency is the primary constraint. Meanwhile, vocabulary sizes continue to grow rapidly, making the classification head a critical bottleneck that accounts for up to 60\% of model parameters, and 50\% of inference compute. We introduce FlashHead, the first efficient drop-in replacement for the dense classification head that is training-free and hardware-friendly. FlashHead builds on principles from information retrieval, reframing that computation at the output head as a retrieval problem rather than a dense classification over the full vocabulary. FlashHead introduces four key innovations: (1) a balanced clustering scheme that structures vocabulary partitions into compact hardware-efficient tensors, (2) extending multiprobe retrieval to language model heads, enabling thousands of clusters to be scored in parallel, (3) a novel inference-time sampling mechanism that extends retrieval beyond top tokens, enabling probabilistic sampling across the full vocabulary, and (4) selective quantization, enabling effective low-bit computation in the head. Experiments on Llama-3.2, Gemma-3, and Qwen-3 show that FlashHead delivers model-level inference speedups of up to \textbf{1.75x} which maintaining output accuracy compared to the original head. By overcoming the classification head bottleneck, FlashHead establishes a new benchmark for efficient inference and removes a key barrier to developing smaller, capable models for consumer hardware.
BibTeX
@misc{tranheden2026flashhead,
  author = {Wilhelm Tranheden and Shahnawaz Ahmed and Devdatt Dubhashi and Jonna Matthiesen and Hannes von Essen},
  title = {{FlashHead: Efficient Drop-In Replacement for the Classification Head in Language Model Inference}},
  year = {2026},
  eprint = {2603.14591},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2603.14591},
}
Figure