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

[LLM] [NPU] StaticLLMPipeline: support weightless caching #1635

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 19 additions & 3 deletions src/cpp/src/llm_pipeline_static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,16 +712,23 @@ StatefulLLMPipeline::StatefulLLMPipeline(
if (!fin.is_open()) {
OPENVINO_THROW("Blob file can't be opened: " + blob_path);
}
auto compiled = genai::utils::singleton_core().import_model(fin, device, {});
auto compiled = genai::utils::singleton_core().import_model(fin, device, config);
m_max_prompt_len = compiled.get_property("NPUW_LLM_MAX_PROMPT_LEN").as<uint32_t>();
auto min_resp_len = compiled.get_property("NPUW_LLM_MIN_RESPONSE_LEN").as<uint32_t>();
m_kvcache_total = m_max_prompt_len + min_resp_len;
m_request = compiled.create_infer_request();
} else {
auto model = genai::utils::singleton_core().read_model(models_path / "openvino_model.xml", {}, config);
ModelConfigDesc model_desc = get_modeldesc_from_json(models_path / "config.json");
ov::AnyMap properties = config;
auto compiled = setupAndCompileModel(model, model_desc, properties);
std::shared_ptr<ov::CompiledModel> compiled;
// CACHE_DIR + weightless flow support
auto cache_mode = get_option<CacheMode>(config, "CACHE_MODE");
if (cache_mode.has_value() && *cache_mode == CacheMode::OPTIMIZE_SIZE) {
compiled = setupAndCompileModel(models_path / "openvino_model.xml", model_desc, properties);
} else {
auto model = genai::utils::singleton_core().read_model(models_path / "openvino_model.xml", {}, config);
compiled = setupAndCompileModel(model, model_desc, properties);
}
// Also export compiled model if required
if (export_blob) {
if (blob_path.empty()) {
Expand Down Expand Up @@ -802,6 +809,15 @@ std::shared_ptr<ov::CompiledModel> StatefulLLMPipeline::setupAndCompileModel(
return std::make_shared<ov::CompiledModel>(genai::utils::singleton_core().compile_model(model, "NPU", pipeline_config));
}

std::shared_ptr<ov::CompiledModel> StatefulLLMPipeline::setupAndCompileModel(
const std::filesystem::path& model_path,
const ModelConfigDesc& model_desc,
ov::AnyMap& pipeline_config) {
updateStatefulConfig(model_desc, pipeline_config);

return std::make_shared<ov::CompiledModel>(genai::utils::singleton_core().compile_model(model_path, "NPU", pipeline_config));
}

DecodedResults StatefulLLMPipeline::generate(
StringInputs inputs,
OptionalGenerationConfig generation_config,
Expand Down
5 changes: 5 additions & 0 deletions src/cpp/src/llm_pipeline_static.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class StatefulLLMPipeline : public LLMPipelineImplBase {
const ModelConfigDesc& model_desc,
ov::AnyMap& pipeline_config);

std::shared_ptr<ov::CompiledModel> setupAndCompileModel(
const std::filesystem::path& model_path,
const ModelConfigDesc& model_desc,
ov::AnyMap& pipeline_config);

void updateStatefulConfig(
const ModelConfigDesc& model_desc,
ov::AnyMap& pipeline_config);
Expand Down
Loading