From c6a902ee4be93f22ae80d422e4706fc5acfc93a4 Mon Sep 17 00:00:00 2001
From: Franck Dary <franck.dary@lis-lab.fr>
Date: Sun, 17 May 2020 23:11:28 +0200
Subject: [PATCH] Throw error if given pretrained word embeddings file don't
 exist

---
 torch_modules/src/Submodule.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/torch_modules/src/Submodule.cpp b/torch_modules/src/Submodule.cpp
index 31e43c7..0cfa723 100644
--- a/torch_modules/src/Submodule.cpp
+++ b/torch_modules/src/Submodule.cpp
@@ -7,9 +7,12 @@ void Submodule::setFirstInputIndex(std::size_t firstInputIndex)
 
 void Submodule::loadPretrainedW2vEmbeddings(torch::nn::Embedding & embeddings, std::filesystem::path path)
 {
-  if (!std::filesystem::exists(path))
+  if (path.empty())
     return;
 
+  if (!std::filesystem::exists(path))
+    util::myThrow(fmt::format("pretrained word2vec file '{}' do not exist", path.string()));
+
   torch::NoGradGuard no_grad;
 
   auto originalState = getDict().getState();
-- 
GitLab