Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kv state cache module. #1777

Merged
merged 20 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8f76778
Support kv state cache for llm using vineyard (#1720)
vegetableysm Jan 22, 2024
d2e6803
Improve the split logic and implement the serialization and deseriali…
dashanji Jan 26, 2024
79f68de
Refactor code of radix split subtree and fix bug of radix split. (#1735)
vegetableysm Jan 26, 2024
b570466
Support merge tree / merge object / bug fix. (#1738)
vegetableysm Feb 1, 2024
32ad9f1
Support merge cache object with radix tree. (#1741)
vegetableysm Feb 2, 2024
024dc1e
Replace lz4 with zstd (#1744)
dashanji Feb 4, 2024
03d6325
Recycle resources of kv state cache object. (#1748)
vegetableysm Feb 5, 2024
5065f3b
Add the unit test for the radix tree. (#1749)
dashanji Feb 5, 2024
e7fafc8
Fix the bug in the radix split logic. (#1751)
dashanji Feb 5, 2024
17be7a9
Support layer for kv state cache (#1766)
vegetableysm Feb 22, 2024
26cef28
Support to store more than 64 entries for kv cache block (#1769)
vegetableysm Feb 26, 2024
6ecf15c
Add ci test for kv state cache and fix bug (#1772)
vegetableysm Feb 27, 2024
44d7c00
Disable code formatting of radix tree and fix a bug of serialization …
dashanji Feb 28, 2024
9f6a64e
Add a benchmark test for kv state cache (#1774)
dashanji Feb 28, 2024
7bdffc6
Add the rax linsence and fix a warning (#1778)
dashanji Feb 28, 2024
5c12567
Clean code.
vegetableysm Feb 28, 2024
24c241e
Move llm tests to llm-cache directory
vegetableysm Feb 28, 2024
61a77c7
Use nano second as timestamp
vegetableysm Feb 29, 2024
2acff41
Refactor kv state cache utils api.
vegetableysm Feb 29, 2024
3fb2376
Move the radix tree to the thirdparty and update the type of kv_state…
dashanji Feb 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@ jobs:
if: false
uses: mxschmitt/action-tmate@v3

- name: Run llm tests
run: |
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib64:/usr/local/lib/x86_64-linux-gnu
export VINEYARD_DATA_DIR=`pwd`/gstest
export TMPDIR="${TMPDIR:-$(dirname $(mktemp))}"

rm -rf default.etcd
rm -rf /dev/shm/etcd*
python3 test/runner.py $RUNNER_ARGS --with-llm

- name: Run cpp tests
run: |
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib64:/usr/local/lib/x86_64-linux-gnu
Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ option(BUILD_VINEYARD_MALLOC_OVERRIDE "Using the client-side malloc to override
option(BUILD_VINEYARD_FUSE "Enable vineyard's fuse support" OFF)
option(BUILD_VINEYARD_FUSE_PARQUET "Enable vineyard's fuse parquet support" OFF)
option(BUILD_VINEYARD_HOSSEINMOEIN_DATAFRAME "Enable hosseinmoein dataframe support" OFF)
option(BUILD_VINEYARD_LLM_CACHE "Enable kv-state cache support" ON)

option(BUILD_VINEYARD_TESTS "Generate make targets for vineyard tests" ON)
option(BUILD_VINEYARD_TESTS_ALL "Include make targets for vineyard tests to ALL" OFF)
Expand Down Expand Up @@ -932,6 +933,11 @@ if(BUILD_VINEYARD_HOSSEINMOEIN_DATAFRAME)
list(APPEND VINEYARD_INSTALL_LIBS vineyard_hosseinmoein_dataframe)
endif()

if(BUILD_VINEYARD_LLM_CACHE)
add_subdirectory(modules/llm-cache)
list(APPEND VINEYARD_INSTALL_LIBS vineyard_llm_cache)
endif()

if(BUILD_VINEYARD_TESTS)
add_subdirectory(test)
endif()
Expand Down Expand Up @@ -975,7 +981,7 @@ endfunction()

file_glob_recurse(FILES_NEED_FORMAT DIRECTORIES "src" "modules" "python" "test" "benchmark"
PATTERNS ".*\\.(cc|cpp|h|hpp|vineyard-mod)$"
EXCLUDE_PATTERNS ".*\\.vineyard.h$"
EXCLUDE_PATTERNS "(.*\\.vineyard.h$)"
)

# the `memcpy.h` is borrowed from external project
Expand Down
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -1181,3 +1181,18 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

-------------------------------------------------------------------------------

The files thirdparty/rax/{radix.cc, radix.h, rax_malloc} is referred from project antirez/rax,
which has the following license:

Copyright (c) 2017, Salvatore Sanfilippo <[email protected]>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 4 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ This product includes software from the ClickHouse project
This product includes software from the BBHash project
* Copyright (c) 2015 Guillaume Rizk
* https://github.com/rizkg/BBHash

This product includes software from the rax project (BSD, 2-clause)
* Copyright (c) 2017-2019, Salvatore Sanfilippo <antirez at gmail dot com>
* https://github.com/antirez/rax
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ We thank the following excellent open-source projects:
- `skywalking-swck <https://github.com/apache/skywalking-swck>`_ A kubernetes operator for the Apache Skywalking.
- `wyhash <https://github.com/alainesp/wy>`_, C++ wrapper around wyhash and wyrand.
- `BBHash <https://github.com/rizkg/BBHash>`_, a fast, minimal-memory perfect hash function.
- `rax <https://github.com/antirez/rax>`_, an ANSI C radix tree implementation.

License
-------
Expand Down
17 changes: 17 additions & 0 deletions modules/llm-cache/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
file(GLOB VINEYARD_LLM_CACHE_SRCS "${CMAKE_CURRENT_SOURCE_DIR}"
"ds/*.cc"
"ds/*.h"
"radix-tree/*.cc"
"radix-tree/*.h"
"${PROJECT_SOURCE_DIR}/thirdparty/rax/*.cc"
"${PROJECT_SOURCE_DIR}/thirdparty/rax/*.h"
)

add_library(vineyard_llm_cache ${VINEYARD_LLM_CACHE_SRCS})
target_link_libraries(vineyard_llm_cache PUBLIC vineyard_client vineyard_basic)

install_export_vineyard_target(vineyard_llm_cache)
install_vineyard_headers("${CMAKE_CURRENT_SOURCE_DIR}/ds/")
install_vineyard_headers("${CMAKE_CURRENT_SOURCE_DIR}/radix-tree/")

add_subdirectory(tests)
27 changes: 27 additions & 0 deletions modules/llm-cache/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
KV-state cache on Vineyard
=============================

Run test
--------

Build vineyard and vineyard test

.. code:: bash
mkdir build
cd build
cmake .. -DBUILD_VINEYARD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug
make -j$(nproc)
make vineyard_tests -j$(nproc)

Start vineyard server

.. code:: bash
cd build
./bin/vineyardd --socket=/tmp/vineyard_test.sock # make sure the env VINEYARD_IPC_SOCKET is set properly

Run test

.. code:: bash
cd build
export VINEYARD_IPC_SOCKET=/tmp/vineyard_test.sock
./bin/kv_state_cache_test
Loading
Loading