Skip to content

Commit

Permalink
[LLM] [NPU] StaticLLMPipeline: Export blob (#1603)
Browse files Browse the repository at this point in the history
Mirror of #1601
  • Loading branch information
smirnov-alexey authored Jan 21, 2025
1 parent d896501 commit ec13531
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/cpp/src/llm_pipeline_static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,12 +697,13 @@ StatefulLLMPipeline::StatefulLLMPipeline(
utils::from_config_json_if_exists(models_path)),
m_sampler(m_tokenizer) {
ov::AnyMap properties = config;
const auto use_blob = pop_or_default(properties, "USE_BLOB", false);
if (use_blob) {
auto blob_path = pop_or_default(properties, "BLOB_PATH", std::string{});
if (blob_path.empty()) {
blob_path = (models_path / "openvino_model.blob").string();
}

auto blob_path = pop_or_default(properties, "BLOB_PATH", std::string{});
const auto export_blob = pop_or_default(properties, "EXPORT_BLOB", false);

bool do_import = (!blob_path.empty() && !export_blob);

if (do_import) {
if (!std::filesystem::exists(blob_path)) {
OPENVINO_THROW("Blob file is not found at: " + blob_path);
}
Expand All @@ -720,6 +721,25 @@ StatefulLLMPipeline::StatefulLLMPipeline(
ModelConfigDesc model_desc = get_modeldesc_from_json(models_path / "config.json");
ov::AnyMap properties = config;
auto compiled = setupAndCompileModel(model, model_desc, properties);
// Also export compiled model if required
if (export_blob) {
if (blob_path.empty()) {
blob_path = (models_path / "openvino_model.blob").string();
}
// Check the path is full
const int EXT_SIZE = 5; // ".blob"
if (blob_path.size() < EXT_SIZE) {
OPENVINO_THROW("Please provide a full path to blob file in BLOB_PATH: " + blob_path);
}
if (strncmp(".blob", &blob_path[blob_path.size() - EXT_SIZE], EXT_SIZE) != 0) {
OPENVINO_THROW("Please provide a full path to blob file in BLOB_PATH: " + blob_path);
}
std::ofstream fout(blob_path, std::ios::out | std::ios::binary);
if (!fout.is_open()) {
OPENVINO_THROW("Blob file can't be exported to: " + blob_path);
}
compiled->export_model(fout);
}
m_request = compiled->create_infer_request();
m_sampler.set_seed(m_generation_config.rng_seed);
}
Expand Down

0 comments on commit ec13531

Please sign in to comment.