DyNet provides C++ interfaces for users to save and restore model parameters. The user has two options for saving a model. In the most basic use case, a complete ParameterCollection object can be saved. At loading time, the user should define and allocate the same parameter variables that were present in the model when it was saved (this usually amounts to having the same parameter creation called by both code paths), and then call populate and pass in the ParameterCollection object containing the parameters that should be loaded.

#include <dynet/io.h>
// save end
ParameterCollection m;
{
dynet::TextFileSaver s("/tmp/tmp.model");
s.save(m);
}

ParameterCollection m;
{
l.populate(m);
}


However, in some cases it is useful to save only a subset of parameter objects(for example, if users wish to load these in a pretraining setup). Here, Parameter or LookupParameter objects can be saved explicitly. User could also specify keys for partial saving and loading.

#include <dynet/io.h>
// save end
ParameterCollection m1, m2;
{
dynet::TextFileSaver s("/tmp/tmp.model");
s.save(m1, "/namespace_tmp/");
s.save(param_b, "param_b");
}

ParameterCollection m;
{
l.populate(m, "/namespace_tmp/");
l.populate(param_b, "param_b");
}

// user can use equivalent interfaces to load model parameters
ParameterCollection m;
Parameter param_a, param_b;
LookupParameter l_param;
{

Currently, DyNet only supports plain text format. The native format is quite simple so very readable. The model file is consist of basic storage blocks. A basic block starts with a first line of meta data information: #object_type# object_name dimension block_size and the remaining part of real data. During loading process, DyNet uses meta data lines to locate the objects user wants to load.