-
Notifications
You must be signed in to change notification settings - Fork 238
Prefix caching for NPU in nested plugin config structure #3929
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -448,7 +448,6 @@ def export_text_generation_model(model_repository_path, source_model, model_name | |||||||||
| raise ValueError("max_prompt_len is only supported for NPU target device") | ||||||||||
| if task_parameters['max_prompt_len'] <= 0: | ||||||||||
| raise ValueError("max_prompt_len should be a positive integer") | ||||||||||
| plugin_config['MAX_PROMPT_LEN'] = task_parameters['max_prompt_len'] | ||||||||||
| if task_parameters['ov_cache_dir'] is not None: | ||||||||||
| plugin_config['CACHE_DIR'] = task_parameters['ov_cache_dir'] | ||||||||||
|
|
||||||||||
|
|
@@ -459,6 +458,17 @@ def export_text_generation_model(model_repository_path, source_model, model_name | |||||||||
| if "HETERO" in task_parameters['target_device']: | ||||||||||
| plugin_config['MODEL_DISTRIBUTION_POLICY'] = 'PIPELINE_PARALLEL' | ||||||||||
|
|
||||||||||
| if task_parameters['target_device'] == 'NPU': | ||||||||||
| max_prompt_len = task_parameters['max_prompt_len'] | ||||||||||
| npu_properties = {} | ||||||||||
| if max_prompt_len is not None: | ||||||||||
| npu_properties['MAX_PROMPT_LEN'] = max_prompt_len | ||||||||||
| if task_parameters['enable_prefix_caching']: | ||||||||||
| npu_properties['NPUW_LLM_ENABLE_PREFIX_CACHING'] = True | ||||||||||
| device_properties = { "NPU": npu_properties } | ||||||||||
| plugin_config['DEVICE_PROPERTIES'] = device_properties | ||||||||||
|
Comment on lines
+468
to
+469
|
||||||||||
| device_properties = { "NPU": npu_properties } | |
| plugin_config['DEVICE_PROPERTIES'] = device_properties | |
| npu_device_properties = { "NPU": npu_properties } | |
| plugin_config['DEVICE_PROPERTIES'] = npu_device_properties |
Copilot
AI
Jan 28, 2026
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.
There is an extra blank line here. Consider removing this trailing whitespace to maintain consistent code formatting.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -597,12 +597,43 @@ std::variant<std::optional<std::string>, Status> GraphExport::createPluginString | |||||||||||||||||||||||||||||||||||||
| rapidjson::Value value; | ||||||||||||||||||||||||||||||||||||||
| value.SetBool(pluginConfig.useNpuPrefixCaching.value()); | ||||||||||||||||||||||||||||||||||||||
| auto itr = d.FindMember("NPUW_LLM_ENABLE_PREFIX_CACHING"); | ||||||||||||||||||||||||||||||||||||||
| if (itr != d.MemberEnd()) { | ||||||||||||||||||||||||||||||||||||||
| bool foundInTopLevel = (itr != d.MemberEnd()); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| bool foundInDeviceProperties = false; | ||||||||||||||||||||||||||||||||||||||
| if (!foundInTopLevel) { | ||||||||||||||||||||||||||||||||||||||
| auto devicePropsItr = d.FindMember("DEVICE_PROPERTIES"); | ||||||||||||||||||||||||||||||||||||||
| if (devicePropsItr != d.MemberEnd() && devicePropsItr->value.IsObject()) { | ||||||||||||||||||||||||||||||||||||||
| auto npuItr = devicePropsItr->value.FindMember("NPU"); | ||||||||||||||||||||||||||||||||||||||
| if (npuItr != devicePropsItr->value.MemberEnd() && npuItr->value.IsObject()) { | ||||||||||||||||||||||||||||||||||||||
| auto npuPrefixCachingItr = npuItr->value.FindMember("NPUW_LLM_ENABLE_PREFIX_CACHING"); | ||||||||||||||||||||||||||||||||||||||
| foundInDeviceProperties = (npuPrefixCachingItr != npuItr->value.MemberEnd()); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (foundInTopLevel || foundInDeviceProperties) { | ||||||||||||||||||||||||||||||||||||||
| return Status(StatusCode::PLUGIN_CONFIG_CONFLICTING_PARAMETERS, "Doubled NPUW_LLM_ENABLE_PREFIX_CACHING parameter in plugin config."); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| d.AddMember("NPUW_LLM_ENABLE_PREFIX_CACHING", value, d.GetAllocator()); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Add to nested structure DEVICE_PROPERTIES.NPU | ||||||||||||||||||||||||||||||||||||||
| auto devicePropsItr = d.FindMember("DEVICE_PROPERTIES"); | ||||||||||||||||||||||||||||||||||||||
| if (devicePropsItr == d.MemberEnd()) { | ||||||||||||||||||||||||||||||||||||||
| rapidjson::Value deviceProps(rapidjson::kObjectType); | ||||||||||||||||||||||||||||||||||||||
| d.AddMember("DEVICE_PROPERTIES", deviceProps, d.GetAllocator()); | ||||||||||||||||||||||||||||||||||||||
| devicePropsItr = d.FindMember("DEVICE_PROPERTIES"); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| auto npuItr = devicePropsItr->value.FindMember("NPU"); | ||||||||||||||||||||||||||||||||||||||
| if (npuItr == devicePropsItr->value.MemberEnd()) { | ||||||||||||||||||||||||||||||||||||||
| rapidjson::Value npuObj(rapidjson::kObjectType); | ||||||||||||||||||||||||||||||||||||||
| devicePropsItr->value.AddMember("NPU", npuObj, d.GetAllocator()); | ||||||||||||||||||||||||||||||||||||||
| npuItr = devicePropsItr->value.FindMember("NPU"); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+623
to
+630
|
||||||||||||||||||||||||||||||||||||||
| devicePropsItr = d.FindMember("DEVICE_PROPERTIES"); | |
| } | |
| auto npuItr = devicePropsItr->value.FindMember("NPU"); | |
| if (npuItr == devicePropsItr->value.MemberEnd()) { | |
| rapidjson::Value npuObj(rapidjson::kObjectType); | |
| devicePropsItr->value.AddMember("NPU", npuObj, d.GetAllocator()); | |
| npuItr = devicePropsItr->value.FindMember("NPU"); | |
| devicePropsItr = d.MemberEnd(); | |
| --devicePropsItr; | |
| } | |
| auto npuItr = devicePropsItr->value.FindMember("NPU"); | |
| if (npuItr == devicePropsItr->value.MemberEnd()) { | |
| rapidjson::Value npuObj(rapidjson::kObjectType); | |
| devicePropsItr->value.AddMember("NPU", npuObj, d.GetAllocator()); | |
| npuItr = devicePropsItr->value.MemberEnd(); | |
| --npuItr; |
Copilot
AI
Jan 28, 2026
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.
Similar to the DEVICE_PROPERTIES creation, after adding the NPU member in line 628, the FindMember call in line 629 is redundant. Consider refactoring to avoid this unnecessary lookup.
| devicePropsItr->value.AddMember("NPU", npuObj, d.GetAllocator()); | |
| npuItr = devicePropsItr->value.FindMember("NPU"); | |
| } | |
| npuItr->value.AddMember("NPUW_LLM_ENABLE_PREFIX_CACHING", value, d.GetAllocator()); | |
| npuObj.AddMember("NPUW_LLM_ENABLE_PREFIX_CACHING", value, d.GetAllocator()); | |
| devicePropsItr->value.AddMember("NPU", npuObj, d.GetAllocator()); | |
| } else { | |
| npuItr->value.AddMember("NPUW_LLM_ENABLE_PREFIX_CACHING", value, d.GetAllocator()); | |
| } |
Uh oh!
There was an error while loading. Please reload this page.
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.
previously we accessed
task_parameters['max_prompt_len']only if we previouslyif task_parameters['max_prompt_len'] is not None:now we dont have such check, wont there be KeyError?