Skip to content

Commit 6a847f1

Browse files
committed
add check_bool_optional_param
Signed-off-by: xiping.yan <xiping.yan@intel.com>
1 parent 033ec81 commit 6a847f1

4 files changed

Lines changed: 21 additions & 16 deletions

File tree

src/cpp/src/module_genai/modules/md_denoiser_loop/class.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ bool DenoiserLoopModule::initialize() {
8383

8484
check_splitted_model();
8585

86-
m_dynamic_load_weights = check_bool_param("dynamic_load_weights", false);
86+
m_dynamic_load_weights = check_bool_optional_param("dynamic_load_weights", false);
8787

8888
check_cache_dir();
8989
if (m_dynamic_load_weights && m_cache_dir.empty()) {

src/cpp/src/module_genai/modules/md_text_to_speech/md_text_to_speech.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ TextToSpeechModule::TextToSpeechModule(const IBaseModuleDesc::PTR& desc,
7272
: IBaseModule(desc, pipeline_desc),
7373
m_model_type(model_type),
7474
m_device(desc->device.empty() ? "CPU" : desc->device) {
75-
m_sample_codec_token_greedy_search = check_bool_param("sample_codec_token_greedy_search", false);
76-
m_merge_ar_and_sce_ov_models = check_bool_param("merge_ar_and_sce_ov_models", false);
75+
m_sample_codec_token_greedy_search = check_bool_optional_param("sample_codec_token_greedy_search", false);
76+
m_merge_ar_and_sce_ov_models = check_bool_optional_param("merge_ar_and_sce_ov_models", false);
7777
}
7878

7979
TextToSpeechModule::~TextToSpeechModule() = default;

src/cpp/src/module_genai/pipeline/module_base.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,24 +156,28 @@ void IBaseModule::check_splitted_model() {
156156
}
157157
}
158158

159-
bool IBaseModule::check_bool_param(const std::string& param_name, const bool& default_value, const bool& requires) {
160-
auto p = requires ? get_param(param_name) : get_optional_param(param_name);
161-
if (p.empty()) {
162-
return default_value;
163-
}
164-
165-
if (p == "true" || p == "True" || p == "TRUE" || p == "1") {
166-
GENAI_INFO("Module[" + module_desc->name + "]: " + param_name + " = true");
159+
static bool str_to_bool(const std::string& str, bool default_value) {
160+
if (str == "true" || str == "True" || str == "TRUE" || str == "1") {
167161
return true;
168-
} else if (p == "false" || p == "False" || p == "FALSE" || p == "0") {
169-
GENAI_INFO("Module[" + module_desc->name + "]: " + param_name + " = false");
162+
} else if (str == "false" || str == "False" || str == "FALSE" || str == "0") {
170163
return false;
171164
}
172-
GENAI_ERR("Module[" + module_desc->name + "]: Invalid bool param value for '" + param_name + "': " + p +
173-
", use default value: " + (default_value ? "true" : "false"));
174165
return default_value;
175166
}
176167

168+
bool IBaseModule::check_bool_param(const std::string& param_name) {
169+
auto p = get_param(param_name);
170+
return str_to_bool(p, false);
171+
}
172+
173+
bool IBaseModule::check_bool_optional_param(const std::string& param_name, const bool& default_value) {
174+
auto p = get_optional_param(param_name);
175+
if (p.empty()) {
176+
return default_value;
177+
}
178+
return str_to_bool(p, default_value);
179+
}
180+
177181
// PipelineDesc implementation
178182
PipelineDesc::PipelineDesc() : m_resource_cache(std::make_unique<PipelineResourceCache>()) {}
179183

src/cpp/src/module_genai/pipeline/module_base.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ class IBaseModule {
8181
bool m_splitted_model = false;
8282
void check_splitted_model();
8383

84-
bool check_bool_param(const std::string& param_name, const bool& default_value, const bool& requires=false);
84+
bool check_bool_param(const std::string& param_name);
85+
bool check_bool_optional_param(const std::string& param_name, const bool& default_value);
8586

8687
// Initialize ov::Model from config models_map with param_name: "ov_model"
8788
void init_ov_model();

0 commit comments

Comments
 (0)