diff options
author | Marcin Junczys-Dowmunt <junczys@amu.edu.pl> | 2017-04-05 12:58:15 +0300 |
---|---|---|
committer | Marcin Junczys-Dowmunt <junczys@amu.edu.pl> | 2017-04-05 12:58:15 +0300 |
commit | fdb4fa4c92eab1d90062144ef57e1ce970067c6b (patch) | |
tree | 16ded9eff53b0b0d4b4245e0ea721edd6ee74f40 | |
parent | dafd15d9a52bade8ba13295f8e040788e19860e3 (diff) | |
parent | 0097387283ec3c934317233aa94c7c477a4d5982 (diff) |
Merge branch 'master' into marian-integration
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | src/amun/cpu/dl4mt/decoder.h | 12 | ||||
-rw-r--r-- | src/amun/cpu/npz_converter.h | 36 |
3 files changed, 29 insertions, 24 deletions
@@ -146,3 +146,8 @@ The setting above uses 8 CPU threads and 4 GPU threads (2 GPUs x 2 threads). The ## Acknowledgements The development of Amunmt received funding from the European Union's Horizon 2020 Research and Innovation Programme under grant agreements 688139 (SUMMA; 2016-2019) and 645487 (Modern MT; 2015-2017) and the Amazon Academic Research Awards program. + + + + + diff --git a/src/amun/cpu/dl4mt/decoder.h b/src/amun/cpu/dl4mt/decoder.h index 607d41d8..b1c10e97 100644 --- a/src/amun/cpu/dl4mt/decoder.h +++ b/src/amun/cpu/dl4mt/decoder.h @@ -182,14 +182,13 @@ class Decoder { auto t = blaze::forEach(T1_ + T2_ + T3_, Tanh()); if(!filtered_) { - Probs_ = t * w_.W4_; - AddBiasVector<byRow>(Probs_, w_.B4_); + Probs = t * w_.W4_; + AddBiasVector<byRow>(Probs, w_.B4_); } else { - Probs_ = t * FilteredW4_; - AddBiasVector<byRow>(Probs_, FilteredB4_); + Probs = t * FilteredW4_; + AddBiasVector<byRow>(Probs, FilteredB4_); } - mblas::Softmax(Probs_); - Probs = blaze::forEach(Probs_, Log()); + LogSoftmax(Probs); } void Filter(const std::vector<size_t>& ids) { @@ -209,7 +208,6 @@ class Decoder { mblas::Matrix T1_; mblas::Matrix T2_; mblas::Matrix T3_; - mblas::Matrix Probs_; }; public: diff --git a/src/amun/cpu/npz_converter.h b/src/amun/cpu/npz_converter.h index 6bd2f692..7488ead7 100644 --- a/src/amun/cpu/npz_converter.h +++ b/src/amun/cpu/npz_converter.h @@ -12,55 +12,55 @@ class NpzConverter { public: NpyMatrixWrapper(const cnpy::NpyArray& npy) : npy_(npy) {} - + size_t size() const { return size1() * size2(); } - + float* data() const { return (float*)npy_.data; } - + float operator()(size_t i, size_t j) const { return ((float*)npy_.data)[i * size2() + j]; } - + size_t size1() const { return npy_.shape[0]; } - + size_t size2() const { if(npy_.shape.size() == 1) return 1; else - return npy_.shape[1]; + return npy_.shape[1]; } - + private: const cnpy::NpyArray& npy_; }; - + public: - + typedef blaze::CustomMatrix<float, blaze::unaligned, blaze::unpadded, blaze::rowMajor> BlazeWrapper; - - + + NpzConverter(const std::string& file) : model_(cnpy::npz_load(file)), destructed_(false) { } - + ~NpzConverter() { if(!destructed_) model_.destruct(); } - + void Destruct() { model_.destruct(); destructed_ = true; } - + mblas::Matrix operator[](const std::string& key) const { BlazeWrapper matrix; auto it = model_.find(key); @@ -69,14 +69,16 @@ class NpzConverter { matrix = BlazeWrapper(np.data(), np.size1(), np.size2()); } else { - std::cerr << "Missing " << key << std::endl; + if (key.find("gamma") == std::string::npos) { + std::cerr << "Missing " << key << std::endl; + } } mblas::Matrix ret; ret = matrix; return std::move(ret); } - + mblas::Matrix operator()(const std::string& key, bool transpose) const { BlazeWrapper matrix; @@ -91,7 +93,7 @@ class NpzConverter { ret = matrix2; return std::move(ret); } - + private: cnpy::npz_t model_; bool destructed_; |