Add named submodule support to nn::Sequential (#17552)
authorWill Feng <willfeng@fb.com>
Fri, 29 Mar 2019 19:59:29 +0000 (12:59 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 29 Mar 2019 20:06:29 +0000 (13:06 -0700)
commit6ebfbdf4c66586d0c3237bc29b1267a9fe0a13cd
tree0c1373a25461258530fe35d4e7d08a41e25ddce6
parente73be58ff7f9df478cdb57fad6102a2dcf5dc181
Add named submodule support to nn::Sequential (#17552)

Summary:
Previously, we were not able to assign names to `nn::Sequential`'s submodules. This PR adds this feature to match the Python API. Example use:
```cpp
Sequential sequential(named_submodule({
      {"linear", Linear(10, 3)},
      {"conv2d", Conv2d(1, 2, 3)},
      {"dropout", Dropout(0.5)},
      {"batchnorm", BatchNorm(5)},
      {"embedding", Embedding(4, 10)},
      {"lstm", LSTM(4, 5)}
}));
```

It also enables loading parameters of Python `nn.Sequential` module with custom submodules names into C++ frontend, unblocking https://github.com/pytorch/vision/pull/728#issuecomment-466661344.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17552

Differential Revision: D14246834

Pulled By: yf225

fbshipit-source-id: 3030b5c5d68f6dd5d3e37ac4b4f98dc6d6d9ba72
docs/cpp/source/check-doxygen.sh
test/cpp/api/sequential.cpp
torch/CMakeLists.txt
torch/csrc/api/include/torch/nn/modules/any.h
torch/csrc/api/include/torch/nn/modules/named_any.h [new file with mode: 0644]
torch/csrc/api/include/torch/nn/modules/sequential.h
torch/csrc/api/src/nn/modules/named_any.cpp [new file with mode: 0644]