Introduction
N-gram language models (LMs) are essential components in natural language processing (NLP) pipelines, particularly for machine translation and speech recognition. However, as model sizes and query volumes grow, these models often become a computational bottleneck. While Graphics Processing Units (GPUs) offer significantly higher theoretical peak performance than CPUs, their architecture is not naturally suited for the branching and random memory access patterns typical of traditional N-gram lookups.
The Challenge of GPU-Based Search
Traditional CPU-based N-gram models utilize tries or hash tables that rely on heavy branching. On a GPU, these structures lead to "warp divergence" and uncoalesced memory accesses, causing the hardware to stall. To harness the raw power of GPUs, researchers from the University of Edinburgh developed gLM, a novel N-gram language model designed from the ground up for the Single Instruction, Multiple Threads (SIMT) architecture.
Methods: Parallel-Friendly Data Structures
The core innovation of gLM is the replacement of serial search algorithms with parallel-friendly alternatives:
- B-trees for K-ary Search: Instead of standard binary search, gLM uses B-trees to implement K-ary search. This allows a single GPU warp (32 threads) to compare a search key against multiple keys simultaneously, effectively making 32-way decisions in a single step.
- Coalesced Memory Access: B-tree nodes are arranged so that keys are stored contiguously. This ensures that when a warp reads a node, the GPU can perform a single "coalesced" read for all threads, maximizing memory bandwidth.
- Compact Pointer-less Layout: To fit large models into limited GPU VRAM, gLM uses a byte-array layout with relative offsets instead of 64-bit pointers. This allows the system to store large-scale models, such as a 423 million n-gram model, efficiently.
Evaluation and Results
The researchers compared gLM against KenLM, the industry-standard CPU baseline, using several datasets including a 5-gram Moses model and a large-scale 423 million n-gram model.
Key findings include:
- Throughput: gLM achieved 65.5 million queries per second, a sixfold increase over the single-threaded KenLM baseline (10.3 million queries/sec).
- Economic Efficiency: When fully utilized, gLM nearly doubled the performance-per-dollar compared to high-end CPU setups.
- Memory Footprint: Despite avoiding complex compression, gLM's memory usage (1.2 GB) was lower than KenLM’s probing hash table (1.8 GB) for the same model.
Conclusion
gLM demonstrates that by aligning data structures with hardware architecture, search-heavy NLP tasks can be effectively offloaded to GPUs. While the system requires batching to overcome data transfer overhead, it provides a powerful solution for high-throughput server-side processing. Future work aims to integrate the entire decoding pipeline onto the GPU to further minimize latency and maximize efficiency.
Summary updated