Optimizing the LM Head in Large Language Models: Methods and Real Bottlenecks
This article breaks down the two distinct bottlenecks often attributed to a large language model's LM head: the mathematical softmax rank bottleneck and the engineering resource bottleneck. It explains why the rank limitation is real in theory but rarely affects model quality in practice, then focuses on the four engineering costs worth optimizing—logits materialization and memory peaks, vocabulary size, parameters and bandwidth, and inference latency—along with concrete techniques, a method-selection comparison, and a practical checklist.
1. Defining the Problem: What the LM Head Actually Does
The LM head is the single linear projection that follows the Transformer backbone: it maps the final hidden state to logits over the vocabulary dimension, and a softmax then turns those logits into a probability distribution.
# Illustrative: a single output projectionlogits = h @ W_out.T # h: [batch*seq, d] -> logits: [batch*seq, V]probs = softmax(logits) # for sampling or argmax
Take a mainstream configuration as an example: a vocabulary of roughly 128K and a hidden dimension of 4096 gives an output weight of about 524 million parameters. In a model on the order of 8 billion parameters, this single output projection alone accounts for more than 6%. Training makes things harder: the logits must be materialized as a [batch*seq, V] tensor, and once long context is enabled, this intermediate activation often consumes more memory than the weights themselves.
The key point is that the word “bottleneck” has been stretched to cover two completely different meanings:
- A mathematical expressiveness bottleneck: the set of distributions the model can represent is limited (a rank problem);
- An engineering resource bottleneck: memory, bandwidth, latency, and cost (a cost problem);
- And a third one that often gets wrongly attached: the model “knows but doesn’t say,” i.e., the hallucination problem.
2. The Mathematical Half: The Softmax Rank Bottleneck Is Real but Rarely Bites
The theory traces back to 2017 work on breaking the softmax bottleneck: the output log-probability matrix can be written as the product of the hidden-state matrix and the transpose of the vocabulary embedding matrix, so its rank is capped at min(N, d, V) = d; real language log-probability matrices are high-rank, and the gap between the two is the softmax bottleneck. Follow-up research offers several routes: mixing multiple softmaxes to raise the rank, re-analyzing the bottleneck with a redesigned normalization function, reducing overhead via a “high-rank + low-rank” decomposition, and empirically demonstrating that this bottleneck limits the ability to model multi-modal token distributions.
But the empirical conclusion is equally clear: in a systematic study of about 150 open-source models, only 13 actually had tokens that could “never be selected,” and those tokens appear with extremely low frequency—not enough to affect overall quality. In other words, the rank bottleneck is mathematically valid but essentially harmless in engineering. The second class of bottleneck is what truly deserves investment.
One common misconception is worth correcting along the way: the draft module in speculative decoding is not a “latent-space probing head.” Its typical handling of the output layer is to share it as-is and freeze it, so it does not participate in training updates.
3. The Engineering Half: Four Categories of Cost Worth Optimizing
1. Memory Peak: Logits Materialization
During training, [batch*seq, V] is the main driver of the peak. Viable approaches:
- Compute logits and loss in chunks, reducing as you go without materializing the full tensor;
- Use a fused output-projection + cross-entropy operator to avoid the intermediate tensor;
- Apply sequence parallelism / tensor parallelism over long sequences, spreading either the V dimension or the seq dimension.
# Illustrative: chunked cross-entropy, avoiding full logits materializationloss = 0.0for chunk in h.split(chunk_size, dim=0):lg = chunk @ W_out.Tloss += cross_entropy(lg, target_chunk) * chunk.size(0)loss /= total_tokens
2. Vocabulary Size: Pruning, Hierarchy, and Sampling
- Frequency pruning: fold or map extremely low-frequency tokens to a fallback symbol, directly shrinking V;
- Hierarchical / chunked sampling: group at a coarse level first, then refine within each group, splitting one large softmax into two smaller ones;
- Negative-sampling objectives: in small-vocabulary or incremental-training scenarios, use sampling approximations instead of full normalization (watch for the bias relative to full softmax).
3. Parameters and Bandwidth: Low-Rank, Sharing, and Quantization
- Low-rank output:
W_out ≈ A·B, trading rank r for fewer parameters and less bandwidth; - Weight sharing: share one matrix between the input embedding and the output projection to save parameters significantly (the benefit is more pronounced when the vocabulary is large and d is small);
- Low-bit: on the inference side, apply low-bit quantization to the output weights to reduce memory access; note that logits and normalization are best kept at higher precision.
4. Inference Latency: Compute Only What You Need
Autoregressive decoding needs logits only for the last position at each step, whereas training needs the full sequence. Engineering practice should strictly separate the two paths to avoid paying training-level compute and memory costs during inference; in batching scenarios, group requests by length to reduce wasted alignment.
4. Method Selection at a Glance
| Goal | Preferred Approach | Main Cost |
|---|---|---|
| Reduce memory peak | Chunked/fused output loss, sequence parallelism | Implementation complexity, communication overhead |
| Reduce parameters | Embedding-output sharing, low-rank decomposition | Slight loss of expressiveness, needs validation |
| Reduce vocabulary | Frequency pruning, hierarchical softmax | Coverage and OOV strategy |
| Reduce latency | Compute only last-position logits, batch grouping | Scheduling complexity |
| Improve theoretical expressiveness | Mixed softmax | Higher training and inference cost, limited gains |
5. Deployment Checklist
- Measure first: tally the output layer’s parameter share, peak logits memory, and last-position decoding time;
- Then localize: distinguish whether you’re facing a rank bottleneck or a resource bottleneck—the former is usually not worth the investment;
- Validate in small steps: change one variable at a time and align quality against a fixed evaluation set;
- Precision fallback: keep normalization and sampling at high precision, and apply quantization only to weights and activations;
- Keep boundaries clear: decouple output-layer optimization from draft-style speculative decoding to avoid conflating concepts.
The conclusion is straightforward: the claim that the LM head is the “root cause of hallucination” is heavily overstated, and the rank bottleneck is almost never a quality constraint in real models; meanwhile, its memory and compute bill is definitely real. Optimizing the four cost categories above, one by one, is the path with the best return on investment.
