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

Overlap KV cache update for WindowedKeyValueCache in DecoderOnlyPipelineState #1222

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

edgchen1
Copy link
Contributor

@edgchen1 edgchen1 commented Feb 4, 2025

Add support for overlapping the KV cache update for a pipelined model part with the graph execution of other pipelined model parts. It only applies to DecoderOnlyPipelineState with WindowedKeyValueCache.

For example, consider a model with two parts (graph[1] and graph[2]) that have KV caches.

This is the approach in this PR:

iter 1 graph[1] run | -
iter 1 graph[2] run | iter 1 graph[1] KV cache update
iter 2 graph[1] run | iter 1 graph[2] KV cache update
iter 2 graph[2] run | iter 2 graph[1] KV cache update
iter 3 graph[1] run | iter 2 graph[2] KV cache update

For comparison, this is the existing approach:

iter 1 graph[1] run
iter 1 graph[2] run
iter 1 graph[1] KV cache update
iter 1 graph[2] KV cache update
iter 2 graph[1] run
iter 2 graph[2] run
iter 2 graph[1] KV cache update
iter 2 graph[2] KV cache update

TODO measurements

@@ -100,39 +101,7 @@ struct CrossCache {
std::vector<std::string> input_name_strings_, output_name_strings_;
};

struct WindowedKeyValueCache : KeyValueCache {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: moved WindowedKeyValueCache to windowed_kv_cache.h/cpp

@@ -23,7 +18,7 @@ target_include_directories(unit_tests PRIVATE
target_link_directories(unit_tests PRIVATE ${ORT_LIB_DIR})
target_link_libraries(unit_tests PRIVATE
onnxruntime-genai-static
GTest::gtest_main
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: there's already a main in test/main.cpp so we don't need one from gtest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant