pytorch/torch/csrc/jit/script
davidriazati cd28ff5395 Add support for __getstate__/__setstate__ on module (#20242)
Summary:
Adds support for `__getstate__` and `__setstate__` on modules that are called as part of export (`torch.save()`) and import (`torch.jit.load`).
* `__getstate__` and `__setstate__` must be TorchScript functions with the signatures `() -> T` and `(T) -> None` respectively
* The results of `__getstate__` are stored using the pickler in `states.pkl` with one for each module in definition order (`__getstate__` returns `None` by default if an imlpementation is not provided)
    * This prevents sharing between `__getstate__` and attributes, but this should be fine since their use is mostly unrelated (attributes are for storing values to be used in script methods, `__getstate__` for running arbitrary computations during import)

Follow up
* Somehow replacing `__getstate__`/`__setstate__` with a `ScriptMethodStub` makes `MyScriptModule().__getstate__()` call `ScriptModule.__getstate__()` when used in Python. This should be fixed so semantics in Python are preserved, but it doesn't affect the typical usage.
](https://our.intern.facebook.com/intern/diff/15287161/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/20242

Pulled By: driazati

Differential Revision: D15287161

fbshipit-source-id: b3f5f33ab74a21a89e6d15460af63aff75cab2d8
2019-05-17 14:43:14 -07:00
..
builtin_functions.cpp Cleanup includes in torch/csrc/* (#19924) 2019-05-06 14:03:18 -07:00
builtin_functions.h First class modules in the compiler, round 2 (#19167) 2019-04-11 13:55:48 -07:00
class_type.cpp @torch.jit.script(fn) now is a torch.jit.Function (#19721) 2019-04-25 15:53:00 -07:00
compilation_unit.h Replace AT_CHECK with TORCH_CHECK [shard 10/10] 2019-05-15 07:35:37 -07:00
compiler.cpp Remove SourceLocation (respin) (#20333) 2019-05-09 16:17:33 -07:00
compiler.h Turn resolver into a class (#19236) 2019-04-19 13:01:59 -07:00
edit_distance.cpp Print out operator suggestions for unknown builtin op (#15183) 2019-01-04 13:04:44 -08:00
edit_distance.h Cleanup includes in torch/csrc/jit/script/* (#19921) 2019-05-06 13:24:22 -07:00
error_report.h Remove SourceLocation (respin) (#20333) 2019-05-09 16:17:33 -07:00
final_returns.cpp Serialize first-class version of functions (#19723) 2019-04-25 15:53:07 -07:00
final_returns.h clang format world (#15524) 2018-12-26 06:55:01 -08:00
function_schema_parser.cpp Memory format support for contiguous and is_contiguous (#20455) 2019-05-16 07:18:24 -07:00
function_schema_parser.h Allow registering ops without specifying the full schema (#19286) 2019-04-18 02:04:46 -07:00
init.cpp Namespace isolation for classes (#19903) 2019-05-07 22:48:31 -07:00
init.h Canonicalize all includes in PyTorch. (#14849) 2018-12-08 19:38:30 -08:00
jit_exception.cpp C++ changes toward libtorch and libcaffe2 unification (#19554) 2019-04-26 01:38:10 -07:00
jit_exception.h C++ changes toward libtorch and libcaffe2 unification (#19554) 2019-04-26 01:38:10 -07:00
lexer.cpp Move function schema parser to ATen/core build target (#19282) 2019-04-18 01:03:37 -07:00
lexer.h Cleanup includes in torch/csrc/jit/script/* (#19921) 2019-05-06 13:24:22 -07:00
logging.cpp C++ changes toward libtorch and libcaffe2 unification (#19554) 2019-04-26 01:38:10 -07:00
logging.h Cleanup includes in torch/csrc/jit/script/* (#19921) 2019-05-06 13:24:22 -07:00
module_python.h Extract Python-specific SugaredValues to a separate file from init.cpp. (#19986) 2019-04-30 19:38:23 -07:00
module.cpp Convenience APIs for script objects (#20226) 2019-05-10 13:03:58 -07:00
module.h Add support for __getstate__/__setstate__ on module (#20242) 2019-05-17 14:43:14 -07:00
parse_string_literal.h clang format world (#15524) 2018-12-26 06:55:01 -08:00
parser.cpp fix parsing bugs (#20246) 2019-05-07 19:35:51 -07:00
parser.h Attribute serialization (#17423) 2019-03-18 18:18:22 -07:00
python_sugared_value.cpp Add support for __getstate__/__setstate__ on module (#20242) 2019-05-17 14:43:14 -07:00
python_sugared_value.h Add support for __getstate__/__setstate__ on module (#20242) 2019-05-17 14:43:14 -07:00
python_tree_views.cpp Cleanup includes in torch/csrc/jit/script/* (#19921) 2019-05-06 13:24:22 -07:00
python_tree_views.h clang format world (#15524) 2018-12-26 06:55:01 -08:00
resolver.h Namespace isolation for classes (#19903) 2019-05-07 22:48:31 -07:00
schema_matching.cpp Remove SourceLocation (respin) (#20333) 2019-05-09 16:17:33 -07:00
schema_matching.h Index into a tuple with non constant integer (#20081) 2019-05-06 14:23:16 -07:00
schema_type_parser.cpp Memory format support for contiguous and is_contiguous (#20455) 2019-05-16 07:18:24 -07:00
schema_type_parser.h Move function schema parser to ATen/core build target (#19282) 2019-04-18 01:03:37 -07:00
script_type_parser.cpp Cleanup includes in torch/csrc/jit/script/* (#19921) 2019-05-06 13:24:22 -07:00
script_type_parser.h Cleanup includes in torch/csrc/jit/script/* (#19921) 2019-05-06 13:24:22 -07:00
slot.h First class modules in the compiler, round 2 (#19167) 2019-04-11 13:55:48 -07:00
strtod.cpp Fix strtod for MSVC (#20490) 2019-05-15 07:40:44 -07:00
strtod.h Fixing function schema parser for Android (#19281) 2019-04-17 23:50:17 -07:00
sugared_value.cpp Remove SourceLocation (respin) (#20333) 2019-05-09 16:17:33 -07:00
sugared_value.h Support operator overloading for UDT (#20033) 2019-05-07 17:28:06 -07:00
tree_views.h Cleanup includes in torch/csrc/jit/script/* (#19921) 2019-05-06 13:24:22 -07:00
tree.h Cleanup includes in torch/csrc/jit/script/* (#19921) 2019-05-06 13:24:22 -07:00