Skip to content

Validate create graph parameters #3290

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

Merged
merged 11 commits into from
May 29, 2025

Conversation

michalkulakowski
Copy link
Collaborator

🛠 Summary

CVS-166727

🧪 Checklist

  • Unit tests added.
  • The documentation updated.
  • Change follows security best practices.
    ``

@michalkulakowski michalkulakowski requested a review from rasapala May 14, 2025 15:13
@michalkulakowski michalkulakowski force-pushed the mkulakow/create_graph_parameters_validation branch 3 times, most recently from 8c9921f to 1b2c917 Compare May 22, 2025 08:59
@michalkulakowski michalkulakowski requested a review from dtrawins May 22, 2025 12:38
@@ -92,6 +92,66 @@ bool Config::validate() {
std::cerr << "Error: --task parameter not set." << std::endl;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove // TODO: CVS-1667

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not removed.

std::cerr << "truncate: " << settings.truncate << " is not allowed. Supported values: true, false" << std::endl;
return false;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add check for source_model and model_repository_path if they are set and add unit tests.

src/config.cpp Outdated
}

if (serverSettings.hfSettings.sourceModel.rfind("OpenVINO/", 0) != 0) {
std::cerr << "For now only OpenVINO models are supported";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be generic check not only for text_generation. @dtrawins

@michalkulakowski michalkulakowski force-pushed the mkulakow/create_graph_parameters_validation branch from 885923a to 42d22fb Compare May 29, 2025 08:04
src/config.cpp Outdated
@@ -92,6 +92,67 @@ bool Config::validate() {
std::cerr << "Error: --task parameter not set." << std::endl;
return false;
}
#if (PYTHON_DISABLE == 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if (PYTHON_DISABLE == 1) can be removed IMHO. We base optimum-cli functionality on external tools/python/environment not on internal ovms compilation flags. This check should be generic until I change it in optimum-cli enabling PR. @dtrawins

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a valid check. The version without python shouldn't pull models outside of OV organization. Otherwise the pulled model will not work. It might change in the future but for how it looks reasonable.
@rasapala do you have in mind replacing it with a logic for checking if optimum-cli is present in runtime? It would be also fine when we have this detection.

// clang-format on
std::string fullPath = FileSystem::joinPath({directoryPath, "graph.pbtxt"});
return FileSystem::createFileOverwrite(fullPath, oss.str());
}

static Status validateSubconfigSchema(const std::string& subconfig, const std::string& type) {
rapidjson::Document subconfigJson;
rapidjson::ParseResult parseResult = subconfigJson.Parse(subconfig.c_str());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am for parsing subconfig and mediapipe graph once it is created. @dtrawins want to remove it. Lets decide now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rasapala subconfig will not be used then new embeddings and rerank calculators are merged.

::mediapipe::CalculatorGraphConfig config;
bool success = ::google::protobuf::TextFormat::ParseFromString(oss.str(), &config);
if (!success) {
SPDLOG_ERROR("Created graph config couldn't be parsed - some parameters values are invalid.");
Copy link
Collaborator

@rasapala rasapala May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created graph config couldn't be parsed - check used task parameters values.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have mixed feelings if we should include this check in the graph export. It will be checked in the model initialization.
Do we know which parameters should cause such error? How is printed out? The log format might look strange for the CLI interface.

return StatusCode::JSON_INVALID;
}
if (validateJsonAgainstSchema(subconfigJson, MEDIAPIPE_SUBCONFIG_SCHEMA.c_str()) != StatusCode::OK) {
SPDLOG_ERROR("Created {} subconfig file is not in valid configuration format", type);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created graph config couldn't be parsed - check used task parameters values.

Copy link
Collaborator

@rasapala rasapala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dtrawins please respond.

@rasapala
Copy link
Collaborator

Please change std::string "true":"false" flags to bool in cxxopts and settingsImpl.

src/config.cpp Outdated
return false;
}

std::vector allowedTargeDevices = {"CPU", "GPU", "NPU", "HETERO"};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::vector allowedTargeDevices = {"CPU", "GPU", "NPU", "HETERO"};
std::vector allowedTargetDevices = {"CPU", "GPU", "NPU", "HETERO"};

src/config.cpp Outdated
return false;
}

std::vector allowedTargeDevices = {"CPU", "GPU", "NPU", "HETERO"};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that might be to restrictive

// clang-format on
std::string fullPath = FileSystem::joinPath({directoryPath, "graph.pbtxt"});
return createFile(fullPath, oss.str());
}

static Status validateSubconfigSchema(const std::string& subconfig, const std::string& type) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed

(char*)modelName.c_str(),
(char*)"--model_repository_path",
(char*)downloadPath.c_str(),
(char*)"--enable_prefix_caching",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be bool value

(char*)modelName.c_str(),
(char*)"--model_repository_path",
(char*)downloadPath.c_str(),
(char*)"--dynamic_split_fuse",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be bool flag

(char*)"--task",
(char*)"embeddings",
(char*)"--normalize",
(char*)"INVALID",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be bool option

src/config.cpp Outdated
@@ -92,6 +92,67 @@ bool Config::validate() {
std::cerr << "Error: --task parameter not set." << std::endl;
return false;
}
#if (PYTHON_DISABLE == 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a valid check. The version without python shouldn't pull models outside of OV organization. Otherwise the pulled model will not work. It might change in the future but for how it looks reasonable.
@rasapala do you have in mind replacing it with a logic for checking if optimum-cli is present in runtime? It would be also fine when we have this detection.

src/config.cpp Outdated
return false;
}

if (std::find(allowedBoolValues.begin(), allowedBoolValues.end(), settings.truncate) == allowedBoolValues.end()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

truncate option will be effective only when convert_tokenizer is used? Maybe this parameter should be dropped for now?

::mediapipe::CalculatorGraphConfig config;
bool success = ::google::protobuf::TextFormat::ParseFromString(oss.str(), &config);
if (!success) {
SPDLOG_ERROR("Created graph config couldn't be parsed - some parameters values are invalid.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have mixed feelings if we should include this check in the graph export. It will be checked in the model initialization.
Do we know which parameters should cause such error? How is printed out? The log format might look strange for the CLI interface.

// clang-format on
std::string fullPath = FileSystem::joinPath({directoryPath, "graph.pbtxt"});
return FileSystem::createFileOverwrite(fullPath, oss.str());
}

static Status validateSubconfigSchema(const std::string& subconfig, const std::string& type) {
rapidjson::Document subconfigJson;
rapidjson::ParseResult parseResult = subconfigJson.Parse(subconfig.c_str());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rasapala subconfig will not be used then new embeddings and rerank calculators are merged.

@michalkulakowski michalkulakowski force-pushed the mkulakow/create_graph_parameters_validation branch from 0dc248d to e63a6f2 Compare May 29, 2025 11:07
};

int arg_count = 6;
EXPECT_EXIT(ovms::Config::instance().parse(arg_count, n_argv), ::testing::ExitedWithCode(OVMS_EX_USAGE), "or now OVMS version without python supports pulling OpenVINO models only");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EXPECT_EXIT(ovms::Config::instance().parse(arg_count, n_argv), ::testing::ExitedWithCode(OVMS_EX_USAGE), "or now OVMS version without python supports pulling OpenVINO models only");
EXPECT_EXIT(ovms::Config::instance().parse(arg_count, n_argv), ::testing::ExitedWithCode(OVMS_EX_USAGE), "Only OpenVINO models supported");

Copy link
Collaborator

@rasapala rasapala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 change.

@michalkulakowski michalkulakowski merged commit d885cf3 into main May 29, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants