Add module attributes (#17309)
authorDavid Riazati <davidriazati@fb.com>
Thu, 7 Mar 2019 18:41:13 +0000 (10:41 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 7 Mar 2019 18:44:10 +0000 (10:44 -0800)
commita2381fa346a08dd9be3ef7942efb048d789cbee1
tree3f85fac664f1015a1773a0dfdd00d8a0e70027dd
parente4c9d75008f5a8d5cd44c6b4e24d1e90bb81c598
Add module attributes (#17309)

Summary:
Similar to `nn.Parameter`s, this PR lets you store any `IValue` on a module as an attribute on a `ScriptModule` (only from the Python front-end currently). To mark something as an attribute, it should wrapped in `jit.Attribute(value, type)` (ex. `self.table = torch.jit.Attribute(table, Dict[str, torch.Tensor])`)

Followup Work:
* (de)serializing for use in C++
* change `self.training` to be a `bool` attribute instead of a buffer
* mutable attributes
* string frontend support
* documentation
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17309

Differential Revision: D14354316

Pulled By: driazati

fbshipit-source-id: 67e08ab5229366b67fbc837e67b58831a4fb3318
15 files changed:
test/custom_operator/test_custom_ops.cpp
test/test_jit.py
torch/csrc/api/src/serialize/input-archive.cpp
torch/csrc/jit/export.cpp
torch/csrc/jit/import.cpp
torch/csrc/jit/import.h
torch/csrc/jit/import_method.cpp
torch/csrc/jit/passes/python_print.cpp
torch/csrc/jit/pybind_utils.h
torch/csrc/jit/script/init.cpp
torch/csrc/jit/script/module.cpp
torch/csrc/jit/script/module.h
torch/jit/__init__.py
torch/nn/parallel/replicate.py
torch/onnx/utils.py