Class InputArchive¶
Defined in File input-archive.h
Page Contents
Class Documentation¶
-
class InputArchive¶
A recursive representation of tensors that can be deserialized from a file or stream.
In most cases, users should not have to interact with this class, and should instead use
torch::load
.Public Functions
-
InputArchive()¶
Default-constructs the
InputArchive
.
-
InputArchive(InputArchive&&) = default¶
-
InputArchive &operator=(InputArchive&&) = default¶
-
InputArchive(InputArchive&) = delete¶
-
InputArchive &operator=(InputArchive&) = delete¶
-
~InputArchive() = default¶
-
void read(const std::string &key, c10::IValue &ivalue)¶
Reads an
IValue
associated with a givenkey
.
-
bool try_read(const std::string &key, c10::IValue &ivalue)¶
Reads an
IValue
associated with a givenkey
.If there is no
IValue
associated with thekey
, this returns false, otherwise it returns true.
-
bool try_read(const std::string &key, Tensor &tensor, bool is_buffer = false)¶
Reads a
tensor
associated with a givenkey
.If there is no
tensor
associated with thekey
, this returns false, otherwise it returns true. If the tensor is expected to be a buffer (not differentiable),is_buffer
must betrue
.
-
void read(const std::string &key, Tensor &tensor, bool is_buffer = false)¶
Reads a
tensor
associated with a givenkey
.If the tensor is expected to be a buffer (not differentiable),
is_buffer
must betrue
.
-
bool try_read(const std::string &key, InputArchive &archive)¶
Reads a
InputArchive
associated with a givenkey
.If there is no
InputArchive
associated with thekey
, this returns false, otherwise it returns true.
-
void read(const std::string &key, InputArchive &archive)¶
Reads an
InputArchive
associated with a givenkey
.The archive can thereafter be used for further deserialization of the nested data.
-
void load_from(const std::string &filename, std::optional<torch::Device> device = std::nullopt)¶
Loads the
InputArchive
from a serialized representation stored in the file atfilename
.Storage are remapped using device option. If device is not specified, the module is loaded to the original device.
-
void load_from(std::istream &stream, std::optional<torch::Device> device = std::nullopt)¶
Loads the
InputArchive
from a serialized representation stored in the givenstream
.Storage are remapped using device option. If device is not specified, the module is loaded to the original device.
-
void load_from(const char *data, size_t size, std::optional<torch::Device> device = std::nullopt)¶
-
void load_from(const std::function<size_t(uint64_t pos, void *buf, size_t nbytes)> &read_func, const std::function<size_t(void)> &size_func, std::optional<torch::Device> device = std::nullopt)¶
-
std::vector<std::string> keys()¶
-
template<typename ...Ts>
inline void operator()(Ts&&... ts)¶ Forwards all arguments to
read()
.Useful for generic code that can be re-used for both
InputArchive
andOutputArchive
(whereoperator()
forwards towrite()
).
-
InputArchive()¶