From a3f05abd05e6368c5e8ece63951285a3692a92e6 Mon Sep 17 00:00:00 2001 From: Alexander Gutkin Date: Tue, 10 Sep 2024 13:13:18 -0700 Subject: [PATCH] Parallelizing FST construction. PiperOrigin-RevId: 673078224 --- nisaba/translit/fst/pairlm_decoder.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/nisaba/translit/fst/pairlm_decoder.cc b/nisaba/translit/fst/pairlm_decoder.cc index 7451cb3c..49d46159 100644 --- a/nisaba/translit/fst/pairlm_decoder.cc +++ b/nisaba/translit/fst/pairlm_decoder.cc @@ -993,11 +993,18 @@ StdVectorFst PairLMDecoder::BuildTransliterationFst( const std::vector input_words = absl::StrSplit( input_line, utf8::Utf8WhitespaceDelimiter(), absl::SkipEmpty()); std::vector translit_fsts(input_words.size()); - // TODO: Fix parallelization. + { + ThreadPool pool(max_parallel_tokens_); + pool.StartWorkers(); for (int i = 0; i < input_words.size(); ++i) { - translit_fsts[i] = TransliterateWord(input_words[i], word_k_best, - fst_params); + pool.Schedule([this, i, word_k_best, &translit_fsts, &input_words, + &fst_params] { + translit_fsts[i] = TransliterateWord(input_words[i], word_k_best, + fst_params); + }); } + // Wait until all threads are complete. + } // Loop through the fsts produced, joining them into a sentence lattice. for (int i = 0; i < input_words.size(); ++i) {