From bc2e4eee5ccb7bfc0158edb7bd7b7d12090703cb Mon Sep 17 00:00:00 2001 From: Jerin Philip Date: Thu, 6 May 2021 00:26:03 +0100 Subject: [PATCH] Making bytearray a commandline switch (#127) * Adding bytearray option * collapse intermediate for bytearray apps * Removing service-cli-bytearray * Removing the bergamot bytearray app * Bumping updates to brt collapsing apps * Reasonable defaults and hard check when cmd enabled * Update documentation for flags * Bump brt with MKL check and skip * Bumping BRT with MKL_FOUND instead of USE_MKL * Bumping BRT with no mkl enforce * Bumping BRT with ssse3 output * Let's try disabling OpenBLAS * Trying to disable apple accelerate * Using WASM compatible BLAS can enable intgemm * Adding a CMake -L to see what exactly is the diff * Revert "Let's try disabling OpenBLAS" This reverts commit 9a6b9bc53bf7dec956889f6e0b7047e5388e1b7e. * Revert "Using WASM compatible BLAS can enable intgemm" This reverts commit 936a592e18431c279e6c5952a278d012d18ff295. * Restricting mac tests through tags and on GitHub CI * Using only check-bytearray * Bumping BRT with change of default behaviour --- .github/workflows/native-mac.yml | 8 +- app/CMakeLists.txt | 6 -- app/bergamot-translator-app-bytearray.cpp | 40 ---------- app/service-cli-bytearray.cpp | 92 ----------------------- app/service-cli.cpp | 14 +++- bergamot-translator-tests | 2 +- 6 files changed, 20 insertions(+), 142 deletions(-) delete mode 100644 app/bergamot-translator-app-bytearray.cpp delete mode 100644 app/service-cli-bytearray.cpp diff --git a/.github/workflows/native-mac.yml b/.github/workflows/native-mac.yml index 8df203d..b1fe18f 100644 --- a/.github/workflows/native-mac.yml +++ b/.github/workflows/native-mac.yml @@ -14,7 +14,7 @@ jobs: include: - name: "full-marian" os: macos-10.15 - test_tags: "" + test_tags: "'#mac'" cmake: CMAKE_BUILD_TYPE: "Release" COMPILE_TESTS: "ON" @@ -23,6 +23,7 @@ jobs: USE_STATIC_LIBS: "OFF" COMPILE_SERVER: "OFF" COMPILE_EXAMPLES: "OFF" + USE_APPLE_ACCELERATE: "OFF" - name: "minimal-marian" os: macos-10.15 @@ -37,6 +38,8 @@ jobs: USE_STATIC_LIBS: "ON" COMPILE_SERVER: "OFF" COMPILE_EXAMPLES: "OFF" + USE_APPLE_ACCELERATE: "OFF" + name: ${{ matrix.name }} runs-on: ${{ matrix.os }} @@ -66,13 +69,14 @@ jobs: run: | mkdir -p build cd build - cmake .. \ + cmake -L .. \ -DCMAKE_BUILD_TYPE=${{ matrix.cmake.CMAKE_BUILD_TYPE }}\ -DCOMPILE_TESTS=${{ matrix.cmake.COMPILE_TESTS }}\ -DCOMPILE_EXAMPLES=${{ matrix.cmake.COMPILE_EXAMPLES }} \ -DCOMPILE_SERVER=${{ matrix.cmake.COMPILE_SERVER }} \ -DUSE_STATIC_LIBS=${{ matrix.cmake.USE_STATIC_LIBS }} \ -DUSE_WASM_COMPATIBLE_SOURCE=${{ matrix.cmake.USE_WASM_COMPATIBLE_SOURCE }} \ + -DUSE_APPLE_ACCELERATE=${{ matrix.cmake.USE_APPLE_ACCELERATE }} \ -DUSE_FBGEMM=${{ matrix.cmake.USE_FBGEMM }} - name: Compile diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index e23a107..a55a571 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1,16 +1,10 @@ add_executable(bergamot-translator-app bergamot-translator-app.cpp) target_link_libraries(bergamot-translator-app PRIVATE bergamot-translator) -add_executable(bergamot-translator-app-bytearray bergamot-translator-app-bytearray.cpp) -target_link_libraries(bergamot-translator-app-bytearray PRIVATE bergamot-translator) - if (NOT USE_WASM_COMPATIBLE_SOURCE) add_executable(service-cli service-cli.cpp) target_link_libraries(service-cli PRIVATE bergamot-translator) - add_executable(service-cli-bytearray service-cli-bytearray.cpp) - target_link_libraries(service-cli-bytearray PRIVATE bergamot-translator) - add_executable(marian-decoder-new marian-decoder-new.cpp) target_link_libraries(marian-decoder-new PRIVATE bergamot-translator) endif() diff --git a/app/bergamot-translator-app-bytearray.cpp b/app/bergamot-translator-app-bytearray.cpp deleted file mode 100644 index 91353c0..0000000 --- a/app/bergamot-translator-app-bytearray.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * main.cpp - * - * An example application to demonstrate the use of Bergamot translator. - * - */ - -#include - -#include "translator/byte_array_util.h" -#include "translator/parser.h" -#include "translator/service.h" - -int main(int argc, char **argv) { - - // Create a configParser and load command line parameters into a YAML config - // string. - auto configParser = marian::bergamot::createConfigParser(); - auto options = configParser.parseOptions(argc, argv, true); - std::string config = options->asYamlString(); - - // Route the config string to construct marian model through TranslationModel - marian::bergamot::Service model( - config, marian::bergamot::getModelMemoryFromConfig(options)); - - TranslationRequest translationRequest; - std::vector texts; - - for (std::string line; std::getline(std::cin, line);) { - texts.emplace_back(line); - } - - auto results = model.translateMultiple(std::move(texts), translationRequest); - - for (auto &result : results) { - std::cout << result.getTranslatedText() << std::endl; - } - - return 0; -} diff --git a/app/service-cli-bytearray.cpp b/app/service-cli-bytearray.cpp deleted file mode 100644 index d8c7059..0000000 --- a/app/service-cli-bytearray.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include -#include -#include -#include - -#include "common/definitions.h" -#include "common/utils.h" -#include "marian.h" -#include "translator/parser.h" -#include "translator/response.h" -#include "translator/service.h" -#include "translator/byte_array_util.h" - -int main(int argc, char *argv[]) { - auto cp = marian::bergamot::createConfigParser(); - auto options = cp.parseOptions(argc, argv, true); - - // Prepare memories for model and shortlist - marian::bergamot::AlignedMemory modelBytes = marian::bergamot::getModelMemoryFromConfig(options); - marian::bergamot::AlignedMemory shortlistBytes = marian::bergamot::getShortlistMemoryFromConfig(options); - - marian::bergamot::Service service(options, std::move(modelBytes), std::move(shortlistBytes)); - - // Read a large input text blob from stdin - std::ostringstream std_input; - std_input << std::cin.rdbuf(); - std::string input = std_input.str(); - using marian::bergamot::Response; - - marian::bergamot::ResponseOptions responseOptions; - responseOptions.qualityScores = true; - responseOptions.alignment = true; - responseOptions.alignmentThreshold = 0.2f; - - // Wait on future until Response is complete - std::future responseFuture = - service.translate(std::move(input), responseOptions); - responseFuture.wait(); - Response response = responseFuture.get(); - - std::cout << "[original]: " << response.source.text << '\n'; - std::cout << "[translated]: " << response.target.text << '\n'; - for (int sentenceIdx = 0; sentenceIdx < response.size(); sentenceIdx++) { - std::cout << " [src Sentence]: " << response.source.sentence(sentenceIdx) - << '\n'; - std::cout << " [tgt Sentence]: " << response.target.sentence(sentenceIdx) - << '\n'; - std::cout << "Alignments" << '\n'; - typedef std::pair Point; - - // Initialize a point vector. - std::vector> aggregate( - response.source.numWords(sentenceIdx)); - - // Handle alignments - auto &alignments = response.alignments[sentenceIdx]; - for (auto &p : alignments) { - aggregate[p.src].emplace_back(p.tgt, p.prob); - } - - for (size_t src = 0; src < aggregate.size(); src++) { - std::cout << response.source.word(sentenceIdx, src) << ": "; - for (auto &p : aggregate[src]) { - std::cout << response.target.word(sentenceIdx, p.first) << "(" - << p.second << ") "; - } - std::cout << '\n'; - } - - // Handle quality. - auto &quality = response.qualityScores[sentenceIdx]; - std::cout << "Quality: whole(" << quality.sequence - << "), tokens below:" << '\n'; - size_t wordIdx = 0; - bool first = true; - for (auto &p : quality.word) { - if (first) { - first = false; - } else { - std::cout << " "; - } - std::cout << response.target.word(sentenceIdx, wordIdx) << "(" << p - << ")"; - wordIdx++; - } - std::cout << '\n'; - } - std::cout << "--------------------------\n"; - std::cout << '\n'; - - return 0; -} diff --git a/app/service-cli.cpp b/app/service-cli.cpp index d7c72e6..e9dc433 100644 --- a/app/service-cli.cpp +++ b/app/service-cli.cpp @@ -6,6 +6,7 @@ #include "common/definitions.h" #include "common/utils.h" #include "marian.h" +#include "translator/byte_array_util.h" #include "translator/parser.h" #include "translator/response.h" #include "translator/response_options.h" @@ -14,7 +15,18 @@ int main(int argc, char *argv[]) { auto cp = marian::bergamot::createConfigParser(); auto options = cp.parseOptions(argc, argv, true); - marian::bergamot::Service service(options); + + // Prepare memories for model and shortlist + marian::bergamot::AlignedMemory modelBytes, shortlistBytes; + + if (options->get("check-bytearray")) { + // Load legit values into bytearrays. + modelBytes = marian::bergamot::getModelMemoryFromConfig(options); + shortlistBytes = marian::bergamot::getShortlistMemoryFromConfig(options); + } + + marian::bergamot::Service service(options, std::move(modelBytes), + std::move(shortlistBytes)); // Read a large input text blob from stdin std::ostringstream std_input; diff --git a/bergamot-translator-tests b/bergamot-translator-tests index 3771001..442edcf 160000 --- a/bergamot-translator-tests +++ b/bergamot-translator-tests @@ -1 +1 @@ -Subproject commit 3771001720a8f01bba185ee5d5d908b7c266ef31 +Subproject commit 442edcfea34dc1c53c90b5775347958fba1ffd08