Abstract
Standard Word2Vec implementations using the "Hogwild!" approach face significant scaling bottlenecks on multi-core processors due to memory contention on frequently accessed nodes in the Hierarchical Softmax Huffman tree. This paper proposes a lightweight caching strategy for these "hot" nodes, enabling local thread updates and periodic synchronization. Experimental results show up to a 4x speedup over standard implementations with no loss in model accuracy.
Introduction
Parallelizing Word2Vec training typically relies on the "Hogwild!" approach, where multiple threads update a shared model in memory without locks. While this works for sparse data, natural language follows a power-law distribution. In the Hierarchical Softmax (HS) variant, words are organized in a Huffman tree. Every update requires traversing a path from the root, making the root and its immediate children "hot" memory locations accessed by nearly every training sample.
This creates a massive bottleneck: concurrent attempts to read and update these specific memory locations increase latency, causing performance to plateau or degrade beyond 8–16 CPU cores.
The Proposed Caching Strategy
The authors introduce a straightforward caching mechanism for HS Word2Vec:
- Identify "Hot" Nodes: The most frequently used inner nodes near the Huffman tree root are identified.
- Local Caching: Each thread maintains a private copy of these high-frequency weight vectors.
- Batch Updates: Threads perform updates on their local cache instead of shared memory.
- Periodic Synchronization: After a small batch (10-100 words), cumulative changes are applied to shared memory using efficient BLAS functions like
saxpy.
This approach significantly reduces memory contention by minimizing the frequency of shared memory access for the most contested parameters.
Performance and Scalability
The implementation, dubbed Cythnn, was evaluated on the Text8 dataset. As shown in Figure 1, the original Word2Vec implementation (w2v) and Gensim see performance degradation or stagnation as the number of cores increases. In contrast, the cached version (c31) continues to scale effectively up to 24 cores.
The caching strategy achieved a 3.9x speedup over the original C implementation and a 2.5x speedup over Gensim. Crucially, this performance gain does not compromise accuracy; the cached version achieved a 33.57% score on word analogy tests, compared to 33.73% for the original version.
Impact of Cache Size
A key finding is that caching even a very small number of nodes provides substantial benefits. Caching just the root node improved efficiency by over 40% at high core counts. Figure 2 illustrates that the most significant gains occur when moving from 0 to 15 cached nodes, with diminishing returns thereafter.
Conclusion
By addressing the memory contention inherent in the Hierarchical Softmax tree structure, this caching strategy allows Word2Vec to scale efficiently on modern multi-core hardware. The approach is hardware-independent and provides a significant speedup while maintaining model quality. Future work may explore further optimizations for memory bandwidth limits, which remain a bottleneck at very high core counts.
Summary updated