Optimizing the LM Head in Large Language Models: Methods and Trade-offs

    This article explains where the LM head becomes a bottleneck in large language models, separating the theoretical softmax rank limitation from the practical costs of memory, bandwidth, and latency. It reviews actionable optimization methods—weight sharing and freezing, low-rank and structured decomposition, mixed and hierarchical outputs, vocabulary pruning, chunked computation, mixed precision, and inference caching—and offers guidance on choosing the right approach based on measurements.

    1. Define the Problem: Where the LM Head Actually Bottlenecks

    The LM head is the final linear projection after the Transformer backbone. It maps the last hidden state to logits over the vocabulary, which are then turned into a probability distribution by softmax. With a typical vocabulary of around one hundred thousand tokens and a hidden dimension in the thousands, this single layer can hold hundreds of millions of parameters, accounting for several percent of the total in small and medium-sized models. During training, it also materializes an intermediate tensor of batch size × sequence length × vocabulary size; for long contexts, this overhead can even exceed the size of the weights themselves.

    The key issue is that the word “bottleneck” is used with two different meanings. One is insufficient mathematical expressiveness: the model cannot represent certain real distributions. The other is that the model already contains the knowledge internally but fails to output it, which is hallucination. The two have different causes and require completely different optimization approaches; conflating them leads to choosing the wrong solution.

    2. The Softmax Bottleneck in the Mathematical Sense: Real but Rarely Bites

    Early theoretical work pointed out that the rank of the output log-probability matrix is bounded by the hidden dimension, while real language distributions are high-rank; the gap between them is the softmax bottleneck. The classic remedy is to mix multiple softmaxes to raise the rank, with later improvements based on sigmoid normalization and high-rank-plus-low-rank factorization.

    However, large-scale empirical studies give a milder conclusion: across many open-source models, the proportion of tokens that can “never be selected” is extremely low, and they appear so infrequently that they do not affect overall quality. In other words, the rank constraint is not the main issue in most engineering scenarios, and it is not worth paying a high cost to address it.

    3. The Bottleneck Worth Optimizing: Memory, Bandwidth, and Latency

    The more realistic pressure comes from the resource bill, which breaks down into four parts:

    1. Parameters and optimizer states: the output projection has a large parameter count, and training also requires gradients and momentum, multiplying memory usage.
    2. Activation materialization: the logits tensor grows linearly with batch size and sequence length, and is the main source of peak memory in long-context training.
    3. Reduction cost of the vocabulary softmax: full-vocabulary normalization consumes significant bandwidth with large vocabularies.
    4. Sampling and decoding: every step passes through the output layer, which is especially noticeable in latency-sensitive scenarios.

    4. Actionable Optimization Methods

    4.1 Weight Sharing and Freezing

    Sharing weights between the input embedding and the output projection can significantly reduce the parameter count. In downstream fine-tuning or speculative decoding setups, a common practice is to share and freeze the output layer as-is and train only the backbone, which saves memory and stabilizes training.

    4.2 Low-Rank and Structured Decomposition

    Factor the output matrix into low-rank factors or a block structure, approximating the original mapping with a small number of parameters. Combined with a sparse correction for the high-rank residual, this can reduce bandwidth with a controlled accuracy loss.

    4.3 Mixed and Hierarchical Outputs

    Split a single softmax into a mixture of sub-distributions, or switch to tree-based/hierarchical normalization, reducing complexity from linear to logarithmic. This is suitable for very large vocabularies.

    4.4 Vocabulary Pruning and Dynamic Candidates

    Prune low-frequency tokens by corpus frequency, or keep only a candidate subset at inference time before normalization. This reduces both memory and latency, at the cost of handling recall for the pruned tokens.

    4.5 Chunked Computation and Recomputation

    During training, compute logits in chunks over the sequence and aggregate the loss on the fly, avoiding materializing one huge tensor at once. Trading recomputation for memory is a common technique in long-context training.

    4.6 Mixed Precision and Operator Fusion

    The output layer is relatively sensitive to precision, so higher-precision accumulation is usually retained, while the projection, normalization, and sampling are fused into a few operators to reduce intermediate reads and writes.

    4.7 Inference-Oriented Caching and Batching

    Co-design the output layer computation with batch scheduling and caching strategies to avoid repeatedly consuming bandwidth with small batches.

    5. How to Choose

    If the goal is to reduce memory and training peaks, prioritize chunked computation, weight sharing, and low-rank decomposition. If the goal is inference latency, prioritize vocabulary pruning, hierarchical normalization, and operator fusion. If you do observe that the probabilities of certain tokens are persistently suppressed, then consider rank-raising approaches such as mixed outputs. The order of judgment should be measure first, then optimize: collect statistics on logits peaks, the share of time spent in the output layer, and the frequency of suppressed tokens, and let the data decide where to invest, rather than being led by claims about the “root cause of hallucination.”