Skip to content

Commit

Permalink
See the struggle turning autoformat off and prettifying diff ugghhh
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerin Philip committed Apr 2, 2021
1 parent 62d022c commit 512cc3d
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions src/translator/batch_translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,28 @@ namespace bergamot {
BatchTranslator::BatchTranslator(DeviceId const device,
std::vector<Ptr<Vocab const>> &vocabs,
Ptr<Options> 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.
if (options_->hasAndNotEmpty("shortlist")) {
int srcIdx = 0, trgIdx = 1;
bool shared_vcb = vocabs_->front() == vocabs_->back();
if (shortlistMemory_->size() > 0 && shortlistMemory_->begin() != nullptr) {
bool check = options_->get<bool>("check-bytearray", true);
slgen_ = New<data::BinaryShortlistGenerator>(
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<bool>("check-bytearray",true);
slgen_ = New<data::BinaryShortlistGenerator>(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<data::BinaryShortlistGenerator>(options_, vocabs_->front(),
vocabs_->back(), srcIdx,
trgIdx, shared_vcb);
vocabs_->back(), srcIdx,
trgIdx, shared_vcb);
}
}

Expand All @@ -41,18 +42,10 @@ void BatchTranslator::initialize() {
graph_->setDevice(device_);
graph_->getBackend()->configureDevice(options_);
graph_->reserveWorkspaceMB(options_->get<size_t>("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<const void *> 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<const void *> 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_);
Expand All @@ -76,6 +69,7 @@ void BatchTranslator::translate(Batch &batch) {
Segment segment = sentence.getUnderlyingSegment();
sentence_tuple.push_back(segment);
batchVector.push_back(sentence_tuple);

++batchSequenceNumber;
}

Expand Down

0 comments on commit 512cc3d

Please sign in to comment.