@@ -286,10 +286,15 @@ class TestOptimumDownloader : public ovms::OptimumDownloader {
286286 TestOptimumDownloader (const ovms::HFSettingsImpl& inHfSettings) :
287287 ovms::OptimumDownloader (inHfSettings.exportSettings, inHfSettings.task, inHfSettings.sourceModel, ovms::HfDownloader::getGraphDirectory(inHfSettings.downloadPath, inHfSettings.sourceModel), inHfSettings.overwriteModels) {}
288288 std::string getExportCmd () { return ovms::OptimumDownloader::getExportCmd (); }
289+ std::string getConvertCmd () { return ovms::OptimumDownloader::getConvertCmd (); }
289290 std::string getGraphDirectory () { return ovms::OptimumDownloader::getGraphDirectory (); }
290291 void setExportCliCheckCommand (const std::string& input) { this ->OPTIMUM_CLI_CHECK_COMMAND = input; }
292+ void setConvertCliCheckCommand (const std::string& input) { this ->CONVERT_TOKENIZER_CHECK_COMMAND = input; }
291293 void setExportCliExportCommand (const std::string& input) { this ->OPTIMUM_CLI_EXPORT_COMMAND = input; }
294+ void setConvertCliExportCommand (const std::string& input) { this ->CONVERT_TOKENIZER_EXPORT_COMMAND = input; }
292295 ovms::Status checkRequiredToolsArePresent () { return ovms::OptimumDownloader::checkRequiredToolsArePresent (); }
296+ bool checkIfDetokenizerFileIsExported () { return ovms::OptimumDownloader::checkIfDetokenizerFileIsExported (); }
297+ bool checkIfTokenizerFileIsExported () { return ovms::OptimumDownloader::checkIfTokenizerFileIsExported (); }
293298};
294299
295300class TestHfDownloader : public ovms ::HfDownloader {
@@ -347,48 +352,101 @@ class TestOptimumDownloaderSetup : public ::testing::Test {
347352 }
348353};
349354
355+ class TestOptimumDownloaderSetupWithFile : public TestOptimumDownloaderSetup {
356+ public:
357+ ovms::HFSettingsImpl inHfSettings;
358+ std::string cliMockPath;
359+ std::filesystem::path file_path;
360+ std::filesystem::path dir_path;
361+ void TearDown () override {
362+ std::filesystem::remove (file_path);
363+ std::filesystem::remove_all (dir_path);
364+ }
365+ };
366+
350367TEST_F (TestOptimumDownloaderSetup, Methods) {
351368 std::unique_ptr<TestOptimumDownloader> optimumDownloader = std::make_unique<TestOptimumDownloader>(inHfSettings);
352369 std::string expectedPath = inHfSettings.downloadPath + " /" + inHfSettings.sourceModel ;
353370 std::string expectedCmd = " optimum-cli export openvino --model model/name --trust-remote-code --weight-format fp64 --param --param value \\ path\\ to\\ Download\\ model\\ name" ;
371+ std::string expectedCmd2 = " convert_tokenizer model/name --with-detokenizer -o \\ path\\ to\\ Download\\ model\\ name" ;
354372#ifdef _WIN32
355373 std::replace (expectedPath.begin (), expectedPath.end (), ' /' , ' \\ ' );
356374#endif
357375#ifdef __linux__
358376 std::replace (expectedCmd.begin (), expectedCmd.end (), ' \\ ' , ' /' );
377+ std::replace (expectedCmd2.begin (), expectedCmd2.end (), ' \\ ' , ' /' );
359378#endif
360379 ASSERT_EQ (optimumDownloader->getGraphDirectory (), expectedPath);
361380 ASSERT_EQ (optimumDownloader->getExportCmd (), expectedCmd);
381+ ASSERT_EQ (optimumDownloader->getConvertCmd (), expectedCmd2);
362382}
363383
364384TEST_F (TestOptimumDownloaderSetup, RerankExportCmd) {
365385 inHfSettings.task = ovms::RERANK_GRAPH;
366386 std::unique_ptr<TestOptimumDownloader> optimumDownloader = std::make_unique<TestOptimumDownloader>(inHfSettings);
367387 std::string expectedCmd = " optimum-cli export openvino --disable-convert-tokenizer --model model/name --trust-remote-code --weight-format fp64 --task text-classification \\ path\\ to\\ Download\\ model\\ name" ;
388+ std::string expectedCmd2 = " convert_tokenizer model/name -o \\ path\\ to\\ Download\\ model\\ name" ;
368389#ifdef __linux__
369390 std::replace (expectedCmd.begin (), expectedCmd.end (), ' \\ ' , ' /' );
391+ std::replace (expectedCmd2.begin (), expectedCmd2.end (), ' \\ ' , ' /' );
370392#endif
371393 ASSERT_EQ (optimumDownloader->getExportCmd (), expectedCmd);
394+ ASSERT_EQ (optimumDownloader->getConvertCmd (), expectedCmd2);
372395}
373396
374397TEST_F (TestOptimumDownloaderSetup, ImageGenExportCmd) {
375398 inHfSettings.task = ovms::IMAGE_GENERATION_GRAPH;
376399 std::unique_ptr<TestOptimumDownloader> optimumDownloader = std::make_unique<TestOptimumDownloader>(inHfSettings);
377400 std::string expectedCmd = " optimum-cli export openvino --model model/name --weight-format fp64 \\ path\\ to\\ Download\\ model\\ name" ;
401+ std::string expectedCmd2 = " " ;
378402#ifdef __linux__
379403 std::replace (expectedCmd.begin (), expectedCmd.end (), ' \\ ' , ' /' );
380404#endif
381405 ASSERT_EQ (optimumDownloader->getExportCmd (), expectedCmd);
406+ ASSERT_EQ (optimumDownloader->getConvertCmd (), expectedCmd2);
382407}
383408
384409TEST_F (TestOptimumDownloaderSetup, EmbeddingsExportCmd) {
385410 inHfSettings.task = ovms::EMBEDDINGS_GRAPH;
386411 std::unique_ptr<TestOptimumDownloader> optimumDownloader = std::make_unique<TestOptimumDownloader>(inHfSettings);
387412 std::string expectedCmd = " optimum-cli export openvino --disable-convert-tokenizer --task feature-extraction --library sentence_transformers --model model/name --trust-remote-code --weight-format fp64 \\ path\\ to\\ Download\\ model\\ name" ;
413+ std::string expectedCmd2 = " convert_tokenizer model/name -o \\ path\\ to\\ Download\\ model\\ name" ;
388414#ifdef __linux__
389415 std::replace (expectedCmd.begin (), expectedCmd.end (), ' \\ ' , ' /' );
416+ std::replace (expectedCmd2.begin (), expectedCmd2.end (), ' \\ ' , ' /' );
390417#endif
391418 ASSERT_EQ (optimumDownloader->getExportCmd (), expectedCmd);
419+ ASSERT_EQ (optimumDownloader->getConvertCmd (), expectedCmd2);
420+ }
421+
422+ TEST_F (TestOptimumDownloaderSetup, DetokenizerCheckNegative) {
423+ std::unique_ptr<TestOptimumDownloader> optimumDownloader = std::make_unique<TestOptimumDownloader>(inHfSettings);
424+ ASSERT_EQ (optimumDownloader->checkIfDetokenizerFileIsExported (), false );
425+ ASSERT_EQ (optimumDownloader->checkIfTokenizerFileIsExported (), false );
426+ }
427+
428+ TEST_F (TestOptimumDownloaderSetupWithFile, DetokenizerCheckPositive) {
429+ file_path = getGenericFullPathForBazelOut (" /ovms/bazel-bin/src/model/name/openvino_detokenizer.xml" );
430+ inHfSettings.sourceModel = " model/name" ;
431+ inHfSettings.downloadPath = getGenericFullPathForBazelOut (" /ovms/bazel-bin/src/" );
432+ dir_path = getGenericFullPathForBazelOut (" /ovms/bazel-bin/src/model/" );
433+ std::filesystem::create_directories (getGenericFullPathForBazelOut (" /ovms/bazel-bin/src/model/name" ));
434+ std::ofstream ofs (file_path); // Creates an empty file
435+ ofs.close ();
436+ std::unique_ptr<TestOptimumDownloader> optimumDownloader = std::make_unique<TestOptimumDownloader>(inHfSettings);
437+ ASSERT_EQ (optimumDownloader->checkIfDetokenizerFileIsExported (), true );
438+ }
439+
440+ TEST_F (TestOptimumDownloaderSetupWithFile, TokenizerCheckPositive) {
441+ file_path = getGenericFullPathForBazelOut (" /ovms/bazel-bin/src/model/name/openvino_tokenizer.xml" );
442+ inHfSettings.sourceModel = " model/name" ;
443+ inHfSettings.downloadPath = getGenericFullPathForBazelOut (" /ovms/bazel-bin/src/" );
444+ dir_path = getGenericFullPathForBazelOut (" /ovms/bazel-bin/src/model/" );
445+ std::filesystem::create_directories (getGenericFullPathForBazelOut (" /ovms/bazel-bin/src/model/name" ));
446+ std::ofstream ofs (file_path); // Creates an empty file
447+ ofs.close ();
448+ std::unique_ptr<TestOptimumDownloader> optimumDownloader = std::make_unique<TestOptimumDownloader>(inHfSettings);
449+ ASSERT_EQ (optimumDownloader->checkIfTokenizerFileIsExported (), true );
392450}
393451
394452TEST_F (TestOptimumDownloaderSetup, UnknownExportCmd) {
@@ -405,33 +463,51 @@ TEST_F(TestOptimumDownloaderSetup, NegativeWrongPath) {
405463
406464TEST_F (TestOptimumDownloaderSetup, NegativeExportCommandFailed) {
407465 std::unique_ptr<TestOptimumDownloader> optimumDownloader = std::make_unique<TestOptimumDownloader>(inHfSettings);
408- optimumDownloader->setExportCliCheckCommand (" ls" );
409- #ifdef _WIN32
410- optimumDownloader->setExportCliCheckCommand (" dir" );
411- #endif
466+ optimumDownloader->setExportCliCheckCommand (" echo " );
467+ optimumDownloader->setConvertCliCheckCommand (" echo " );
412468 optimumDownloader->setExportCliExportCommand (" NonExistingCommand22" );
413469 ASSERT_EQ (optimumDownloader->downloadModel (), ovms::StatusCode::HF_RUN_OPTIMUM_CLI_EXPORT_FAILED);
414470}
415471
472+ TEST_F (TestOptimumDownloaderSetup, NegativeConvertCommandFailed) {
473+ std::unique_ptr<TestOptimumDownloader> optimumDownloader = std::make_unique<TestOptimumDownloader>(inHfSettings);
474+ optimumDownloader->setExportCliCheckCommand (" echo " );
475+ optimumDownloader->setConvertCliCheckCommand (" echo " );
476+ optimumDownloader->setExportCliExportCommand (" echo " );
477+ optimumDownloader->setConvertCliExportCommand (" nonExistingCommand222" );
478+ ASSERT_EQ (optimumDownloader->downloadModel (), ovms::StatusCode::HF_RUN_CONVERT_TOKENIZER_EXPORT_FAILED);
479+ }
480+
416481TEST_F (TestOptimumDownloaderSetup, NegativeCheckOptimumExistsCommandFailed) {
417482 std::unique_ptr<TestOptimumDownloader> optimumDownloader = std::make_unique<TestOptimumDownloader>(inHfSettings);
418483 optimumDownloader->setExportCliCheckCommand (" NonExistingCommand33" );
484+ optimumDownloader->setConvertCliCheckCommand (" echo " );
485+ ASSERT_EQ (optimumDownloader->checkRequiredToolsArePresent (), ovms::StatusCode::HF_FAILED_TO_INIT_OPTIMUM_CLI);
486+ }
487+
488+ TEST_F (TestOptimumDownloaderSetup, NegativeCheckConverterExistsCommandFailed) {
489+ std::unique_ptr<TestOptimumDownloader> optimumDownloader = std::make_unique<TestOptimumDownloader>(inHfSettings);
490+ optimumDownloader->setExportCliCheckCommand (" echo " );
491+ optimumDownloader->setConvertCliCheckCommand (" NonExistingCommand33" );
419492 ASSERT_EQ (optimumDownloader->checkRequiredToolsArePresent (), ovms::StatusCode::HF_FAILED_TO_INIT_OPTIMUM_CLI);
420493}
421494
422495TEST_F (TestOptimumDownloaderSetup, PositiveOptimumExistsCommandPassed) {
423496 std::unique_ptr<TestOptimumDownloader> optimumDownloader = std::make_unique<TestOptimumDownloader>(inHfSettings);
424497 cliMockPath += " -h" ;
425498 optimumDownloader->setExportCliCheckCommand (cliMockPath);
499+ optimumDownloader->setConvertCliCheckCommand (" echo " );
426500 ASSERT_EQ (optimumDownloader->checkRequiredToolsArePresent (), ovms::StatusCode::OK);
427501}
428502
429503TEST_F (TestOptimumDownloaderSetup, PositiveOptimumExportCommandPassed) {
430504 std::unique_ptr<TestOptimumDownloader> optimumDownloader = std::make_unique<TestOptimumDownloader>(inHfSettings);
431505 std::string cliCheckCommand = cliMockPath += " -h" ;
432506 optimumDownloader->setExportCliCheckCommand (cliCheckCommand);
507+ optimumDownloader->setConvertCliCheckCommand (" echo " );
433508 cliMockPath += " export" ;
434509 optimumDownloader->setExportCliExportCommand (cliMockPath);
510+ optimumDownloader->setConvertCliExportCommand (" echo " );
435511 ASSERT_EQ (optimumDownloader->downloadModel (), ovms::StatusCode::OK);
436512}
437513
0 commit comments