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

Wilhelm Tranheden, Shahnawaz Ahmed, Devdatt Dubhashi, Jonna Matthiesen, Hannes von EssenSubmission to ICLR 2026 · Desk rejected

Here is a concise, accessible summary of the paper.

FlashHead: Unbottlenecking Language Model Inference with Retrieval-Based Output Heads

TL;DR

FlashHead is a training-free, drop-in replacement for the final classification layer (lm-head) in language models that reframes token generation as a fast two-stage retrieval problem. By combining equal-sized spherical clustering, multi-probe retrieval, and selective quantization, it slashes classification head latency by up to $4.85\times$ and delivers end-to-end model speedups of up to $1.75\times$ without degrading benchmark accuracy.

What Problem Does This Paper Address?

In Small Language Models (SLMs) tailored for edge devices and consumer hardware (such as Llama-3.2-1B or Gemma-3-270M), vocabulary sizes have exploded to 128k+ tokens. As the model backbone shrinks, the final linear layer—the dense classification head that computes dot products between the hidden state and every token embedding—becomes an outsized bottleneck.

In sub-3B models, this single projection can account for 20% to 60% of total parameters and up to 50% of inference compute. While the rest of the Transformer body has benefited from weight quantization (e.g., INT4), deployment frameworks like vLLM historically leave the output head in high precision (FP16/BF16) because quantizing it severely degrades model accuracy. Prior head-efficiency alternatives (like hierarchical softmax or vocabulary trimming) either require expensive retraining, distort the output distribution, or rely on hardware-unfriendly dynamic sparse operations.

Methods

FlashHead converts the dense $O(v \cdot d)$ classification step into a two-stage inverted-file (IVF) retrieval routine with complexity $O(cd + pbd)$, where $c$ is the number of clusters, $b$ is the cluster size, and $p$ is the number of sampled probes ($p \cdot b \ll v$):

  1. Equal-Sized Spherical $K$-Means: Offline, the token embedding matrix is partitioned into $c$ clusters of strictly identical size ($b = v/c$) using cosine similarity. Balancing cluster size is hardware-critical: it maps cluster IDs to token indices using a dense, regular 2D tensor, avoiding ragged memory gathers and dynamic masking on GPUs.
  2. Aggressive Multi-Probe Retrieval: Rather than assigning queries to a single cluster, FlashHead scales to tens of thousands of clusters ($c \approx 8{,}016$) and queries hundreds of candidate clusters ($p = 512$) simultaneously.
  3. Probabilistic Probe Sampling: To support stochastic generation (sampling temperature $\tau > 0$), FlashHead samples $p$ clusters without replacement via softmax on coarse centroid logits, gathers the candidate token subset, and performs the final token softmax over only this candidate pool.
  4. Selective Quantization: FlashHead safely quantizes the first stage (centroid logits $C \times h$) down to INT4. Because mass is distributed across hundreds of clusters, coarse centroid scoring is noise-tolerant, and final probabilities are refined using full-precision embeddings in stage two.

Datasets

The authors evaluate FlashHead on diverse generation, reasoning, and containment benchmarks:

  • Core Benchmarks: MMLU-Pro, HellaSwag, IFEval, BoolQ, BIG-bench Hard (BBH), TruthfulQA-gen, GSM8K (8-shot CoT), and OpenBookQA.
  • Top-$k$ Containment & Edge Cases: Alpaca (eval), MATH-Hard (complex logic), and XNLI (cross-lingual representations).
  • Base Models: Llama-3.2 (1B, 3B), Llama-3.1 (8B), Gemma-3 (270M, 1B), and Qwen-3 (1.7B).

(No new datasets were introduced; established public benchmarks were used).

Key Insights and Ideas

  • Equal cluster sizes matter more for hardware than for mathematics: While standard $k$-means produces variable-sized clusters, forcing equal sizes enables modular arithmetic indexing. This eliminates irregular memory reads, reducing head latency from $0.520\,\text{ms}$ to $0.320\,\text{ms}$ on GPU while slightly improving accuracy.
  • Two-stage retrieval protects quantization: Directly quantizing a dense output head hurts accuracy (BBH drops from 0.381 to 0.369). FlashHead quantizes only centroid matching while computing candidate token logits in higher precision, achieving faster inference ($0.258\,\text{ms}$) with almost zero degradation (0.379 BBH).
  • Clustering keys beats clustering queries: Unlike older retrieval-based heads that cluster dynamic context vectors (requiring training-set statistics), FlashHead clusters static token keys once offline, making it completely data-free and training-free.

Key Results

  • Task Accuracy: FlashHead matches the dense baseline across MMLU-Pro (0.18), HellaSwag (0.59), IFEval (0.45), BoolQ (0.69), BBH (0.38), and GSM8K (0.46) on Llama-3.2-1B.
  • Head & Model Latency: On an NVIDIA RTX 3500 Ada GPU (batch size 1):
  • Head speedup: Cuts Llama-3.2-1B head latency ($\text{TPOT}^\text{H}$) from $1.94\,\text{ms}$ to $0.40\,\text{ms}$ ($4.85\times$ speedup).
  • End-to-end speedup: Reduces full-model token latency from $7.69\,\text{ms}$ to $6.15\,\text{ms}$ ($1.25\times$) in BF16, and from $3.60\,\text{ms}$ to $2.06\,\text{ms}$ ($1.75\times$) when paired with an INT4 backbone.
  • Active Memory Footprint: Decreases active head parameters from $263\text{M}$ to $33\text{M}$ during decoding.
  • Broad Applicability: Yields consistent model-level speedups across Gemma-3-270M ($1.35\times$), Qwen-3-1.7B ($1.31\times$), and Llama-3.1-8B ($1.13\times$).

Limitations and Future Work

  • Lack of Closed-Form Probabilities: FlashHead does not output closed-form likelihoods over the complete vocabulary in a single pass. Evaluating perplexity or sequence log-likelihoods requires Monte Carlo sampling (roughly 10,000 samples to converge), which is slow for evaluation tasks like HellaSwag.
  • Batch Size 1 Focus: Evaluations target consumer edge devices with batch size 1. The authors note that scaling to high-throughput server workloads with large dynamic batching or speculative decoding remains open for future development.
  • Offline Clustering Overhead: Requires a one-time spherical $k$-means pass (~4 hours on an A40 GPU for a 128k vocabulary), though this is non-recurring and fast compared to pretraining or fine-tuning.

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, where the output head is viewing the output head as a retrieval problem rather than a dense computation. FlashHead introduces four key innovations: (1) equal-sized clustering of embeddings, (2) multi-probe retrieval to model heads, (3) a novel inference-time sampling mechanism, 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 1.75x while 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},
}

Loading related content...

Figure