Files
pytorch/torch/csrc/jit/serialization/import.h
PyTorch MergeBot 846bb30e13 Revert "[1/N] Change #include <c10/util/Optional.h> to #include <optional> (#128301)"
This reverts commit bd72e28314d8d63bb347becb8309f5ac7761c6b5.

Reverted https://github.com/pytorch/pytorch/pull/128301 on behalf of https://github.com/huydhn due to Sorry for reverting your change but it fails XLA build bd72e28314. Please rebase your PR before relanding because I think the failure is hidden by an unrelated broken trunk XLA failure from your current base commit ([comment](https://github.com/pytorch/pytorch/pull/128301#issuecomment-2169035822))
2024-06-15 01:58:20 +00:00

158 lines
4.9 KiB
C++

#pragma once
#include <ATen/core/ivalue.h>
#include <caffe2/serialize/inline_container.h>
#include <torch/csrc/jit/api/module.h>
#include <torch/csrc/jit/ir/ir.h>
#include <istream>
namespace caffe2 {
namespace serialize {
class ReadAdapterInterface;
} // namespace serialize
} // namespace caffe2
namespace torch {
namespace jit {
class DeserializationStorageContext;
TORCH_API Module import_ir_module(
std::shared_ptr<CompilationUnit> cu,
const std::string& filename,
std::optional<c10::Device> device = c10::nullopt,
bool load_debug_files = true);
TORCH_API Module import_ir_module(
std::shared_ptr<CompilationUnit> cu,
std::istream& in,
std::optional<c10::Device> device = c10::nullopt,
bool load_debug_files = true);
TORCH_API Module import_ir_module(
std::shared_ptr<CompilationUnit> cu,
std::unique_ptr<caffe2::serialize::ReadAdapterInterface> rai,
std::optional<c10::Device> device = c10::nullopt,
bool load_debug_files = true);
TORCH_API Module import_ir_module(
std::shared_ptr<CompilationUnit> cu,
const std::string& filename,
std::optional<c10::Device> device,
ExtraFilesMap& extra_files,
bool load_debug_files = true,
bool restore_shapes = false);
// For reading unified serialization format from torch.Package
TORCH_API Module import_ir_module(
std::shared_ptr<CompilationUnit> cu,
std::shared_ptr<caffe2::serialize::PyTorchStreamReader> reader,
std::shared_ptr<torch::jit::DeserializationStorageContext> storage_context,
std::optional<at::Device> device,
std::string ts_id /* torchscript identifier inside package */);
TORCH_API Module import_ir_module(
std::shared_ptr<CompilationUnit> cu,
std::istream& in,
std::optional<c10::Device> device,
ExtraFilesMap& extra_files,
bool load_debug_files = true,
bool restore_shapes = false);
TORCH_API Module import_ir_module(
std::shared_ptr<CompilationUnit> cu,
std::unique_ptr<caffe2::serialize::ReadAdapterInterface> rai,
std::optional<c10::Device> device,
ExtraFilesMap& extra_files,
bool load_debug_files = true);
TORCH_API Module import_ir_module(
std::shared_ptr<CompilationUnit> cu,
std::shared_ptr<caffe2::serialize::ReadAdapterInterface> rai,
std::optional<c10::Device> device,
ExtraFilesMap& extra_files,
bool load_debug_files = true);
/// Loads a serialized `Module` from the given `istream`.
///
/// The istream must contain a serialized `Module`, exported via
/// `torch::jit::ExportModule` in C++.
TORCH_API Module load(
std::istream& in,
std::optional<c10::Device> device = c10::nullopt,
bool load_debug_files = true);
TORCH_API Module load(
std::istream& in,
std::optional<c10::Device> device,
ExtraFilesMap& extra_files,
bool load_debug_files = true);
/// Loads a serialized `Module` from the given `filename`.
///
/// The file stored at the location given in `filename` must contain a
/// serialized `Module`, exported either via `ScriptModule.save()` in
/// Python or `torch::jit::ExportModule` in C++.
TORCH_API Module load(
const std::string& filename,
std::optional<c10::Device> device = c10::nullopt,
bool load_debug_files = true);
TORCH_API Module load(
const std::string& filename,
std::optional<c10::Device> device,
ExtraFilesMap& extra_files,
bool load_debug_files = true);
/// Loads a serialized `Module` from the given shared_ptr `rai`.
///
/// The reader adapter, which is for customized input stream, must contain a
/// serialized `Module`, exported either via `ScriptModule.save()` in
/// Python or `torch::jit::ExportModule` in C++.
TORCH_API Module load(
std::shared_ptr<caffe2::serialize::ReadAdapterInterface> rai,
std::optional<c10::Device> device = c10::nullopt,
bool load_debug_files = true);
TORCH_API Module load(
std::shared_ptr<caffe2::serialize::ReadAdapterInterface> rai,
std::optional<c10::Device> device,
ExtraFilesMap& extra_files,
bool load_debug_files = true);
TORCH_API Module jitModuleFromSourceAndConstants(
const IValue& ivalue,
const ExtraFilesMap& source,
const std::vector<IValue>& constants,
int32_t version);
TORCH_API Module parse_and_initialize_jit_module(
std::shared_ptr<char> data,
size_t size,
ExtraFilesMap& extra_files,
std::optional<at::Device> device = c10::nullopt);
TORCH_API Module load_jit_module_from_file(
const std::string& filename,
ExtraFilesMap& extra_files,
std::optional<at::Device> device = c10::nullopt);
TORCH_API Module load_jit_module_from_stream(
std::istream& in,
ExtraFilesMap& extra_files,
std::optional<at::Device> device = c10::nullopt);
TORCH_API Module parse_and_initialize_jit_module(
std::shared_ptr<char> data,
size_t size,
ExtraFilesMap& extra_files,
std::optional<at::Device> device);
TORCH_API c10::intrusive_ptr<c10::ivalue::Object> ObjLoaderFunc(
const at::StrongTypePtr& type,
IValue input);
} // namespace jit
} // namespace torch