diff --git a/src/translator/batch_translator.cpp b/src/translator/batch_translator.cpp index 1506537cf..ea8d0925a 100644 --- a/src/translator/batch_translator.cpp +++ b/src/translator/batch_translator.cpp @@ -11,10 +11,10 @@ namespace bergamot { BatchTranslator::BatchTranslator(DeviceId const device, std::vector> &vocabs, Ptr options, - const AlignedMemory *modelMemory, - const AlignedMemory *shortlistMemory) + const AlignedMemory* modelMemory, + const AlignedMemory* shortlistMemory) : device_(device), options_(options), vocabs_(&vocabs), - modelMemory_(modelMemory), shortlistMemory_(shortlistMemory) {} + modelMemory_(modelMemory), shortlistMemory_(shortlistMemory) {} void BatchTranslator::initialize() { // Initializes the graph. @@ -22,16 +22,17 @@ void BatchTranslator::initialize() { int srcIdx = 0, trgIdx = 1; bool shared_vcb = vocabs_->front() == vocabs_->back(); if (shortlistMemory_->size() > 0 && shortlistMemory_->begin() != nullptr) { - bool check = options_->get("check-bytearray", true); - slgen_ = New( - shortlistMemory_->begin(), shortlistMemory_->size(), vocabs_->front(), - vocabs_->back(), srcIdx, trgIdx, shared_vcb, check); - } else { - // Changed to BinaryShortlistGenerator to enable loading binary shortlist - // file This class also supports text shortlist file + bool check = options_->get("check-bytearray",true); + slgen_ = New(shortlistMemory_->begin(), shortlistMemory_->size(), + vocabs_->front(), vocabs_->back(), + srcIdx, trgIdx, shared_vcb, check); + } + else { + // Changed to BinaryShortlistGenerator to enable loading binary shortlist file + // This class also supports text shortlist file slgen_ = New(options_, vocabs_->front(), - vocabs_->back(), srcIdx, - trgIdx, shared_vcb); + vocabs_->back(), srcIdx, + trgIdx, shared_vcb); } } @@ -41,18 +42,10 @@ void BatchTranslator::initialize() { graph_->setDevice(device_); graph_->getBackend()->configureDevice(options_); graph_->reserveWorkspaceMB(options_->get("workspace")); - if (modelMemory_->size() > 0 && - modelMemory_->begin() != - nullptr) { // If we have provided a byte array that contains the model - // memory, we can initialise the model from there, as - // opposed to from reading in the config file + if (modelMemory_->size() > 0 && modelMemory_->begin() != nullptr) { // If we have provided a byte array that contains the model memory, we can initialise the model from there, as opposed to from reading in the config file ABORT_IF((uintptr_t)modelMemory_->begin() % 256 != 0, - "The provided memory is not aligned to 256 bytes and will crash " - "when vector instructions are used on it."); - const std::vector container = { - modelMemory_->begin()}; // Marian supports multiple models initialised - // in this manner hence std::vector. However we - // will only ever use 1 during decoding. + "The provided memory is not aligned to 256 bytes and will crash when vector instructions are used on it."); + const std::vector container = {modelMemory_->begin()}; // Marian supports multiple models initialised in this manner hence std::vector. However we will only ever use 1 during decoding. scorers_ = createScorers(options_, container); } else { scorers_ = createScorers(options_); @@ -76,6 +69,7 @@ void BatchTranslator::translate(Batch &batch) { Segment segment = sentence.getUnderlyingSegment(); sentence_tuple.push_back(segment); batchVector.push_back(sentence_tuple); + ++batchSequenceNumber; }