diff --git a/CMakeLists.txt b/CMakeLists.txt index e6edd356d..e907fa05d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ project(openvino_tokenizers) include(cmake/platforms.cmake) -find_package(OpenVINO REQUIRED COMPONENTS Runtime) +find_package(OpenVINO REQUIRED COMPONENTS Runtime OPTIONAL_COMPONENTS TensorFlow) # set the project version using OpenVINO major, minor and patch versions set(CMAKE_PROJECT_VERSION_TWEAK 0) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a72889439..282a9dd5c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -167,11 +167,20 @@ endif() # file(GLOB SRC *.cpp) +if(NOT OpenVINO_Frontend_TensorFlow_FOUND) + list(REMOVE_ITEM SRC ${CMAKE_CURRENT_SOURCE_DIR}/tensorflow_translators.cpp) +endif() + add_library(${TARGET_NAME} SHARED ${SRC}) target_compile_definitions(${TARGET_NAME} PRIVATE IMPLEMENT_OPENVINO_EXTENSION_API) target_link_libraries(${TARGET_NAME} PRIVATE openvino::runtime) +if(OpenVINO_Frontend_TensorFlow_FOUND) + target_link_libraries(${TARGET_NAME} PRIVATE openvino::frontend::tensorflow) + target_compile_definitions(${TARGET_NAME} PRIVATE OpenVINO_Frontend_TensorFlow_FOUND) +endif() + # # Target include dirs, link libraries and other properties # diff --git a/src/ov_extension.cpp b/src/ov_extension.cpp index 0cb01d09f..0c45ccbf6 100644 --- a/src/ov_extension.cpp +++ b/src/ov_extension.cpp @@ -8,6 +8,21 @@ #include "tokenizer.hpp" +#ifdef OpenVINO_Frontend_TensorFlow_FOUND +#include +#define OPENVINO_TOKENIZERS_TENSORFLOW_CONVERSION_EXTENSIONS \ + std::make_shared("WordpieceTokenizeWithOffsets", translate_wordpiece_tokenize_with_offsets), \ + std::make_shared("RegexSplitWithOffsets", translate_regex_split_with_offsets), \ + std::make_shared("NormalizeUTF8", translate_normalize_utf8), \ + std::make_shared("CaseFoldUTF8", translate_case_fold_utf8), \ + std::make_shared("SentencepieceOp", translate_sentencepiece_op), \ + std::make_shared("RaggedTensorToSparse", translate_sentencepiece_tokenizer), \ + std::make_shared("StringLower", translate_string_lower), \ + std::make_shared("StaticRegexReplace", translate_static_regex_replace), +#else +#define OPENVINO_TOKENIZERS_TENSORFLOW_CONVERSION_EXTENSIONS +#endif + // clang-format off //! [ov_extension:entry_point] OPENVINO_CREATE_EXTENSIONS( @@ -16,15 +31,10 @@ OPENVINO_CREATE_EXTENSIONS( std::make_shared>(), std::make_shared>(), std::make_shared>(), - std::make_shared("CaseFoldUTF8", translate_case_fold_utf8), std::make_shared>(), - std::make_shared("NormalizeUTF8", translate_normalize_utf8), std::make_shared>(), - std::make_shared("StaticRegexReplace", translate_static_regex_replace), std::make_shared>(), - std::make_shared("RegexSplitWithOffsets", translate_regex_split_with_offsets), std::make_shared>(), - std::make_shared("WordpieceTokenizeWithOffsets", translate_wordpiece_tokenize_with_offsets), std::make_shared>(), std::make_shared>(), std::make_shared>(), @@ -34,9 +44,7 @@ OPENVINO_CREATE_EXTENSIONS( std::make_shared>(), std::make_shared>(), std::make_shared>(), - std::make_shared("SentencepieceOp", translate_sentencepiece_op), - std::make_shared("RaggedTensorToSparse", translate_sentencepiece_tokenizer), - std::make_shared("StringLower", translate_string_lower), - })); + OPENVINO_TOKENIZERS_TENSORFLOW_CONVERSION_EXTENSIONS +})); //! [ov_extension:entry_point] // clang-format on