-
Notifications
You must be signed in to change notification settings - Fork 231
Convert_tokenizer support #3699
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
+199
−12
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f399447
Convert_tokenizr support
rasapala 25d6dbd
Fix warning
rasapala c093b8f
Fix ut
rasapala 01d4018
Update optimum_export.cpp
rasapala 2ec3fd7
Merge branch 'main' into fix_optimum_tokenizer
dtrawins 287cf40
Merge branch 'main' into fix_optimum_tokenizer
rasapala 58fafe2
Fix tokenizer export
rasapala db0b01e
Fix tests
rasapala 8210552
Fix deteokenizer creation
rasapala d96666a
Fix tests
rasapala d5912a2
Switch to whereis
rasapala de12a87
Merge branch 'main' into fix_optimum_tokenizer
rasapala 3e67db4
Fix ci tests logs
rasapala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,7 @@ std::string OptimumDownloader::getExportCmdEmbeddings() { | |
| std::ostringstream oss; | ||
| // clang-format off | ||
| oss << this->OPTIMUM_CLI_EXPORT_COMMAND; | ||
| oss << "--disable-convert-tokenizer --task feature-extraction --library sentence_transformers"; | ||
| oss << "--task feature-extraction --library sentence_transformers"; | ||
| oss << " --model " << this->sourceModel << " --trust-remote-code "; | ||
| oss << " --weight-format " << this->exportSettings.precision; | ||
| oss << " " << this->downloadPath; | ||
|
|
@@ -64,7 +64,7 @@ std::string OptimumDownloader::getExportCmdRerank() { | |
| std::ostringstream oss; | ||
| // clang-format off | ||
| oss << this->OPTIMUM_CLI_EXPORT_COMMAND; | ||
| oss << "--disable-convert-tokenizer --model " << this->sourceModel; | ||
| oss << "--model " << this->sourceModel; | ||
| oss << " --trust-remote-code "; | ||
| oss << " --weight-format " << this->exportSettings.precision; | ||
| oss << " --task text-classification "; | ||
|
|
@@ -114,12 +114,32 @@ std::string OptimumDownloader::getExportCmd() { | |
| return cmd; | ||
| } | ||
|
|
||
| OptimumDownloader::OptimumDownloader(const ExportSettings& inExportSettings, const GraphExportType& inTask, const std::string& inSourceModel, const std::string& inDownloadPath, bool inOverwrite, const std::string& cliExportCmd, const std::string& cliCheckCmd) : | ||
| std::string OptimumDownloader::getConvertCmd() { | ||
| std::ostringstream oss; | ||
| // clang-format off | ||
| oss << this->CONVERT_TOKENIZER_EXPORT_COMMAND; | ||
| oss << this->sourceModel; | ||
| oss << " --with-detokenizer -o "; | ||
| oss << this->downloadPath; | ||
| // clang-format on | ||
|
|
||
| return oss.str(); | ||
| } | ||
|
|
||
| bool OptimumDownloader::checkIfDetokenizerFileIsExported() { | ||
| return std::filesystem::exists(FileSystem::joinPath({this->downloadPath, "openvino_detokenizer.xml"})); | ||
| } | ||
|
|
||
| OptimumDownloader::OptimumDownloader(const ExportSettings& inExportSettings, const GraphExportType& inTask, | ||
| const std::string& inSourceModel, const std::string& inDownloadPath, bool inOverwrite, const std::string& cliExportCmd, | ||
| const std::string& cliCheckCmd, const std::string& convertExportCmd, const std::string& convertCheckCmd) : | ||
| IModelDownloader(inSourceModel, inDownloadPath, inOverwrite), | ||
| exportSettings(inExportSettings), | ||
| task(inTask), | ||
| OPTIMUM_CLI_CHECK_COMMAND(cliCheckCmd), | ||
| OPTIMUM_CLI_EXPORT_COMMAND(cliExportCmd) {} | ||
| OPTIMUM_CLI_EXPORT_COMMAND(cliExportCmd), | ||
| CONVERT_TOKENIZER_CHECK_COMMAND(convertCheckCmd), | ||
| CONVERT_TOKENIZER_EXPORT_COMMAND(convertExportCmd) {} | ||
|
|
||
| Status OptimumDownloader::checkRequiredToolsArePresent() { | ||
| int retCode = -1; | ||
|
|
@@ -131,6 +151,15 @@ Status OptimumDownloader::checkRequiredToolsArePresent() { | |
| } | ||
|
|
||
| SPDLOG_DEBUG("Optimum-cli executable is present"); | ||
|
|
||
| output = exec_cmd(this->CONVERT_TOKENIZER_CHECK_COMMAND, retCode); | ||
| if (retCode != 0) { | ||
| SPDLOG_DEBUG("Command output {}", output); | ||
| SPDLOG_ERROR("Trying to pull {} from HuggingFace but missing convert_tokenizer. Use the ovms package with convert_tokenizer.", this->sourceModel); | ||
|
||
| return StatusCode::HF_FAILED_TO_INIT_OPTIMUM_CLI; | ||
| } | ||
|
|
||
| SPDLOG_DEBUG("Convert_tokenizer executable is present"); | ||
| return StatusCode::OK; | ||
| } | ||
|
|
||
|
|
@@ -171,6 +200,20 @@ Status OptimumDownloader::downloadModel() { | |
| return StatusCode::HF_RUN_OPTIMUM_CLI_EXPORT_FAILED; | ||
| } | ||
|
|
||
| if (!this->checkIfDetokenizerFileIsExported()) { | ||
| SPDLOG_DEBUG("Detokenizer not found in the exported model. Exporting tokenizer and detokenizer from HF model."); | ||
| cmd = getConvertCmd(); | ||
| retCode = -1; | ||
| output = exec_cmd(cmd, retCode); | ||
| if (retCode != 0) { | ||
| SPDLOG_DEBUG("Command output {}", output); | ||
| SPDLOG_ERROR("convert_tokenizer command failed."); | ||
| return StatusCode::HF_RUN_CONVERT_TOKENIZER_EXPORT_FAILED; | ||
| } | ||
| } else { | ||
| SPDLOG_DEBUG("Detokenizer is found in the exported model directory. Convert_tokenizer command not required."); | ||
| } | ||
|
|
||
| return StatusCode::OK; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in some pipelines there is no detokenizer. was it tested?