-
Notifications
You must be signed in to change notification settings - Fork 134
Self-adaptive translation mode for Marian (runtime domain adaptation). #887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rihardsk
wants to merge
143
commits into
marian-nmt:master
Choose a base branch
from
marian-cef:adaptive-whole-graph-recreate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
143 commits
Select commit
Hold shift + click to select a range
0eefedf
Dynamic swap working, as long as the vocabularies are the same
XapaJIaMnu 521f634
Model and GPUSlot separation, add vocab support
kpu 67190db
Add vocabulary padding script
kpu b165af8
Split code into main and library h/cpp
kpu 4d8e327
Restore ensemble support
kpu 203a9bb
Minor logging improvements
kpu c71d488
Return Histories
kpu 47feb2b
Alignments
kpu 8fc8d02
Fix enit
kpu b4bded3
Merge github.com:marian-nmt/marian-dev into dynamic_swap_mvp
kpu b9bc153
Merge https://github.com/kpu/marian-dev into dynamic_swap_mvp
kpu 9b3e76a
Add an option to force loading
kpu cf12178
Allow CPU only compilation
XapaJIaMnu 7e06801
Add explicit gpu device index when creating the object
XapaJIaMnu 635cfb0
Allow multiple mini-batches
XapaJIaMnu ee6ff75
No stringstreams
XapaJIaMnu 57ddeba
Sort the histories before returning them
XapaJIaMnu 4f2b218
SwappableSlot: add GPU-to-GPU reset feature
fa51460
Merge pull request #1 from davidecaroselli/dynamic_swap_mvp
XapaJIaMnu 2062438
Merge branch 'dynamic_swap_mvp' of https://github.com/kpu/marian-dev …
XapaJIaMnu e3f5388
Separate graph from loading to GPU
XapaJIaMnu ba4d166
Abort if not initialized
kpu f8523b7
Go back to Load instead of OverwriteFrom
kpu 8bcfdcc
Check device index
kpu a893f19
Start working on code to reproduce a bug i encountered
rihardsk 7f6d01e
Build the model implement a simplistic training loop
rihardsk f4e227e
Load config using the cli parser so that we can have default values f…
rihardsk dcb7122
Add dummy values for training sets in the config
rihardsk fcb9a61
Repeat the graph initialization in a cycle
rihardsk 6560067
Add a part of the self adaptive marian's implementation
rihardsk 7130800
Fix compatability issues with some new refactors in master
rihardsk 10cdffa
Fix options parsing issues
rihardsk 286a23c
Fix remaining input parsing issues
rihardsk 85685c6
Re-enable all of the adaptive code
rihardsk fca5fe4
Some further debugging, ugh
rihardsk 37b6aa4
Fix the way inputs are initialized
rihardsk f67015e
Output graphviz graphs for the training graph
rihardsk 78bcce1
Fix the segfault in the repro by moving the builder inside the loop
rihardsk 162a17c
Move the builder initialization inside run() to fix the segfault
rihardsk de49880
Use a dedicated builder for the adaptive graph to avoid segfaults
rihardsk 29415c7
Make a copy of all the swappable stuff to later adjust for training
rihardsk 5b28f1f
Implement training with swappable stuff
rihardsk 98b1ad1
Remove CPULoadedModelTrain in favor of just using CPULoadedModel
rihardsk d14da1b
Adapt self_adaptive.h to use the swappable stuff
rihardsk 07658fb
Fix some runtime issues related to configuration
rihardsk 06ee187
Fix issues woth vocab initialization and memory allocation
rihardsk c4ff8b9
Initialize the ExpressionGraph for translation with inference=true
rihardsk 16ec013
Seek to beginning of the istringstream when resetting text input
rihardsk a220a2b
When translating, directly use the trained parameters instead of load…
rihardsk 4f67aab
Ensure that SwapPointers is called an even number of times
rihardsk ea1380d
Get some params from the gpu memory for debugging
rihardsk dda5995
Retrieve some debugging information in SwapPointers
rihardsk 4e743bf
Attempt to load the io::Items representing parameters directly into t…
rihardsk 9e898b0
Only reserve memory not fill it with values when initializing the mem…
rihardsk e7d339b
Load params before building the graph, drop the F0:: prefix, clear pa…
rihardsk 26e7574
Try to clear the graph before loading the parameters in an attempt to…
rihardsk 58851ae
Recreate the graph upon every training invocation
rihardsk 2765e65
The wrong vocab was being passed to the printer
rihardsk c289397
Clean up and move memory piece extraction to a better place
rihardsk 20c893d
Rename for readability; remove commented out code; remove debugging code
rihardsk 724b910
Remove some redundant initialization code
rihardsk 7a79027
Make method naming consistent in GPUEngineTrain
rihardsk 1790ea1
Clean up some comments
rihardsk f8fe981
Simplify the training loop
rihardsk 4a4214a
Make CorpusBase understand that stdin is not a file
rihardsk 0c974eb
Move common training/translation stuff out into a separate method
rihardsk 1176c3f
Rename TrainSet{Reader,Iterator} to AdaptiveContext{Reader,Iterator}
rihardsk 79002cb
Add documentation comments for adaptive context reader classes
rihardsk 632d05f
Move self-adaptive data stuff to a separate file
rihardsk 95ed9af
Move method definitions from adaptive_context.h to .cpp
rihardsk 030ddb0
Introduce more whitespace for readability
rihardsk c90a4d7
Rename and move the adaptive translation function
rihardsk 448de67
Unhardcode the maximum translation input length parameter
rihardsk a6639ff
Compile adaptive_context.cpp conditionally
rihardsk bafcae1
Remove the marian_swapper executable
rihardsk afc5e15
Remove dead code from the model swapping code
rihardsk 6aeb510
Rename some swappable classes and improve documentation
rihardsk ad38da9
Describe the purpose of swappable.h
rihardsk 295040d
Explain the purpose of self-adaptive code
rihardsk 6311f2b
Improve comments in self-adaptive code
rihardsk 6bf3445
Check that param names and sizes match upon loading
rihardsk 5cac0d1
Fix amun model loading
rihardsk 1e1397d
Implement parameter name remapping for nematus models
rihardsk 3f9c088
Work around a crash in amun model loading
rihardsk d4ba1fa
Don't crash when training sets not provided
rihardsk 24e8fc3
Copy over the self-adaptive server example script from an older commit
rihardsk d68fd73
Clean up logging
rihardsk 324f69a
Remove a config option for swappable stuff that isn't used any more
rihardsk fa5f9f1
Merge branch 'master' into adaptive-whole-graph-recreate
rihardsk 7f43074
Disable early stopping for self-adaptive training
rihardsk d7676bd
Forgot to remove a file that was used for debugging
rihardsk e48e737
Update CHANGELOG.md
rihardsk 017b6c1
Fix CPU-only compilation
rihardsk 1257a45
Add a virtual destructor to CollectorBase
rihardsk 96115c8
Fix casing in the `COMPILE_ADAPTIVE` cmake option's description
rihardsk ba61acd
Split out marian-adaptive server mode into a separate executable
rihardsk 2e7e78f
Remove marian-adaptive from the .zip and .tgz targets
rihardsk 0084a3a
Remove a comment that was made obsolete by the grandparrent commit (b…
rihardsk 30c0400
Change the defaultDispFreq option to use an unsigned value
rihardsk 2fbb6ec
Fix indentation
rihardsk d09c021
Fix indentation
rihardsk 10d5bff
Remove @brief from doc comments
rihardsk d41d81b
Remove commented out debugging code
rihardsk fde2226
Don't split the line here
rihardsk e407587
Fix indentation
rihardsk b869f68
Make it clear that validation options are disabled
rihardsk e04b829
Delete the pad_model_vocabulary.py script
rihardsk 939384b
Comment on why data management options are disabled for self-adaptive…
rihardsk 92aaeea
Explain the max-length-translate option; fix the default for max-lengt
rihardsk 99553d5
Remove an obsolete comment
rihardsk 8aec3ca
Remove excessive empty lines
rihardsk 971e1dc
Split some long lines
rihardsk f3a085c
Forgot to add the marian_adaptive_server.cpp file to git
rihardsk bcbeb2d
Document the toMemoryPieces method
rihardsk 2667ea9
Delete some more @briefs
rihardsk 5b28786
Comment on a possibly missing "training-sets" option
rihardsk 097effa
Remove unneeded member variables and describe member var usage
rihardsk 507f8eb
Document some methods
rihardsk d797c90
Don't suggest looking at commits because they'll get squashed
rihardsk babf93d
Add a comment on stdin handling in CorpusBase
rihardsk 2d1ff23
Fix a typo
rihardsk 6955a9a
Document the `dropF0prefix` flag
rihardsk 20cde20
Enable option validation for adaptive marian
rihardsk bbe5196
Add usage instructions to the adaptive/client_example.py script
rihardsk 85d831f
Mention the tutorial repo as well
rihardsk 7bb887a
Add punctiation for clarity
rihardsk 9f03070
Fix a typo in a comment
rihardsk 96615e7
Fix a typo in a comment
rihardsk d4a77ba
Fix a typo in a comment
rihardsk 379418b
Revert an added space
rihardsk 4bb6f5c
Clarify the server mode handling in ConfigParser
rihardsk c41a56b
Remove TSV options from self-adaptive translation
rihardsk 6c97f82
Share code between marian-server and marian-adaptive-server
rihardsk 88308a7
Don't require a "models" option for self-adaptive translation
rihardsk 08d20d5
Fix crashes introduced by removing some options from self-adaptive ma…
rihardsk 1326bb1
Disable parallel data validation for self-adaptive server mode
rihardsk 56cfb37
Introduce a separate workspace size option for the translation graph
rihardsk d9cddf4
Fix alignment printing during translation
rihardsk 892fed4
Merge remote-tracking branch 'upstream/master' into adaptive-whole-gr…
rihardsk 3359bb7
Change "training-sets" to "train-sets"
snukky 22230dd
Merge pull request #9 from marian-cef/adaptive-whole-graph-recreate-p…
kpu ea169a4
Merge branch 'master' into adaptive-whole-graph-recreate
rihardsk a274dfb
Mention marian-adaptive-server in the changelog
rihardsk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| # This is an example for using self-adaptive translation in server mode. | ||
| # | ||
| # To run: | ||
| # 1. Start self-adaptive Marian in server mode, e.g.: | ||
| # ./build/marian-adaptive-server -p 8080 -m model.npz -v vocap.yaml vocab.yaml \ | ||
| # --after-batches 10 --after-epochs 10 --learn-rate 0.1 --mini-batch 15 # other options | ||
| # 2. In a new shell, run this script: | ||
| # python3 ./scripts/self-adaptive/client_exmaple.py -p 8080 | ||
| # | ||
| # For a more extensive example, see https://github.com/marian-cef/marian-examples/tree/master/adaptive | ||
| # or https://github.com/tilde-nlp/runtime-domain-adaptation-tutorial | ||
|
|
||
| from __future__ import print_function, unicode_literals, division | ||
|
|
||
| import sys | ||
| import time | ||
| import argparse | ||
| import json | ||
|
|
||
| from websocket import create_connection | ||
|
|
||
|
|
||
| def translate(batch, port=8080): | ||
| ws = create_connection("ws://localhost:{}/translate".format(port)) | ||
| ws.send(batch) | ||
| result = ws.recv() | ||
| ws.close() | ||
| return result.rstrip() | ||
|
|
||
|
|
||
| def parse_args(): | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("-p", "--port", type=int, default=8080) | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| args = parse_args() | ||
|
|
||
| # List of input sentences separated by a new line character | ||
| inputs = "this is an example\nthe second sentence\nno context provided" | ||
| # For each input sentence a list of parallel sentences can be provided as a | ||
| # list of source and target sentences. | ||
| contexts = [ | ||
| # Source-side context for the first input sentence | ||
| ["this is a test\nthese are examples", | ||
| # Target-side context for the first input sentence | ||
| "das ist ein test\ndies sind Beispiele"], | ||
| # Only one example is given as a context for the second input sentence | ||
| ["the next sentence", | ||
| "der nächste Satz"], | ||
| # No context for the third input sentence | ||
| [] | ||
| ] | ||
|
|
||
| input_data = {'input': inputs, 'context': contexts} | ||
| input_json = json.dumps(input_data) | ||
|
|
||
| output_json = translate(input_json, port=args.port) | ||
| output_data = json.loads(output_json) | ||
| print(output_data['output']) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #include "marian.h" | ||
|
|
||
| #include "common/timer.h" | ||
| #include "common/utils.h" | ||
| #include "training/training.h" | ||
| #include "translator/self_adaptive.h" | ||
|
|
||
| using namespace marian; | ||
|
|
||
| int main(int argc, char **argv) { | ||
| auto options = parseOptions(argc, argv, cli::mode::selfadaptive); | ||
| auto task = New<TrainSelfAdaptive>(options); | ||
|
|
||
| timer::Timer timer; | ||
| task->run(); | ||
| LOG(info, "Total time: {:.5f}s", timer.elapsed()); | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #include "translator/self_adaptive.h" | ||
| #include "translator/server_common.h" | ||
|
|
||
| int main(int argc, char **argv) { | ||
| using namespace marian; | ||
|
|
||
| auto options = parseOptions(argc, argv, cli::mode::selfadaptiveServer); | ||
| auto task = New<TrainSelfAdaptive>(options); | ||
rihardsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return runServer(task, options); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,62 +1,11 @@ | ||
| #include "marian.h" | ||
| #include "translator/beam_search.h" | ||
| #include "translator/server_common.h" | ||
| #include "translator/translator.h" | ||
| #include "common/timer.h" | ||
| #include "common/utils.h" | ||
|
|
||
| #include "3rd_party/simple-websocket-server/server_ws.hpp" | ||
|
|
||
| typedef SimpleWeb::SocketServer<SimpleWeb::WS> WSServer; | ||
|
|
||
| int main(int argc, char **argv) { | ||
| using namespace marian; | ||
|
|
||
| // Initialize translation task | ||
| auto options = parseOptions(argc, argv, cli::mode::server, true); | ||
| auto task = New<TranslateService<BeamSearch>>(options); | ||
| auto quiet = options->get<bool>("quiet-translation"); | ||
|
|
||
| // Initialize web server | ||
| WSServer server; | ||
| server.config.port = (short)options->get<size_t>("port", 8080); | ||
|
|
||
| auto &translate = server.endpoint["^/translate/?$"]; | ||
|
|
||
| translate.on_message = [&task, quiet](Ptr<WSServer::Connection> connection, | ||
| Ptr<WSServer::InMessage> message) { | ||
| // Get input text | ||
| auto inputText = message->string(); | ||
| auto sendStream = std::make_shared<WSServer::OutMessage>(); | ||
|
|
||
| // Translate | ||
| timer::Timer timer; | ||
| auto outputText = task->run(inputText); | ||
| *sendStream << outputText << std::endl; | ||
| if(!quiet) | ||
| LOG(info, "Translation took: {:.5f}s", timer.elapsed()); | ||
|
|
||
| // Send translation back | ||
| connection->send(sendStream, [](const SimpleWeb::error_code &ec) { | ||
| if(ec) | ||
| LOG(error, "Error sending message: ({}) {}", ec.value(), ec.message()); | ||
| }); | ||
| }; | ||
|
|
||
| // Error Codes for error code meanings | ||
| // http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/reference.html | ||
| translate.on_error = [](Ptr<WSServer::Connection> /*connection*/, | ||
| const SimpleWeb::error_code &ec) { | ||
| LOG(error, "Connection error: ({}) {}", ec.value(), ec.message()); | ||
| }; | ||
|
|
||
| // Start server thread | ||
| std::thread serverThread([&server]() { | ||
| server.start([](unsigned short port) { | ||
| LOG(info, "Server is listening on port {}", port); | ||
| }); | ||
| }); | ||
|
|
||
| serverThread.join(); | ||
|
|
||
| return 0; | ||
| return runServer(task, options); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.