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

StaticLLMPipeline dangling models hotfix #693

Merged
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
18 changes: 9 additions & 9 deletions src/cpp/src/llm_pipeline_static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,26 +144,26 @@ StaticLLMPipeline::StaticLLMPipeline(
*/
ov::Core core;
// (1) Read the template model - this will be kvcache model
auto kvcache_model = core.read_model(path / "openvino_model.xml");
m_kvcache_model = core.read_model(path / "openvino_model.xml");
// (2) Expose KV-cache input and output layers from kvcache model
ov::pass::StatefulToStateless().run_on_model(kvcache_model);
ov::pass::StatefulToStateless().run_on_model(m_kvcache_model);
// (3) Clone the model - this will be prefill
auto prefill_model = kvcache_model->clone();
prefill_model->set_friendly_name(kvcache_model->get_friendly_name() + "_prefill");
m_prefill_model = m_kvcache_model->clone();
m_prefill_model->set_friendly_name(m_kvcache_model->get_friendly_name() + "_prefill");
// (4) Reshape both models to static shape
m_kvcache_desc = KVCacheDesc { 1024u, 0u };
const uint32_t max_prompt_size = m_kvcache_desc.total_size;
const uint32_t max_kvcache_size = m_kvcache_desc.total_size;
reshape_to_static(prefill_model, max_prompt_size, max_kvcache_size);
reshape_to_static(kvcache_model, 1u, max_kvcache_size);
reshape_to_static(m_prefill_model, max_prompt_size, max_kvcache_size);
reshape_to_static(m_kvcache_model, 1u, max_kvcache_size);
// (5) Add slices to kvcache model
kvcache_model = add_slices_to_kvcache_inputs(kvcache_model);
m_kvcache_model = add_slices_to_kvcache_inputs(m_kvcache_model);
// (6) Compile both model
m_prefill_request = core.compile_model(
prefill_model, device, extract_config_or_default(config, "PREFILL_CONFIG")
m_prefill_model, device, extract_config_or_default(config, "PREFILL_CONFIG")
).create_infer_request();
m_kvcache_request = core.compile_model(
kvcache_model, device, extract_config_or_default(config, "GENERATE_CONFIG")
m_kvcache_model, device, extract_config_or_default(config, "GENERATE_CONFIG")
).create_infer_request();
// (7) Initialize tensors
prepare_for_new_conversation();
Expand Down
4 changes: 4 additions & 0 deletions src/cpp/src/llm_pipeline_static.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class StaticLLMPipeline final : public LLMPipelineImplBase {
uint32_t num_stored_tokens;
};

// FIXME: Ideally, we don't need to keep those
std::shared_ptr<ov::Model> m_kvcache_model;
std::shared_ptr<ov::Model> m_prefill_model;

KVCacheDesc m_kvcache_desc;
ov::InferRequest m_kvcache_request;
ov::InferRequest m_prefill_request;
Expand Down
Loading