HierarchicalKV
repository·master·Indexed 42 days ago
https://github.com/nvidia-merlin/hierarchicalkvA high-performance key-value storage library for large-scale Recommender Systems (RecSys) and DLRMs. It optimizes memory by managing feature embeddings across GPU HBM and host memory using specialized CUDA kernels and eviction strategies such as LRU, LFU, and Epoch-based methods.
What's inside HierarchicalKV
- HierarchicalKV is a part of NVIDIA Merlin that provides hierarchical key-value storage designed for Recommender Systems (RecSys). It enables storing feature embeddings across both GPU High-Bandwidth Memory (HBM) and host memory simultaneously. This allows training large-scale models (DLRMs) that exceed the HBM capacity of a single GPU while bypassing CPUs to improve communication performance and reduce workload.
Overview of Merlin Key-Value Storage
masterMerlin Key-Value Storage is an open-source library designed for hierarchical key-value storage. It optimizes performance by utilizing both on-GPU high-bandwidth memory (HBM) and host RAM to manage data across different memory tiers.Core concepts of HierarchicalKV
masterHierarchicalKV operates based on several key architectural principles:
- Hybrid Storage: Stores keys in HBM and manages values across HBM and host memory.
- Separation of Concerns: Keys and values are stored separately.
- Local Ordering: Buckets are locally ordered.
- Eviction Management: Uses built-in or customizable eviction strategies implemented via CUDA kernels to manage HBM consumption.
- High Utilization: Designed to operate at a high working-status load factor close to 1.0.
Configure EvictStrategy for key importance
masterEviction occurs only when a bucket is full. The
score(typeuint64_t) defines the importance of a key: larger scores mean higher importance and a lower likelihood of eviction.Available strategies:
__Lru__: Uses device clock in nanoseconds.__Lfu__: Uses frequency increments provided by the caller via thescoresparameter ininsert-likeAPIs.__EpochLru__: Uses a combination of a caller-providedglobal_epoch(high 32 bits) and a device clock-based value (low 32 bits, granularity ~1ms).__EpochLfu__: Uses a caller-providedglobal_epoch(high 32 bits) and a frequency (low 32 bits) that caps at0xffffffff.__Customized__: The caller provides the full score via thescoresparameter ininsert-likeAPIs.
Note:
insert-likeAPIs includeinsert_or_assign,insert_and_evict,find_or_insert,accum_or_assign, andfind_or_insert. The caller is responsible for maintaining and providing theglobal_epochfor epoch-based strategies.Understand HierarchicalKV API Naming Conventions
masterWhen reviewing performance benchmarks or API documentation, note the following naming conventions for key operations:
find*andfind_or_insert*: These represent APIs that directly return the addresses of values, rather than copying them. This is a critical distinction for high-performance usage.insert_or_assign: Inserts a new key-value pair or updates the value if the key already exists.insert_and_evict: Inserts a value and triggers the eviction strategy (e.g., LRU) if capacity is reached.export_batch/export_batch_if: Batch operations for exporting data.contains: Checks for the existence of a key.
Add links to methods or headings with underscores
masterWhen creating links to a method or a heading that contains underscores, you must repeat the underscores in the link target, even though they are converted to hyphens in the final HTML output.
Examples:
- Linking to a heading with spaces and underscores:
../somefile.md#2heading-with-spaces-and_underscore_separated_words-too - Linking to a method with underscores:
./otherfile.md#save_params_to_files-method
- Linking to a heading with spaces and underscores:
Build HierarchicalKV with Bazel
masterTo build using Bazel, it is recommended to use a Docker container to ensure environment consistency.
Important Notes
- Do NOT use the
--recursiveflag when cloning the repository for Bazel builds. - If using customized Docker images, modify the environment variables in the
.bazelrcfile beforehand. - The
nvcr.io/nvidia/tensorflowimages are highly recommended.
Build Steps
- Pull and run the recommended TensorFlow Docker image:
docker pull nvcr.io/nvidia/tensorflow:22.09-tf2-py3 docker run --gpus all -it --rm nvcr.io/nvidia/tensorflow:22.09-tf2-py3 - Inside the container, clone the repository and run the provided build script:
git clone https://github.com/NVIDIA-Merlin/HierarchicalKV.git cd HierarchicalKV && bash bazel_build.sh
Running Benchmarks
- Benchmark:
./benchmark_util
docker pull nvcr.io/nvidia/tensorflow:22.09-tf2-py3 docker run --gpus all -it --rm nvcr.io/nvidia/tensorflow:22.09-tf2-py3 # Inside container git clone https://github.com/NVIDIA-Merlin/HierarchicalKV.git cd HierarchicalKV && bash bazel_build.sh- Do NOT use the
Build the HierarchicalKV documentation
masterTo build the documentation locally, you must install
doxygenand the Python dependencies specified indocs/requirements-doc.txt. The build process uses Doxygen, Breathe, and Exhale to generate API documentation from the C++ source code via Sphinx.- Install system dependencies:
sudo apt-get install doxygen - Install Python requirements:
pip install -r docs/requirements-doc.txt - Run the build command from the root of the repository:
make -C docs clean html
The output will be located at
docs/build/html/index.html.make -C docs clean html- Install system dependencies:
Build HierarchicalKV with CMake
masterHierarchicalKV is a header-only library. The build process primarily creates binaries for benchmarks and unit testing.
Prerequisites
- CUDA version >= 11.2
- NVIDIA GPU with compute capability 8.0, 8.6, 8.7, or 9.0
- GCC supporting
C++17or later - Bazel version >= 3.7.2 (if using Bazel)
Build Steps
- Clone the repository recursively:
git clone --recursive https://github.com/NVIDIA-Merlin/HierarchicalKV.git - Create a build directory and run CMake. Note that you must specify the compute capability using the
-Dsmflag (e.g.,-Dsm=80for Ampere architecture).
Running Benchmarks and Tests
After building, you can run the following binaries:
- Benchmark:
./merlin_hashtable_benchmark - Unit Test:
./merlin_hashtable_test
git clone --recursive https://github.com/NVIDIA-Merlin/HierarchicalKV.git cd HierarchicalKV && mkdir -p build && cd build cmake -DCMAKE_BUILD_TYPE=Release -Dsm=80 .. && make -jLink to files in the GitHub repository
masterIf you need to link to a file that is not part of the published documentation (such as
STYLE_GUIDE.md), provide the full URL to the file on GitHub so the reader knows they are leaving the documentation site.Example:
## Coding Style Refer to the [Style Guide](http://github.com/NVIDIA-Merlin/HierarchicalKV/STYLE_GUIDE.md) in the GitHub repository for more details.Preview built documentation locally
masterAfter building the documentation, you can preview the generated HTML files by running a local HTTP server. Run the following command from the root of the repository:
python -m http.server 8000 --directory docs/build/htmlThen, open your web browser and navigate to
http://localhost:8000.Link between documentation files
masterWhen linking between files within the documentation (e.g., from
README.mdto another section), use relative paths. Sphinx will automatically convert the.mdsuffix to.htmlduring rendering.Example:
To build HierarchicalKV from scratch, refer to [How to Build](./README.md#how-to-build) in the `README` file.