Hash Layers For Large Sparse Models

Stephen Roller, Sainbayar Sukhbaatar, Arthur Szlam, Jason E Weston

Introduction

In Natural Language Processing (NLP), scaling up Transformer models reliably improves performance, but dense models eventually become too slow and expensive to train and evaluate. Mixture-of-Experts (MoE) models solve this by utilizing "conditional computation"—routing different tokens to a sparse subset of specialized neural network layers known as experts.

However, the routing mechanism itself is a major bottleneck. Existing state-of-the-art methods like Switch Transformers learn to route tokens based on their hidden states, requiring delicate load-balancing loss functions to prevent the network from sending all tokens to a single expert. Other methods like BASE Layers use complex linear assignment algorithms to force balanced routing. Both approaches add computational overhead, complicate the objective function, and can suffer from instability because the router is trying to learn assignments while the expert weights themselves are constantly shifting. This raises a fundamental question: Do we actually need to learn how to route?

The Hash Layer Approach

To address the complexities of learned routing, researchers propose Hash Layers, replacing learned routing with a deterministic, parameter-free hashing mechanism.

Illustration of the Hash Layer routing mechanism
  • The Core Idea: Instead of using a learned softmax over the hidden state to pick an expert, the model simply hashes the input token directly. For example, the word "taco" might always be routed to Expert 3.
  • Balanced Hashing: While a standard random hash works well for perplexity, it naturally creates hardware imbalances due to the Zipfian distribution of word frequencies in natural language. To fix this, the authors introduce a "Balanced Hash," which pre-computes a lookup table based on training data frequencies, greedily assigning the most frequent tokens to the emptiest expert buckets to ensure even computational load.
  • MultiHash Layers: Borrowing from traditional hashing literature, the method can also split the feedforward network (FFN) into $N$ segments and use $N$ different hash functions to route each segment independently, concatenating the results for a more expressive routing space without adding parameters.

Key Insights

  • Simplicity is Highly Competitive: A fixed, pre-computed routing assignment works just as well as, or better than, complex learned routing. Because researchers often only have the compute budget to train a massive model once, the robustness and lack of hyperparameters in Hash Layers make it highly attractive.
  • Disperse, Don't Cluster: The authors tested hashing based on k-means clusters of token embeddings (sending similar words to the same expert). Surprisingly, this hurt performance. It turns out it is better to disperse similar tokens across different experts so the model has more capacity to learn fine-grained distinctions between them.
  • Input Tokens over Hidden States: Routing based on the raw input token works better than routing on the hidden state. Hidden states are heavily biased toward the model's future predictions, which limits the router's ability to make optimal conditional compute decisions.
  • Specialize Later: Placing Hash Layers deeper in the network (later layers) yields better perplexity than placing them early. This suggests models should extract general, dense features first before applying specialized, sparse computation.

Key Results

The Hash Layer approach was evaluated across several datasets, including a 1.5 billion example Reddit dataset for dialogue generation and a massive ~100 billion token RoBERTa+cc100en corpus for language modeling.

Performance comparisons of Hash Layers against Switch and BASE models
  • Outperforms Switch Transformers: On the Reddit dataset (using 64 experts and 751M total parameters), the Hash Layer achieved a validation perplexity of 23.16, beating the Switch Transformer's 23.65.
  • Outperforms BASE Layers at Scale: In a 4.5 billion parameter setup on the RoBERTa+cc100en dataset, Hash Layers consistently outperformed BASE Layers in perplexity.
  • Faster Training: Because Hash Layers use pre-computed assignments, they avoid the expensive all-to-all communication steps required by BASE Layers to balance batches. This resulted in an ~11% increase in updates-per-second.
  • Multi-Hashing Works: Splitting a 32-expert layer into 8 independent hashes steadily improved perplexity (dropping from 23.58 with 1 hash to 23.28 with 8 hashes) without adding any parameters.

Limitations and Future Work

While the authors tested models up to 4.5 billion parameters, they acknowledge they did not test at the extreme "trillion-parameter" scales seen in industrial MoE papers. Furthermore, they do not claim that learned routing is a dead end. Instead, they argue that current learned routing methods aren't actually routing very well. Hash Layers serve as a robust, powerful baseline that any future learning-to-route algorithm must prove it can beat to justify its added complexity.

Summary updated

BibTeX
@inproceedings{roller2021hash,
  author = {Stephen Roller and Sainbayar Sukhbaatar and Arthur Szlam and Jason E Weston},
  title = {{Hash Layers For Large Sparse Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=lMgDDWb1ULW},
}
Figure