Template Function torch::load(Value&, LoadFromArgs&&…)

Function Documentation

template<typename Value, typename ...LoadFromArgs>
void torch::load(Value &value, LoadFromArgs&&... args)

Deserializes the given value.

There must be an overload of operator>> between serialize::InputArchive and Value for this method to be well-formed. Currently, such an overload is provided for (subclasses of):

To perform the serialization, a serialize::InputArchive is constructed, and all arguments after the value are forwarded to its load_from method. For example, you can pass a filename, or an istream.

torch::nn::Linear model(3, 4);
torch::load(model, "");

torch::optim::SGD sgd(/*lr=*/0.9);
std::istringstream stream("...");
torch::load(sgd, stream);

auto tensor = torch::ones({3, 4});
torch::load(tensor, "");


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources