Skip to content

Commit

Permalink
Remove shared_ptr wrapping the AlignedMemory of models.
Browse files Browse the repository at this point in the history
  • Loading branch information
graemenail committed Jul 30, 2023
1 parent 4081ec0 commit eef17fc
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/translator/byte_array_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ AlignedMemory loadFileToMemory(const std::string& path, size_t alignment) {
return alignedMemory;
}

std::vector<std::shared_ptr<AlignedMemory>> getModelMemoryFromConfig(marian::Ptr<marian::Options> options) {
std::vector<AlignedMemory> getModelMemoryFromConfig(marian::Ptr<marian::Options> options) {
auto models = options->get<std::vector<std::string>>("models");

std::vector<std::shared_ptr<AlignedMemory>> modelMemories(models.size());
std::vector<AlignedMemory> modelMemories(models.size());
for (size_t i = 0; i < models.size(); ++i) {
const auto model = models[i];
if (marian::io::isBin(model)) {
modelMemories[i] = std::make_shared<AlignedMemory>(loadFileToMemory(model, 256));
modelMemories[i] = loadFileToMemory(model, 256);
} else if (marian::io::isNpz(model)) {
// if any of the models are npz format, we revert to loading from file for all models.
LOG(debug, "Encountered an npz file {}; will use file loading for {} models", model, models.size());
Expand Down
2 changes: 1 addition & 1 deletion src/translator/byte_array_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace marian {
namespace bergamot {

AlignedMemory loadFileToMemory(const std::string& path, size_t alignment);
std::vector<std::shared_ptr<AlignedMemory>> getModelMemoryFromConfig(marian::Ptr<marian::Options> options);
std::vector<AlignedMemory> getModelMemoryFromConfig(marian::Ptr<marian::Options> options);
AlignedMemory getQualityEstimatorModel(const marian::Ptr<marian::Options>& options);
AlignedMemory getQualityEstimatorModel(MemoryBundle& memoryBundle, const marian::Ptr<marian::Options>& options);
AlignedMemory getShortlistMemoryFromConfig(marian::Ptr<marian::Options> options);
Expand Down
2 changes: 1 addition & 1 deletion src/translator/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef AlignedVector<char> AlignedMemory;
/// Memory bundle for all byte-arrays.
/// Can be a set/subset of model, shortlist, vocabs and ssplitPrefixFile bytes.
struct MemoryBundle {
std::vector<std::shared_ptr<AlignedMemory>> models{}; ///< Byte-array of model (aligned to 256)
std::vector<AlignedMemory> models{}; ///< Byte-array of model (each element is aligned to 256)
AlignedMemory shortlist{}; ///< Byte-array of shortlist (aligned to 64)

/// Vector of vocabulary memories (aligned to 64).
Expand Down
2 changes: 1 addition & 1 deletion src/translator/translation_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void TranslationModel::loadBackend(size_t idx) {
const std::vector<const void *> container = std::invoke([&]() {
std::vector<const void *> model_ptrs(memory_.models.size());
for (size_t i = 0; i < memory_.models.size(); ++i) {
const AlignedMemory &model = *memory_.models[i];
const AlignedMemory &model = memory_.models[i];

ABORT_IF(model.size() == 0 || model.begin() == nullptr, "The provided memory is empty. Cannot load the model.");
ABORT_IF(
Expand Down
2 changes: 1 addition & 1 deletion wasm/bindings/service_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ MemoryBundle prepareMemoryBundle(AlignedMemory* modelMemory, AlignedMemory* shor
std::vector<AlignedMemory*> uniqueVocabsMemories,
AlignedMemory* qualityEstimatorMemory) {
MemoryBundle memoryBundle;
memoryBundle.models.emplace_back(std::make_shared<AlignedMemory>(std::move(*modelMemory)));
memoryBundle.models.emplace_back(std::move(*modelMemory));
memoryBundle.shortlist = std::move(*shortlistMemory);
memoryBundle.vocabs = std::move(prepareVocabsSmartMemories(uniqueVocabsMemories));
if (qualityEstimatorMemory != nullptr) {
Expand Down

0 comments on commit eef17fc

Please sign in to comment.