Saving Model in OpenNMT-Py API

Hi everyone, I’m new in NMT and decided to start with OpenNMT-Py.

I am currently using the API of OpenNMT-Py for my research work, and I’m following the guides in the documentation here

I can successfully train a model, but i’m not sure how can I save the model and use it for inference/prediction purposes.

As I’m reading through the docs, there is a parameter called model_saver in the Training class that has the following desciption:

model_saver ( onmt.models.ModelSaverBase ) – the saver is used to save a checkpoint. Thus nothing will be saved if this parameter is None

I’m not sure what do I need to provide in the model_saver parameter for me to use it as an API/Library rather than directly using the and passing a parameter to save a model. similar to OpenNMT-Py’s official example in the docs: I’m figuring out how can I save a model if I’m implementing OpenNMT-Py as an API/Library.

Thank you.

here is a pointer:
but honestly you’d bettter go through the all file to undertstand how things work.

model_saver = onmt.models.ModelSaver(opt=‘saved_model’, model=model, model_opt=, fields=vocab_fields, optim=optim, keep_checkpoint=1)

any idea what do I need to provide in the model_opt parameter? I’m having a hard time tracing it on the codebase. it seems like it’s the args that’s being passed when you run the script, but I want to try to create a model using the Model subclassing/Opennmt library. I tried to pass an empty string the model_opt parameter, and I was able to save/download a model, but I’m getting an error when I try to test the model itself, so I figured that I maybe have to really look into what I am passing on the model_opt parameter.

model_opt is an argparse Namespace.
You can have a look around onmt.opts and onmt.utils.parse for details.