TL;DR
Transformer-based sequential recommendation models achieve state-of-the-art results but struggle to scale to production catalogs containing millions of items due to slow inference speeds. This paper demonstrates that by restructuring the scoring loop of Product Quantization (PQ) compressed models using an algorithm called PQTopK, inference can be highly parallelized on CPU-only hardware. This approach yields up to a 4.5× total inference speedup on a million-item dataset without sacrificing any recommendation accuracy.
What Problem Does This Paper Address?
Modern sequential recommender systems like SASRec and BERT4Rec model user behavior using Transformer architectures, treating the next-item prediction task similarly to next-token prediction in Large Language Models (LLMs). However, while LLM vocabularies rarely exceed a few hundred thousand tokens, e-commerce platforms like Amazon manage catalogs with hundreds of millions of items.
This massive scale introduces severe bottlenecks:
- Memory Consumption: Storing explicit embedding matrices for millions of items quickly exhausts GPU memory.
- Inference Latency: Computing final recommendation scores requires multiplying the user's sequence representation by every single item embedding. This linear complexity ($O(|I| \times d)$) makes real-time, exhaustive scoring practically impossible on standard hardware.
While recent compression techniques like RecJPQ successfully reduce the memory footprint by decomposing item IDs into shared sub-IDs, they fail to improve inference speed. This paper tackles the inference bottleneck, specifically focusing on making exhaustive item scoring efficient on cost-effective, CPU-only production environments.
Methods
The authors leverage Product Quantization (PQ), where an item's embedding is reconstructed by concatenating smaller sub-embeddings from multiple codebook "splits."
The core innovation lies in how the final item scores are calculated. In the original RecJPQ implementation, the algorithm iterates through each split and iteratively accumulates scores for all items. Because of this sequential accumulation, the outer loop cannot be parallelized.
The authors introduce PQTopK, which flips this logic:
- Precomputation: It first computes a small sub-id score matrix ($S$) by taking the dot product of the user's sequence sub-embeddings and the codebook sub-embeddings.
- Parallelized Summation: It then iterates through the items, simply summing the precomputed sub-scores. Because the score calculation for each item is entirely independent, the entire item loop can be fully parallelized using modern accelerated computing frameworks like TensorFlow.
Datasets
The approach was evaluated using both real-world and simulated datasets:
- Booking.com: A smaller dataset containing 140,746 users and 34,742 items.
- Gowalla: A large-scale location-based social network dataset containing 86,168 users and 1,271,638 items.
- Simulated Data: Synthetic catalogs scaling from $10^4$ up to $10^9$ (1 billion) items to stress-test the limits of the algorithm.
Key Insights and Ideas
- Loop Order Matters: The primary bottleneck in prior sub-ID recommendation work wasn't the mathematical complexity, but the loop architecture. Swapping the loop order to eliminate iterative score accumulation unlocked massive parallelization capabilities.
- Decoupling the Backbone: The inference time of the Transformer backbone remains constant regardless of catalog size. The bottleneck is entirely isolated within the final scoring head, meaning optimization efforts are best spent there rather than altering the core Transformer layers.
- Safe vs. Unsafe Retrieval: Unlike Approximate Nearest Neighbor (ANN) search methods (e.g., FAISS), which speed up inference by skipping items risking false negatives, PQTopK performs exhaustive scoring. It guarantees exact mathematical parity with the base model's outputs.
Key Results
The experiments were conducted on a CPU-only setup (AMD Ryzen 5950x) to simulate low-cost production deployments:
- Gowalla Speedups: On the million-item Gowalla dataset, PQTopK-enhanced SASRec achieved a 4.5× total speedup compared to the default SASRec matrix-multiplication method, and a 1.56× speedup over the original RecJPQ scoring method.
- Scoring Isolation: When isolating just the time spent scoring items (excluding the Transformer backbone), PQTopK was 13× faster than the default Transformer scoring head and 3× faster than RecJPQ.
- Extreme Scaling: Using simulated data with a practical number of splits ($m=8$), PQTopK maintained sub-second latencies for catalogs containing up to 100 million items, whereas standard matrix multiplication completely exhausted the system's 128GB of RAM past 10 million items.
Limitations and Future Work
While PQTopK scales remarkably well, performance degrades if the number of quantization splits ($m$) is set too high. For instance, at $m=64$, the overhead of the algorithm matches standard matrix multiplication, though it still retains its massive memory-saving advantages.
Additionally, for ultra-large catalogs approaching 1 billion items, the inference latency exceeds 10 seconds per user. At this scale, the authors note that the method is no longer suitable for real-time interactive serving and must be relegated to offline, batch pre-computation scenarios. Future work could explore combining PQTopK with safe candidate pruning techniques to bridge this gap.
Summary updated