Template Function torch::save(const std::vector<torch::Tensor>&, SaveToArgs&&…)

Function Documentation

template<typename ...SaveToArgs>
void torch::save(const std::vector<torch::Tensor> &tensor_vec, SaveToArgs&&... args)

Serializes the given tensor_vec of type std::vector<torch::Tensor>.

To perform the serialization, a serialize::OutputArchive is constructed, and all arguments after the tensor_vec are forwarded to its save_to method. For example, you can pass a filename, or an ostream.

std::vector<torch::Tensor> tensor_vec = { torch::randn({1, 2}), torch::randn({3, 4}) };
torch::save(tensor_vec, "");

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);


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