Template Function torch::save(const Value&, SaveToArgs&&…)¶
Defined in File serialize.h
Function Documentation¶
-
template<typename Value, typename ...SaveToArgs>
void torch::save(const Value &value, SaveToArgs&&... args)¶ Serializes the given
value
.There must be an overload of
operator<<
betweenserialize::OutputArchive
andValue
for this method to be well-formed. Currently, such an overload is provided for (subclasses of):torch::Tensor
To perform the serialization, a
serialize::OutputArchive
is constructed, and all arguments after thevalue
are forwarded to itssave_to
method. For example, you can pass a filename, or anostream
.torch::nn::Linear model(3, 4); torch::save(model, "model.pt"); torch::optim::SGD sgd(model->parameters(), 0.9); // 0.9 is learning rate std::ostringstream stream; // Note that the same stream cannot be used in multiple torch::save(...) // invocations, otherwise the header will be corrupted. torch::save(sgd, stream); auto tensor = torch::ones({3, 4}); torch::save(tensor, "my_tensor.pt");