In the world of deep learning, recommendation systems are the heavyweights—literally. While a typical language model might fit on a few high-end GPUs, state-of-the-art recommendation models often reach terabytes in size. The culprit? Embedding tables. These tables map millions of categorical IDs (like user interests or movie genres) into dense vectors.
A new paper, "Learning to Collide: Recommendation System Model Compression with Learned Hash Functions," proposes a clever way to shrink these tables without losing the "soul" of the data.
TL;DR
Instead of using random hashing to shrink massive embedding tables—which causes "accidental" collisions between unrelated items—this paper introduces Learned Hash Functions. By training a tiny "teacher" model to find semantic similarities and incorporating access frequency, the authors create a mapping that intentionally collides similar items, maintaining higher model quality at a fraction of the original size.
What Problem Does This Paper Address?
Deep Learning Recommendation Models (DLRMs) rely on embedding tables to understand categorical features. These tables have two dimensions: width (the size of the vector) and height (the number of unique IDs). While width is easy to tune, height is a nightmare; if you have 100 million unique users, your table needs 100 million rows.
The industry standard for shrinking these tables is the "hashing trick": using a simple modulo operation to map many IDs to the same row. The problem? It’s random. You might end up forcing the model to use the same representation for "Action Movies" and "Cooking Tutorials." These "unconstructive collisions" degrade model accuracy (AUC), which, in the world of ads and ranking, translates directly to lost revenue.
Methods
The authors propose a multi-step pipeline to create "semantic collisions":
- The Teacher Model: They train a version of the model where the embedding dimension is drastically reduced (e.g., to just 2 or 4 dimensions). This "low-D" model is small enough to train easily but still learns which IDs are similar in a latent feature space.
- Agglomerative Clustering: They take these learned latent features and run a specialized 1D clustering algorithm. The goal is to group IDs that the teacher model thinks are similar.
- Frequency Integration: Real-world data follows a power-law distribution—some IDs appear millions of times, others only once. The authors prioritize merging low-frequency IDs (which are noisier) and use access counts to weight the "importance" of a cluster's position.
- Learned Mapping: The final output is a lookup table that acts as a hash function, ensuring that similar IDs "collide" into the same row of the compressed embedding table.
To make this practical, they implemented these custom lookups using the FBGEMM library, ensuring the compressed models still run efficiently on GPUs.
Datasets
The researchers used a production ads dataset consisting of eight consecutive days of data:
- Teacher Training: 750M random samples from days 1–7.
- Clustered Model Training: 1.5B samples from day 5.
- Evaluation: 150M samples from day 8.
- Scale: The original model size was O(100) GB, with the largest tables containing over 10 million rows.
Key Insights and Ideas
- Collisions are inevitable, so make them useful: The core philosophy is that if we must have collisions to save memory, we should choose which items collide based on their semantic meaning.
- Frequency is a Filter: Low-frequency IDs often have "random-looking" embeddings because the model hasn't seen them enough to learn a good representation. Merging these first prevents them from "polluting" the embeddings of high-frequency, high-value IDs.
- 1D is Enough: By projecting embeddings down to 1D and clustering, the authors kept the computational overhead of generating the hash function manageable even for tables with millions of entries.
- The "Small Table" Exception: They found that shrinking tables with fewer than 100k rows actually hurts quality more than it saves space. The biggest gains come from attacking the "long tail" of massive tables.
Key Results
- Superior to Random Hashing: The learned hash functions consistently outperformed the standard hashing trick, particularly when the model was compressed to 10–30% of its original size.
- Small but Mighty: While the improvement in Test AUC was small in absolute terms (~0.001), in the context of large-scale recommendation systems, even a 0.1% improvement is considered significant.
- Single vs. Multiple Tables: Interestingly, they found that using a single internal table with their learned mapping was more effective than "compositional embeddings" (using multiple smaller tables to represent one ID) when combined with their clustering approach.
Limitations and Future Work
- The "Zero-Loss" Gap: The authors admit that while their method is better than random hashing, it still results in some quality degradation compared to the full-sized model. They haven't yet found a "silver bullet" for lossless compression.
- Static vs. Dynamic: The current approach requires training a teacher model on historical data. If the data distribution shifts rapidly (e.g., a new viral trend), the learned hash functions might become stale.
- Complexity: Implementing learned hash functions is more complex than a simple
ID % sizeoperation, requiring a two-stage training process and specialized GPU kernels.
For engineers looking to squeeze a terabyte-scale model onto a cluster of 80GB A100s, this research provides a promising roadmap: stop hashing randomly and start learning how to collide.
Summary updated