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

[WA] Add API to release memory by unload plugin #1600

Open
wants to merge 2 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
2 changes: 2 additions & 0 deletions src/cpp/include/openvino/genai/llm_pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ OPENVINO_GENAI_EXPORTS std::pair<std::string, Any> draft_model(
const std::string& device = {},
const ov::AnyMap& properties = {});

OPENVINO_GENAI_EXPORTS void clear_core_device(const std::string &device_name);

template <typename... Properties,
typename std::enable_if<ov::util::StringAny<Properties...>::value, bool>::type = true>
inline std::pair<std::string, Any> draft_model(
Expand Down
3 changes: 3 additions & 0 deletions src/cpp/src/llm_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ std::pair<std::string, Any> draft_model(
return { utils::DRAFT_MODEL_ARG_NAME, Any::make<ModelDesc>(model, tokenizer, device, plugin_config, scheduler_config, generation_config) };
}

void clear_core_device(const std::string &device_name){
utils::singleton_core().unload_plugin(device_name);
};
// Public LLMPipeline

ov::genai::LLMPipeline::LLMPipeline(
Expand Down
5 changes: 4 additions & 1 deletion src/cpp/src/llm_pipeline_stateful.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ StatefulLLMPipeline::StatefulLLMPipeline(
utils::apply_slice_before_matmul_transformation(model);
m_kv_cache_seq_length_axis = ov::genai::utils::get_seq_len_axis(model);

ov::CompiledModel compiled_model;
if (auto filtered_properties = extract_adapters_from_properties(properties, &m_generation_config.adapters)) {
m_generation_config.adapters->set_tensor_name_prefix("base_model.model.model.");
m_adapter_controller = AdapterController(model, *m_generation_config.adapters, device); // TODO: Make the prefix name configurable
Expand Down Expand Up @@ -399,4 +398,8 @@ void StatefulLLMPipeline::finish_chat() {
}
}

StatefulLLMPipeline::~StatefulLLMPipeline(){
compiled_model.release_memory();
};

} // namespace ov::genai
3 changes: 3 additions & 0 deletions src/cpp/src/llm_pipeline_stateful.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace ov::genai {

class StatefulLLMPipeline final : public LLMPipelineImplBase {
ov::InferRequest m_model_runner;
ov::CompiledModel compiled_model;
Sampler m_sampler;

// Chat scenario specific parameters
Expand Down Expand Up @@ -72,6 +73,8 @@ class StatefulLLMPipeline final : public LLMPipelineImplBase {
void start_chat(const std::string& system_message) override;

void finish_chat() override;

~StatefulLLMPipeline() override;
};

} // namespace ov::genai
Loading