pytorch/torch/csrc/jit/import_source.h
Michael Suo 18f721fb9a support serialization of classes (#17856)
Summary:
Stack:
      **#17856 [jit] support serialization of classes**  [💛](https://our.intern.facebook.com/intern/diff/D14402599/)

Add support for saving/loading TorchScript modules that depend on user-defned classes.

We track class dependencies the same we track tensor constants, then write them
all out such that we can just compile them in order before compiling the module
hierarchy.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17856

Reviewed By: shannonzhu

Differential Revision: D14461599

Pulled By: suo

fbshipit-source-id: 7115f87e069fd00dc8381d7de9997864fef7ea9f
2019-03-15 12:06:23 -07:00

27 lines
767 B
C++

#pragma once
#include <torch/csrc/jit/ir.h>
#include <torch/csrc/jit/script/compiler.h>
#include <torch/csrc/jit/script/module.h>
namespace torch {
namespace jit {
namespace script {
// Helpers to define modules and classes from source strings. Used in model
// saving/loading, so it expects the format produced by the model exporter.
// Add the methods defined in `src` to the module `mod`.
TORCH_API void import_methods(
const std::shared_ptr<script::Module>& mod,
const std::string& src,
const std::vector<at::Tensor>& constant_table);
// Defined the list of classes in `src`.
TORCH_API void import_libs(
const std::string& src,
const std::vector<at::Tensor>& constant_table);
} // namespace script
} // namespace jit
} // namespace torch