The first approach we can use to save model parameters is using the torch::save function, which recursively saves parameters from the passed module:
torch::save(model, "pytorch_net.pt");
To use it correctly with our custom modules, we need to register all the submodules in the parent one with the register_module module's method.
To load the saved parameters, we can use the torch::load function:
Net model_loaded;
torch::load(model_loaded, "pytorch_net.pt");
The function fills the passed module parameters with the values that are read from a file.