Enforce single parent for script submodules (#18379)
authorZachary DeVito <zdevito@fb.com>
Thu, 4 Apr 2019 03:21:27 +0000 (20:21 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 4 Apr 2019 03:26:58 +0000 (20:26 -0700)
commit7e59c60454bf5c80a4125808cd69a9b84675c643
treecad588f1a415c10dcc4099192c0db1f6506cc649
parentb80a4fa201d4a7755bfb82b7fbd502297cef41db
Enforce single parent for script submodules (#18379)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18379
ghimport-source-id: 9895ecc1ff7897e98853dc00675341f36726e7c7

Stack from [ghstack](https://github.com/ezyang/ghstack):
* **#18379 Enforce single parent for script submodules**
* #18378 Unify namespace of script::Module
* #18314 Add ability to specialize class types to ArgumentSpec
* #18226 Add Slot type to abstract the raw pointers being used for slots.

The assumption that a ScriptModule has a single parent is present in
our serialization format, and likely a few other places. It is not
enforced on creation of script module hierarchies though, meaning that
problems associated with (e.g. replicating a module twice in the output
format) will not be caught until much later in the development cycle.

This patch enforces the property when a submodule is registered.
It also removes NamedModule since it is no longer necessary in this regime.
This will also allow the easy discover of a modules fully-qualified name
without needing to traverse the Module hierarchy.

Differential Revision: D14603722

fbshipit-source-id: 63ab5d0cccf7d66c7833e0adf9023024ca9607cb
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_source.cpp
torch/csrc/jit/passes/python_print.cpp
torch/csrc/jit/script/init.cpp
torch/csrc/jit/script/module.cpp
torch/csrc/jit/script/module.h