-
Notifications
You must be signed in to change notification settings - Fork 261
Propagate global --cache_dir to continuous batching pipeline (#4230) #4329
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
Open
exzile
wants to merge
2
commits into
openvinotoolkit:main
Choose a base branch
from
exzile:fix/cache-dir-continuous-batching
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+213
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ | |
| #endif | ||
|
|
||
| #include "../../http_rest_api_handler.hpp" | ||
| #include "../../config.hpp" | ||
| #include "../../http_status_code.hpp" | ||
| #include "../../json_parser.hpp" | ||
| #include "../../llm/apis/openai_completions.hpp" | ||
|
|
@@ -4425,6 +4426,201 @@ TEST_F(LLMVLMOptionsHttpTest, LLMVLMNodeOptionsCheckPluginConfig) { | |
| LLMNodeOptionsCheckPluginConfig(modelsPath); | ||
| } | ||
|
|
||
| // Verifies that the global --cache_dir (ServerSettings) is propagated into the | ||
| // continuous batching pipeline plugin config, and that an explicit CACHE_DIR in | ||
| // the node's plugin_config takes precedence over the global value. | ||
| // Regression test for openvinotoolkit/model_server#4230. | ||
| void LLMNodeOptionsCacheDirPropagation(std::string& modelsPath) { | ||
| // Seed the global cache_dir via the CLI parser (same path used in production). | ||
| char* n_argv[] = {(char*)"ovms", (char*)"--model_path", (char*)"/path/to/model", (char*)"--model_name", (char*)"some_name", (char*)"--rest_port", (char*)"8080", (char*)"--cache_dir", (char*)"/tmp/ovms_global_cache"}; | ||
| int arg_count = 9; | ||
| ovms::Config::instance().parse(arg_count, n_argv); | ||
| ASSERT_EQ(ovms::Config::instance().cacheDir(), "/tmp/ovms_global_cache"); | ||
|
|
||
| // Case 1: no CACHE_DIR in node plugin_config -> global value is applied. | ||
| { | ||
| std::string testPbtxt = R"( | ||
| input_stream: "HTTP_REQUEST_PAYLOAD:input" | ||
| output_stream: "HTTP_RESPONSE_PAYLOAD:output" | ||
|
|
||
| node: { | ||
| name: "llmNode" | ||
| calculator: "HttpLLMCalculator" | ||
| input_stream: "LOOPBACK:loopback" | ||
| input_stream: "HTTP_REQUEST_PAYLOAD:input" | ||
| input_side_packet: "LLM_NODE_RESOURCES:llm" | ||
| output_stream: "LOOPBACK:loopback" | ||
| output_stream: "HTTP_RESPONSE_PAYLOAD:output" | ||
| input_stream_info: { | ||
| tag_index: 'LOOPBACK:0', | ||
| back_edge: true | ||
| } | ||
| node_options: { | ||
| [type.googleapis.com / mediapipe.LLMCalculatorOptions]: { | ||
| models_path: ")" + | ||
| modelsPath + R"(" | ||
| } | ||
| } | ||
| input_stream_handler { | ||
| input_stream_handler: "SyncSetInputStreamHandler", | ||
| options { | ||
| [mediapipe.SyncSetInputStreamHandlerOptions.ext] { | ||
| sync_set { | ||
| tag_index: "LOOPBACK:0" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| )"; | ||
| adjustConfigForTargetPlatform(testPbtxt); | ||
| ::mediapipe::CalculatorGraphConfig config; | ||
| ASSERT_TRUE(::google::protobuf::TextFormat::ParseFromString(testPbtxt, &config)); | ||
| std::shared_ptr<GenAiServable> servable; | ||
| ASSERT_EQ(initializeGenAiServable(servable, config.node(0), ""), StatusCode::OK); | ||
| auto properties = std::static_pointer_cast<ContinuousBatchingServableProperties>(servable->getProperties()); | ||
| ASSERT_EQ(properties->pluginConfig.count("CACHE_DIR"), 1); | ||
| ASSERT_EQ(properties->pluginConfig["CACHE_DIR"].as<std::string>(), "/tmp/ovms_global_cache"); | ||
| } | ||
|
|
||
| // Case 2: explicit CACHE_DIR in node plugin_config wins over the global value. | ||
| { | ||
| std::string testPbtxt = R"( | ||
| input_stream: "HTTP_REQUEST_PAYLOAD:input" | ||
| output_stream: "HTTP_RESPONSE_PAYLOAD:output" | ||
|
|
||
| node: { | ||
| name: "llmNode" | ||
| calculator: "HttpLLMCalculator" | ||
| input_stream: "LOOPBACK:loopback" | ||
| input_stream: "HTTP_REQUEST_PAYLOAD:input" | ||
| input_side_packet: "LLM_NODE_RESOURCES:llm" | ||
| output_stream: "LOOPBACK:loopback" | ||
| output_stream: "HTTP_RESPONSE_PAYLOAD:output" | ||
| input_stream_info: { | ||
| tag_index: 'LOOPBACK:0', | ||
| back_edge: true | ||
| } | ||
| node_options: { | ||
| [type.googleapis.com / mediapipe.LLMCalculatorOptions]: { | ||
| models_path: ")" + | ||
| modelsPath + R"(" | ||
| plugin_config: '{"CACHE_DIR": "/tmp/ovms_node_cache"}' | ||
| } | ||
| } | ||
| input_stream_handler { | ||
| input_stream_handler: "SyncSetInputStreamHandler", | ||
| options { | ||
| [mediapipe.SyncSetInputStreamHandlerOptions.ext] { | ||
| sync_set { | ||
| tag_index: "LOOPBACK:0" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| )"; | ||
| adjustConfigForTargetPlatform(testPbtxt); | ||
| ::mediapipe::CalculatorGraphConfig config; | ||
| ASSERT_TRUE(::google::protobuf::TextFormat::ParseFromString(testPbtxt, &config)); | ||
| std::shared_ptr<GenAiServable> servable; | ||
| ASSERT_EQ(initializeGenAiServable(servable, config.node(0), ""), StatusCode::OK); | ||
| auto properties = std::static_pointer_cast<ContinuousBatchingServableProperties>(servable->getProperties()); | ||
| ASSERT_EQ(properties->pluginConfig.count("CACHE_DIR"), 1); | ||
| // The test harness may rewrite the path for the target platform, so match | ||
| // on substrings: the explicit node value must win over the global one. | ||
| std::string nodeCacheDir = properties->pluginConfig["CACHE_DIR"].as<std::string>(); | ||
| ASSERT_NE(nodeCacheDir.find("ovms_node_cache"), std::string::npos) << "Explicit node CACHE_DIR should be used, got: " << nodeCacheDir; | ||
| ASSERT_EQ(nodeCacheDir.find("ovms_global_cache"), std::string::npos) << "Global cache_dir must not override explicit node CACHE_DIR, got: " << nodeCacheDir; | ||
| } | ||
|
|
||
| // Restore the global cache_dir so the singleton does not leak into other tests. | ||
| char* reset_argv[] = {(char*)"ovms", (char*)"--model_path", (char*)"/path/to/model", (char*)"--model_name", (char*)"some_name", (char*)"--rest_port", (char*)"8080"}; | ||
| ovms::Config::instance().parse(7, reset_argv); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we probably need this restore also after any ASSERT in this suite. check how other tests do that via guard patter or SetUp/TearDown mechanic (some tests recover env variables this way) |
||
| } | ||
| TEST_F(LLMOptionsHttpTest, LLMNodeOptionsCacheDirPropagation) { | ||
| LLMNodeOptionsCacheDirPropagation(modelsPath); | ||
| } | ||
| TEST_F(LLMVLMOptionsHttpTest, LLMVLMNodeOptionsCacheDirPropagation) { | ||
| LLMNodeOptionsCacheDirPropagation(modelsPath); | ||
| } | ||
|
|
||
| // End-to-end regression test for #4230: LLMNodeOptionsCacheDirPropagation above only | ||
| // verifies that --cache_dir lands in properties->pluginConfig; it does not prove that | ||
| // OpenVINO Core actually persists compiled-model cache artifacts, which was the crux of | ||
| // the original bug report (log said "cache enabled", nothing was ever written on disk). | ||
| // This test constructs a real ContinuousBatchingPipeline against --cache_dir and asserts | ||
| // that compiled-model cache artifacts actually land under it. | ||
| TEST_F(LLMOptionsHttpTest, LLMNodeOptionsCacheDirWritesCacheArtifacts) { | ||
| std::string cacheDir = std::filesystem::temp_directory_path().string() + | ||
| "/LLMNodeOptionsCacheDirWritesCacheArtifacts_" + | ||
| ::testing::UnitTest::GetInstance()->current_test_info()->name(); | ||
| std::filesystem::remove_all(cacheDir); | ||
| std::filesystem::create_directories(cacheDir); | ||
|
|
||
| // Seed the global cache_dir via the CLI parser (same path used in production). | ||
| char* n_argv[] = {(char*)"ovms", (char*)"--model_path", (char*)"/path/to/model", (char*)"--model_name", (char*)"some_name", (char*)"--rest_port", (char*)"8080", (char*)"--cache_dir", (char*)cacheDir.c_str()}; | ||
| int arg_count = 9; | ||
| ovms::Config::instance().parse(arg_count, n_argv); | ||
| ASSERT_EQ(ovms::Config::instance().cacheDir(), cacheDir); | ||
|
|
||
| std::string testPbtxt = R"( | ||
| input_stream: "HTTP_REQUEST_PAYLOAD:input" | ||
| output_stream: "HTTP_RESPONSE_PAYLOAD:output" | ||
|
|
||
| node: { | ||
| name: "llmNode" | ||
| calculator: "HttpLLMCalculator" | ||
| input_stream: "LOOPBACK:loopback" | ||
| input_stream: "HTTP_REQUEST_PAYLOAD:input" | ||
| input_side_packet: "LLM_NODE_RESOURCES:llm" | ||
| output_stream: "LOOPBACK:loopback" | ||
| output_stream: "HTTP_RESPONSE_PAYLOAD:output" | ||
| input_stream_info: { | ||
| tag_index: 'LOOPBACK:0', | ||
| back_edge: true | ||
| } | ||
| node_options: { | ||
| [type.googleapis.com / mediapipe.LLMCalculatorOptions]: { | ||
| models_path: ")" + | ||
| modelsPath + R"(" | ||
| } | ||
| } | ||
| input_stream_handler { | ||
| input_stream_handler: "SyncSetInputStreamHandler", | ||
| options { | ||
| [mediapipe.SyncSetInputStreamHandlerOptions.ext] { | ||
| sync_set { | ||
| tag_index: "LOOPBACK:0" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| )"; | ||
| adjustConfigForTargetPlatform(testPbtxt); | ||
| ::mediapipe::CalculatorGraphConfig config; | ||
| ASSERT_TRUE(::google::protobuf::TextFormat::ParseFromString(testPbtxt, &config)); | ||
| std::shared_ptr<GenAiServable> servable; | ||
| ASSERT_EQ(initializeGenAiServable(servable, config.node(0), ""), StatusCode::OK); | ||
|
|
||
| bool foundCacheArtifact = false; | ||
| for (const auto& entry : std::filesystem::recursive_directory_iterator(cacheDir)) { | ||
| if (entry.is_regular_file()) { | ||
| foundCacheArtifact = true; | ||
| break; | ||
| } | ||
| } | ||
| EXPECT_TRUE(foundCacheArtifact) | ||
| << "Expected compiled-model cache artifacts under --cache_dir after constructing the " | ||
| << "continuous batching pipeline, found none in: " << cacheDir; | ||
|
|
||
| // Restore the global cache_dir so the singleton does not leak into other tests. | ||
| char* reset_argv[] = {(char*)"ovms", (char*)"--model_path", (char*)"/path/to/model", (char*)"--model_name", (char*)"some_name", (char*)"--rest_port", (char*)"8080"}; | ||
| ovms::Config::instance().parse(7, reset_argv); | ||
| std::filesystem::remove_all(cacheDir); | ||
| } | ||
|
|
||
| void LLMNodeOptionsCheckNonDefault(std::string& modelsPath) { | ||
| std::string testPbtxt = R"( | ||
| input_stream: "HTTP_REQUEST_PAYLOAD:input" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes it for language_model + continuous_batching
what about:
?