Skip to content

Commit 3120bdf

Browse files
committed
Adjust options
1 parent 94495b4 commit 3120bdf

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

src/cpp/src/rag/text_embedding_pipeline.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,16 @@ class TextEmbeddingPipeline::TextEmbeddingPipelineImpl {
245245
}
246246
}
247247

248-
bool should_reshape = (device != "NPU" && (m_config.batch_size.has_value() || m_config.max_length.has_value())) ||
249-
(device == "NPU" && m_config.batch_size.has_value() && is_fixed_size);
250-
if (should_reshape) {
248+
bool should_reshape_non_npu = (device != "NPU" && (m_config.batch_size.has_value() || m_config.max_length.has_value()));
249+
bool should_reshape_npu = (device == "NPU" && m_config.batch_size.has_value() && is_fixed_size);
250+
if (should_reshape_non_npu || should_reshape_npu) {
251251
reshape_model(model);
252252
}
253253

254254
ov::CompiledModel compiled_model;
255255
if (device == "NPU" && model->is_dynamic()) {
256-
const auto is_padding = m_config.pad_to_max_length.has_value() && m_config.pad_to_max_length.value();
257-
OPENVINO_ASSERT(!is_padding || config.pooling_type == TextEmbeddingPipeline::PoolingType::MEAN,
258-
"Padding is only supported for the mean post-processing type");
256+
OPENVINO_ASSERT(!(is_padding_on_left && is_fixed_size) || config.pooling_type == TextEmbeddingPipeline::PoolingType::MEAN,
257+
"Padding on left is only supported for the mean post-processing type");
259258

260259
auto kv_pos = ov::genai::utils::get_kv_axes_pos(model);
261260
utils::KVDesc kv_desc;

src/cpp/src/utils.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ namespace ov {
151151
namespace genai {
152152
namespace utils {
153153

154+
enum class ModelType {
155+
Standard,
156+
Whisper,
157+
TextEmbedding
158+
};
159+
154160
Tensor init_attention_mask(const Tensor& input_ids) {
155161
auto shape = input_ids.get_shape();
156162
auto attention_mask = ov::Tensor{input_ids.get_element_type(), shape};
@@ -608,10 +614,7 @@ void import_npu_model(ov::CompiledModel& compiled,
608614
}
609615

610616
void export_npu_model(ov::CompiledModel& compiled,
611-
std::string& blob_path) {
612-
if (blob_path.empty()) {
613-
blob_path = "openvino_model.blob";
614-
}
617+
const std::string& blob_path) {
615618
// Check the path is full
616619
const int EXT_SIZE = 5; // ".blob"
617620
if (blob_path.size() < EXT_SIZE) {
@@ -657,8 +660,7 @@ std::pair<ov::CompiledModel, KVDesc>
657660
compile_decoder_for_npu_impl(const std::shared_ptr<ov::Model>& model,
658661
const ov::AnyMap& config,
659662
const KVAxesPosition& kv_pos,
660-
const bool is_whisper,
661-
const bool is_text_embedding,
663+
ModelType model_type,
662664
const ov::AnyMap& text_embed_config = {}) {
663665
ov::CompiledModel compiled;
664666
ov::AnyMap properties = config;
@@ -671,15 +673,25 @@ compile_decoder_for_npu_impl(const std::shared_ptr<ov::Model>& model,
671673
if (do_import) {
672674
import_npu_model(compiled, kv_desc, properties, blob_path);
673675
} else {
674-
if (is_text_embedding) {
675-
get_npu_text_embedding_config(properties, kv_pos, kv_desc, text_embed_config);
676-
} else {
677-
get_npu_model_config(properties, kv_pos, kv_desc, is_whisper);
676+
switch (model_type) {
677+
case ModelType::TextEmbedding:
678+
get_npu_text_embedding_config(properties, kv_pos, kv_desc, text_embed_config);
679+
break;
680+
case ModelType::Whisper:
681+
get_npu_model_config(properties, kv_pos, kv_desc, true);
682+
break;
683+
case ModelType::Standard:
684+
default:
685+
get_npu_model_config(properties, kv_pos, kv_desc, false);
686+
break;
678687
}
679688

680689
compiled = ov::genai::utils::singleton_core().compile_model(model, "NPU", properties);
681690
// Also export compiled model if required
682691
if (export_blob) {
692+
if (blob_path.empty()) {
693+
blob_path = "openvino_model.blob";
694+
}
683695
export_npu_model(compiled, blob_path);
684696
}
685697
}
@@ -692,15 +704,17 @@ compile_decoder_for_npu(const std::shared_ptr<ov::Model>& model,
692704
const ov::AnyMap& config,
693705
const KVAxesPosition& kv_pos,
694706
const bool is_whisper) {
695-
return compile_decoder_for_npu_impl(model, config, kv_pos, is_whisper, false);
707+
return compile_decoder_for_npu_impl(model, config, kv_pos,
708+
is_whisper ? ModelType::Whisper : ModelType::Standard
709+
);
696710
}
697711

698712
std::pair<ov::CompiledModel, KVDesc>
699713
compile_decoder_for_npu_text_embedding(const std::shared_ptr<ov::Model>& model,
700714
const ov::AnyMap& config,
701715
const KVAxesPosition& kv_pos,
702716
const ov::AnyMap& text_embed_config) {
703-
return compile_decoder_for_npu_impl(model, config, kv_pos, false, true, text_embed_config);
717+
return compile_decoder_for_npu_impl(model, config, kv_pos, ModelType::TextEmbedding, text_embed_config);
704718
}
705719

706720
std::optional<ov::Any> pop_option(ov::AnyMap& config, const std::string& option_name) {

0 commit comments

Comments
 (0)