To expand on this question, In C++ I can save and load an entire model with parameters using:

torch::save(network, “network_and_weights.pt”);
torch::load(network, “network_and_weights.pt”);

But there does not seem to be a way to save and load just the weights in C++. In Python you can do this with:

torch.save(model.state_dict(), “weights.pt”)
model.load_state_dict(torch.load(“weights.pt”))
The only thing I found in C++ that might be how to save is:


torch::save(network->parameters(), “weights.pt”);

But there is no comparable C++ function to load… I was hoping for something like:

network->load_parameters(torch::load(“weights.pt”));

Saving and loading just the weights seems like such a fundamental aspect of using a framework, and being able to export to ONNX also seems fundamental. I feel like I’m missing something obvious. Is there anyone out there who can help explain how to save/load weights and export to ONNX using C++?
Thanks