From 3d78969785a5f790b84d3db4fa91662c1775db66 Mon Sep 17 00:00:00 2001 From: Tomasz Dwojak Date: Tue, 7 Feb 2017 23:38:37 +0000 Subject: [PATCH 1/8] Repair indents in god.cpp --- src/common/god.cpp | 49 +++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/src/common/god.cpp b/src/common/god.cpp index 20c0faa1..eaad4317 100644 --- a/src/common/god.cpp +++ b/src/common/god.cpp @@ -22,20 +22,22 @@ using namespace std; namespace amunmt { God::God() -:threadIncr_(0) + : threadIncr_(0) { - } -God::~God() {} +God::~God() +{ +} God& God::Init(const std::string& options) { std::vector args = boost::program_options::split_unix(options); int argc = args.size() + 1; char* argv[argc]; argv[0] = const_cast("bogus"); - for(int i = 1; i < argc; i++) + for (int i = 1; i < argc; ++i) { argv[i] = const_cast(args[i-1].c_str()); + } return Init(argc, argv); } @@ -49,35 +51,35 @@ God& God::Init(int argc, char** argv) { config_.AddOptions(argc, argv); config_.LogOptions(); - if(Get("source-vocab").IsSequence()) { - for(auto sourceVocabPath : Get>("source-vocab")) - sourceVocabs_.emplace_back(new Vocab(sourceVocabPath)); - } - else { - sourceVocabs_.emplace_back(new Vocab(Get("source-vocab"))); + if (Get("source-vocab").IsSequence()) { + for (auto sourceVocabPath : Get>("source-vocab")) { + sourceVocabs_.emplace_back(new Vocab(sourceVocabPath)); + } + } else { + sourceVocabs_.emplace_back(new Vocab(Get("source-vocab"))); } targetVocab_.reset(new Vocab(Get("target-vocab"))); weights_ = Get>("weights"); if(Get("show-weights")) { - LOG(info) << "Outputting weights and exiting"; - for(auto && pair : weights_) { - std::cout << pair.first << "= " << pair.second << std::endl; - } - exit(0); + LOG(info) << "Outputting weights and exiting"; + for(auto && pair : weights_) { + std::cout << pair.first << "= " << pair.second << std::endl; + } + exit(0); } LoadScorers(); LoadFiltering(); if (Has("input-file")) { - LOG(info) << "Reading from " << Get("input-file"); - inputStream_.reset(new InputFileStream(Get("input-file"))); + LOG(info) << "Reading from " << Get("input-file"); + inputStream_.reset(new InputFileStream(Get("input-file"))); } else { - LOG(info) << "Reading from stdin"; - inputStream_.reset(new InputFileStream(std::cin)); + LOG(info) << "Reading from stdin"; + inputStream_.reset(new InputFileStream(std::cin)); } LoadPrePostProcessing(); @@ -184,11 +186,9 @@ std::vector God::GetScorers(const DeviceInfo &deviceInfo) const { std::vector scorers; if (deviceInfo.deviceType == CPUDevice) { - //cerr << "CPU GetScorers" << endl; for (auto&& loader : cpuLoaders_ | boost::adaptors::map_values) scorers.emplace_back(loader->NewScorer(*this, deviceInfo)); } else { - //cerr << "GPU GetScorers" << endl; for (auto&& loader : gpuLoaders_ | boost::adaptors::map_values) scorers.emplace_back(loader->NewScorer(*this, deviceInfo)); } @@ -233,14 +233,12 @@ std::vector God::Postprocess(const std::vector& input) } return processed; } -// clean up cuda vectors before cuda context goes out of scope + void God::CleanUp() { for (Loaders::value_type& loader : cpuLoaders_) { - //cerr << "cpu loader=" << loader.first << endl; loader.second.reset(nullptr); } for (Loaders::value_type& loader : gpuLoaders_) { - //cerr << "gpu loader=" << loader.first << endl; loader.second.reset(nullptr); } } @@ -271,7 +269,6 @@ DeviceInfo God::GetNextDevice() const ++threadIncr_; - //cerr << "GetNextDevice=" << ret << endl; return ret; } @@ -283,12 +280,10 @@ Search &God::GetSearch() const boost::shared_lock read_lock(accessLock_); obj = search_.get(); if (obj) { - // found exiting obj return *obj; } } - // create new obj boost::unique_lock lock(accessLock_); obj = new Search(*this); search_.reset(obj); From 66fef0804412968e15e44d1d8d48da5cd0c601ef Mon Sep 17 00:00:00 2001 From: Tomasz Dwojak Date: Thu, 9 Feb 2017 17:56:36 +0000 Subject: [PATCH 2/8] Change Jenkins server from fatboy to uedin's Vali --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b044a0a6..f9389cb6 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # AmuNMT [![Join the chat at https://gitter.im/amunmt/amunmt](https://badges.gitter.im/amunmt/amunmt.svg)](https://gitter.im/amunmt/amunmt?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![CUDA build Status](http://37.247.57.181:8000/job/amunmt_compilation_cuda/badge/icon)](http://37.247.57.181:8000/job/amunmt_compilation_cuda/) -[![CPU Build Status](http://37.247.57.181:8000/job/amunmt_compilation_cpu/badge/icon)](http://37.247.57.181:8000/job/amunmt_compilation_cpu/) + +[![CUDA Build Status](http://vali.inf.ed.ac.uk/jenkins/job/amunmt_compilation_cuda/badge/icon)](http://vali.inf.ed.ac.uk/jenkins/job/amunmt_compilation_cpu/) +[![CPU Build Status](http://vali.inf.ed.ac.uk/jenkins/job/amunmt_compilation_cpu/badge/icon)](http://vali.inf.ed.ac.uk/jenkins/job/amunmt_compilation_cpu/) A C++ inference engine for Neural Machine Translation (NMT) models trained with Theano-based scripts from Nematus (https://github.com/rsennrich/nematus) or DL4MT (https://github.com/nyu-dl/dl4mt-tutorial) From 8d641fd092433cfb60f0811455970b252d3170f9 Mon Sep 17 00:00:00 2001 From: Tomasz Dwojak Date: Thu, 9 Feb 2017 18:07:14 +0000 Subject: [PATCH 3/8] Fix cuda compilation badge --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f9389cb6..d0b71d2d 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,9 @@ # AmuNMT [![Join the chat at https://gitter.im/amunmt/amunmt](https://badges.gitter.im/amunmt/amunmt.svg)](https://gitter.im/amunmt/amunmt?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![CUDA Build Status](http://vali.inf.ed.ac.uk/jenkins/job/amunmt_compilation_cuda/badge/icon)](http://vali.inf.ed.ac.uk/jenkins/job/amunmt_compilation_cpu/) -[![CPU Build Status](http://vali.inf.ed.ac.uk/jenkins/job/amunmt_compilation_cpu/badge/icon)](http://vali.inf.ed.ac.uk/jenkins/job/amunmt_compilation_cpu/) +[![CUDABuild Status](http://vali.inf.ed.ac.uk/jenkins/buildStatus/icon?job=amunmt_compilation_cuda)](http://vali.inf.ed.ac.uk/jenkins/job/amunmt_compilation_cuda/) +[![CPU Build Status](http://vali.inf.ed.ac.uk/jenkins/buildStatus/icon?job=amunmt_compilation_cpu)](http://vali.inf.ed.ac.uk/jenkins/job/amunmt_compilation_cpu/) + A C++ inference engine for Neural Machine Translation (NMT) models trained with Theano-based scripts from Nematus (https://github.com/rsennrich/nematus) or DL4MT (https://github.com/nyu-dl/dl4mt-tutorial) From 5227095ece2c0ddb62e1d7f6e78a02d188866a59 Mon Sep 17 00:00:00 2001 From: Marcin Junczys-Dowmunt Date: Thu, 9 Feb 2017 19:26:36 +0000 Subject: [PATCH 4/8] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d0b71d2d..c7d9244b 100644 --- a/README.md +++ b/README.md @@ -95,13 +95,13 @@ AmuNMT has integrated support for [BPE encoding](https://github.com/rsennrich/su debpe: true ## Using GPU/CPU threads -AmuNMT can use GPUs, CPUs, or both, to distribute translation of different sentences. +AmuNMT can use GPUs, CPUs, or both, to distribute translation of different sentences. 'However, it is unlikely that CPUs used together with GPUs yield any performance improvement. It is probably better to only use the GPU if one or more are available.' cpu-threads: 8 gpu-threads: 2 devices: [0, 1] -The setting above uses 8 CPU threads and 4 GPU threads (2 GPUs x 2 threads). The `gpu-threads` and `devices` options are only available when AmuNMT has been compiled with CUDA support. Multiple GPU threads can be used to increase GPU saturation, but will likely not result in a large performance boost. By default, `gpu-threads` is set to `1` and `cpu-threads` to `0` if CUDA is available. Otherwise `cpu-threads` is set to `1`. To disable the GPU set `gpu-threads` to `0`. Setting both `gpu-threads` and `cpu-threads` to `0` will result in an exception. +The setting above uses 8 CPU threads and 4 GPU threads (2 GPUs x 2 threads). The `gpu-threads` and `devices` options are only available when AmuNMT has been compiled with CUDA support. Multiple GPU threads can be used to increase GPU saturation, but will likely not result in a large performance boost. By default, `gpu-threads` is set to `1` and `cpu-threads` to `0` if CUDA is available. Otherwise `cpu-threads` is set to `1`. To disable the GPU set `gpu-threads` to `0`. Setting both `gpu-threads` and `cpu-threads` to `0` will result in an exception. ## Example usage From 09082d6be9002e7102f066a9236bb3ab7d8ef645 Mon Sep 17 00:00:00 2001 From: Marcin Junczys-Dowmunt Date: Thu, 9 Feb 2017 19:28:04 +0000 Subject: [PATCH 5/8] bold warning --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c7d9244b..a61487a9 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ AmuNMT has integrated support for [BPE encoding](https://github.com/rsennrich/su debpe: true ## Using GPU/CPU threads -AmuNMT can use GPUs, CPUs, or both, to distribute translation of different sentences. 'However, it is unlikely that CPUs used together with GPUs yield any performance improvement. It is probably better to only use the GPU if one or more are available.' +AmuNMT can use GPUs, CPUs, or both, to distribute translation of different sentences. **However, it is unlikely that CPUs used together with GPUs yield any performance improvement. It is probably better to only use the GPU if one or more are available.** cpu-threads: 8 gpu-threads: 2 From 43f3f30c08a516f32686fd0af2c8263e1d9e44b8 Mon Sep 17 00:00:00 2001 From: Tomasz Dwojak Date: Fri, 10 Feb 2017 10:22:53 +0000 Subject: [PATCH 6/8] Change target name for python bindings to 'python' --- src/CMakeLists.txt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bdb7c2b7..a786b48d 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,7 +64,7 @@ cuda_add_executable( ) if(PYTHONLIBS_FOUND) -cuda_add_library(amunmt SHARED +cuda_add_library(python SHARED python/amunmt.cpp # gpu/decoder/ape_penalty.cu gpu/decoder/encoder_decoder.cu @@ -80,7 +80,9 @@ cuda_add_library(amunmt SHARED $ $ ) -set_target_properties("amunmt" PROPERTIES EXCLUDE_FROM_ALL 1) +set_target_properties("python" PROPERTIES EXCLUDE_FROM_ALL 1) +set_target_properties("python" PROPERTIES OUTPUT_NAME "amunmt") + endif(PYTHONLIBS_FOUND) cuda_add_library(mosesplugin STATIC @@ -116,7 +118,7 @@ add_executable( ) if(PYTHONLIBS_FOUND) -add_library(amunmt SHARED +add_library(python SHARED python/amunmt.cpp common/loader_factory.cpp $ @@ -124,14 +126,15 @@ add_library(amunmt SHARED $ $ ) -set_target_properties("amunmt" PROPERTIES EXCLUDE_FROM_ALL 1) +set_target_properties("python" PROPERTIES EXCLUDE_FROM_ALL 1) +set_target_properties("python" PROPERTIES OUTPUT_NAME "amunmt") endif(PYTHONLIBS_FOUND) endif(CUDA_FOUND) SET(EXES "amun") if(PYTHONLIBS_FOUND) -SET(EXES ${EXES} "amunmt") +SET(EXES ${EXES} "python") endif(PYTHONLIBS_FOUND) foreach(exec ${EXES}) From ed125905cc7896fca4b0fbf122066bd7757ef6cb Mon Sep 17 00:00:00 2001 From: Tomasz Dwojak Date: Fri, 10 Feb 2017 10:50:56 +0000 Subject: [PATCH 7/8] Add description about Python bindings --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index a61487a9..09131872 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,27 @@ AmuNMT has integrated support for [BPE encoding](https://github.com/rsennrich/su bpe: bpe.codes debpe: true +## Python Bindings + +Python bindings allow to run AmuNMT decoder in python scripts. The compilation of the bindings requires `python-dev` package. To compile the bindings run: +``` +make python +``` + +The Python bindings consist of 2 function: `init` and `translate`: + +```python +import libamunmt + +libamunmt.init('-c config.yml') +print libamunmt.translate(['this is a little test .']) +``` + +The `init` function init the decoder and the syntax is the same as in command line. The `translate` +function takes a list of sentences to translate. The `scripts/amunmt_erver.py` script uses python +bindings to run REST server. + + ## Using GPU/CPU threads AmuNMT can use GPUs, CPUs, or both, to distribute translation of different sentences. **However, it is unlikely that CPUs used together with GPUs yield any performance improvement. It is probably better to only use the GPU if one or more are available.** From c92bc649947acf7452be1a1b2d7a78d8ec9a2a89 Mon Sep 17 00:00:00 2001 From: Tomasz Dwojak Date: Fri, 10 Feb 2017 10:57:59 +0000 Subject: [PATCH 8/8] Update README: bindings section --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 09131872..184a72cc 100644 --- a/README.md +++ b/README.md @@ -111,8 +111,8 @@ print libamunmt.translate(['this is a little test .']) ``` The `init` function init the decoder and the syntax is the same as in command line. The `translate` -function takes a list of sentences to translate. The `scripts/amunmt_erver.py` script uses python -bindings to run REST server. +function takes a list of sentences to translate. For real-world example, see the `scripts/amunmt_erver.py` +script, which uses python bindings to run REST server. ## Using GPU/CPU threads