mirror of
https://github.com/browsermt/bergamot-translator.git
synced 2024-09-11 05:35:33 +03:00
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 commit9a6b9bc53b
. * Revert "Using WASM compatible BLAS can enable intgemm" This reverts commit936a592e18
. * Restricting mac tests through tags and on GitHub CI * Using only check-bytearray * Bumping BRT with change of default behaviour
This commit is contained in:
parent
c61b2bdd10
commit
bc2e4eee5c
8
.github/workflows/native-mac.yml
vendored
8
.github/workflows/native-mac.yml
vendored
@ -14,7 +14,7 @@ jobs:
|
|||||||
include:
|
include:
|
||||||
- name: "full-marian"
|
- name: "full-marian"
|
||||||
os: macos-10.15
|
os: macos-10.15
|
||||||
test_tags: ""
|
test_tags: "'#mac'"
|
||||||
cmake:
|
cmake:
|
||||||
CMAKE_BUILD_TYPE: "Release"
|
CMAKE_BUILD_TYPE: "Release"
|
||||||
COMPILE_TESTS: "ON"
|
COMPILE_TESTS: "ON"
|
||||||
@ -23,6 +23,7 @@ jobs:
|
|||||||
USE_STATIC_LIBS: "OFF"
|
USE_STATIC_LIBS: "OFF"
|
||||||
COMPILE_SERVER: "OFF"
|
COMPILE_SERVER: "OFF"
|
||||||
COMPILE_EXAMPLES: "OFF"
|
COMPILE_EXAMPLES: "OFF"
|
||||||
|
USE_APPLE_ACCELERATE: "OFF"
|
||||||
|
|
||||||
- name: "minimal-marian"
|
- name: "minimal-marian"
|
||||||
os: macos-10.15
|
os: macos-10.15
|
||||||
@ -37,6 +38,8 @@ jobs:
|
|||||||
USE_STATIC_LIBS: "ON"
|
USE_STATIC_LIBS: "ON"
|
||||||
COMPILE_SERVER: "OFF"
|
COMPILE_SERVER: "OFF"
|
||||||
COMPILE_EXAMPLES: "OFF"
|
COMPILE_EXAMPLES: "OFF"
|
||||||
|
USE_APPLE_ACCELERATE: "OFF"
|
||||||
|
|
||||||
|
|
||||||
name: ${{ matrix.name }}
|
name: ${{ matrix.name }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
@ -66,13 +69,14 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
cd build
|
cd build
|
||||||
cmake .. \
|
cmake -L .. \
|
||||||
-DCMAKE_BUILD_TYPE=${{ matrix.cmake.CMAKE_BUILD_TYPE }}\
|
-DCMAKE_BUILD_TYPE=${{ matrix.cmake.CMAKE_BUILD_TYPE }}\
|
||||||
-DCOMPILE_TESTS=${{ matrix.cmake.COMPILE_TESTS }}\
|
-DCOMPILE_TESTS=${{ matrix.cmake.COMPILE_TESTS }}\
|
||||||
-DCOMPILE_EXAMPLES=${{ matrix.cmake.COMPILE_EXAMPLES }} \
|
-DCOMPILE_EXAMPLES=${{ matrix.cmake.COMPILE_EXAMPLES }} \
|
||||||
-DCOMPILE_SERVER=${{ matrix.cmake.COMPILE_SERVER }} \
|
-DCOMPILE_SERVER=${{ matrix.cmake.COMPILE_SERVER }} \
|
||||||
-DUSE_STATIC_LIBS=${{ matrix.cmake.USE_STATIC_LIBS }} \
|
-DUSE_STATIC_LIBS=${{ matrix.cmake.USE_STATIC_LIBS }} \
|
||||||
-DUSE_WASM_COMPATIBLE_SOURCE=${{ matrix.cmake.USE_WASM_COMPATIBLE_SOURCE }} \
|
-DUSE_WASM_COMPATIBLE_SOURCE=${{ matrix.cmake.USE_WASM_COMPATIBLE_SOURCE }} \
|
||||||
|
-DUSE_APPLE_ACCELERATE=${{ matrix.cmake.USE_APPLE_ACCELERATE }} \
|
||||||
-DUSE_FBGEMM=${{ matrix.cmake.USE_FBGEMM }}
|
-DUSE_FBGEMM=${{ matrix.cmake.USE_FBGEMM }}
|
||||||
|
|
||||||
- name: Compile
|
- name: Compile
|
||||||
|
@ -1,16 +1,10 @@
|
|||||||
add_executable(bergamot-translator-app bergamot-translator-app.cpp)
|
add_executable(bergamot-translator-app bergamot-translator-app.cpp)
|
||||||
target_link_libraries(bergamot-translator-app PRIVATE bergamot-translator)
|
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)
|
if (NOT USE_WASM_COMPATIBLE_SOURCE)
|
||||||
add_executable(service-cli service-cli.cpp)
|
add_executable(service-cli service-cli.cpp)
|
||||||
target_link_libraries(service-cli PRIVATE bergamot-translator)
|
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)
|
add_executable(marian-decoder-new marian-decoder-new.cpp)
|
||||||
target_link_libraries(marian-decoder-new PRIVATE bergamot-translator)
|
target_link_libraries(marian-decoder-new PRIVATE bergamot-translator)
|
||||||
endif()
|
endif()
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
/*
|
|
||||||
* main.cpp
|
|
||||||
*
|
|
||||||
* An example application to demonstrate the use of Bergamot translator.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#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<std::string> 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;
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
#include <cstdlib>
|
|
||||||
#include <future>
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#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<Response> 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<size_t, float> Point;
|
|
||||||
|
|
||||||
// Initialize a point vector.
|
|
||||||
std::vector<std::vector<Point>> 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;
|
|
||||||
}
|
|
@ -6,6 +6,7 @@
|
|||||||
#include "common/definitions.h"
|
#include "common/definitions.h"
|
||||||
#include "common/utils.h"
|
#include "common/utils.h"
|
||||||
#include "marian.h"
|
#include "marian.h"
|
||||||
|
#include "translator/byte_array_util.h"
|
||||||
#include "translator/parser.h"
|
#include "translator/parser.h"
|
||||||
#include "translator/response.h"
|
#include "translator/response.h"
|
||||||
#include "translator/response_options.h"
|
#include "translator/response_options.h"
|
||||||
@ -14,7 +15,18 @@
|
|||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
auto cp = marian::bergamot::createConfigParser();
|
auto cp = marian::bergamot::createConfigParser();
|
||||||
auto options = cp.parseOptions(argc, argv, true);
|
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<bool>("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
|
// Read a large input text blob from stdin
|
||||||
std::ostringstream std_input;
|
std::ostringstream std_input;
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 3771001720a8f01bba185ee5d5d908b7c266ef31
|
Subproject commit 442edcfea34dc1c53c90b5775347958fba1ffd08
|
Loading…
Reference in New Issue
Block a user