Template Function torch::save(const std::vector<torch::Tensor>&, SaveToArgs&&…)¶
Defined in File serialize.h
Function Documentation¶
-
template<typename ...SaveToArgs>
void torch::save(const std::vector<torch::Tensor> &tensor_vec, SaveToArgs&&... args)¶ Serializes the given
tensor_vec
of typestd::vector<torch::Tensor>
.To perform the serialization, a
serialize::OutputArchive
is constructed, and all arguments after thetensor_vec
are forwarded to itssave_to
method. For example, you can pass a filename, or anostream
.std::vector<torch::Tensor> tensor_vec = { torch::randn({1, 2}), torch::randn({3, 4}) }; torch::save(tensor_vec, "my_tensor_vec.pt"); std::vector<torch::Tensor> tensor_vec = { torch::randn({5, 6}), torch::randn({7, 8}) }; std::ostringstream stream; // Note that the same stream cannot be used in multiple torch::save(...) // invocations, otherwise the header will be corrupted. torch::save(tensor_vec, stream);